Category Archives: Uncategorized

Learning Cobol Round #1

My mum learnt COBOL and FORTRAN when she was in university back in the 60s. Although I have used FORTRAN77 in a professional capacity, I still haven’t had the opportunity to try COBOL.

Since being retro is the harbinger of cool, I’ll spend the next few articles blogging about my experience working with COBOL.

Visual Cobol

There is a free non-commercial use license granted by Visual Cobol. This is sufficient for my learning purposes.

In terms of resources, Teach yourself COBOL is 21 days seems to be a good starting point.

The download is a little tricky. After receiving the confirmation email, I was presented with a screen but the download link wasn’t apparent. It’s tucked under the Software/Licenses tab (see red arrow). The download was 417MB, and I was a little concerned I’ll not have much space left on my SSD, which is burgeoning with several virtual machines. However, the promise of the familiarity of Visual Studio and having access to the .NET framework beckons me to try it out.

In comparison, the OPENCOBOL 1.1 source download is 1 Mb. That’s very inviting, although I don’t really like the idea of building GNU autoconf project on Windows.  There’s never a nice ending.  I found prebuilt-binaries for OPENCOBOL on Windows, and given the download size of 7.3 Mb,  I downloaded it as well.

Upon creating the first COBOL project with Visual Studio, I was prompted for a license key. It wasn’t immediately apparent, but all I had to do was to provide the email address I had used to register with Microfocus, and that activated my free copy automatically.

Running Hello World from a Visual Cobol Console project was simple enough.

       identification division.
       program-id. Program1.

       environment division.
       configuration section.

       data division.
       working-storage section.

       procedure division.

       PROGRAM-BEGIN.      
       DISPLAY "Hello World".
       PROGRAM-DONE.
       
       end program Program1.

OpenCobol

OpenCobol was straightforward. Unzip the 64bit binaries to C:\OpenCobol, and run vcvars64.bat to set up the path to Visual C (OpenCobol translates COBOL to C and then uses the platform compiler to build executables). The command below builds hello.exe

cobc -x hello.cob

Project scope

In terms of project, I’d like to try my standard project, involving authorization, data validation and persistence (both NoSQL and SQL). I’m mindful that my projects will be un-COBOL-like, but that can be refined with time.

Next article – Round #2

Saw this in my email today wizpert – billed as “is a fast growing community of experts, where users seek advice and coaching on a range of programming languages, including Python, HTML, PHP, JavaScript and more.

Bookmarked!

Powershell equivalent of xargs

I wanted to be able to build extmap.xml for all the files that were in my packages\ directory. I had a Powershell script called ToExtMap which automated most of my tasks, and a little experimentation with Powershell gave me this one liner:


PS C:\Users\Chui\Projects\SAM-GET\packages>
Get-ChildItem -Filter *.dll -Recurse -name |
%{ ToExtMap $_ | Out-File ($_ -replace "dll", "extmap.xml") -encoding ASCII}

A bit of explanation might be in order:

  1. Get-ChildItem -Recurse finds all the files I require.
  2. The %{} is the shortcut for the foreach operator.
  3. Powershell is object oriented. $_ -replace ... executes a string substitution

Over at Forbes

It started with making one presentation slide for each idea. Each slide would have a heading and several bullet points defining the scope of the feature and metrics describing what success would look like and how it would impact the business. That’s all people got to make their case. And given the speed of the whole process, there was little time for precision.

Dell Service Drop off Brisbane

The Dell service center in Brisbane has moved to 8 Castlemaine St, Cooparoo (effective 6 Jan 2014). It is in the big courier’s shed, and there’s a small narrow storefront. If you need to drop off your computer for repairs, it is no longer at Mowbray Tce.

Hopefully this post finds you before you get lost.

Piano Teacher in Toowoomba

My kids have been taking piano lessons with Marie Kilpatrick in Toowoomba and I liked her style of communicating musical ideas to the children. For example, in Mozart’s Andante, she likened the left hand to rustling wind, while a diva sings on the right hand, and then she works through with the children the kind of touch necessary. Another way she communicated this is by explaining that the triplets on the left hand outnumber the melody on the right hand, and therefore has to be much much softer.

Caliburn Micro Navigation for Silverlight

Users who are accustomed to browser based apps find navigating between screens and having a back button to be a very natural way to interact with applications. In addition, they also make it easy for screens to be bookmarked.

In Silverlight, navigation is integrated with the web browser through the use of Uri fragments. Uri fragments look like this:

http://site.com/sample.htm#/Page1

. When the Uri fragment is changed, it triggers a Frame control to load new content in two steps:

  1. Firstly, the fragment is mapped to the path to a XAML file using the frame’s UriMapper
  2. Then, the XAML file referred to in the previous step is loaded and the navigation events are raised.

Caliburn.Micro, being a ViewModel-First framework can integrate with the Silverlight Navigation Framework. Rob Eisenberg has already provided one for the Windows Phone. With a little work, we can make it work for Silverlight as well. I have provided it in this GitHub project.

A quick note on how Caliburn.Micro integrates navigation: Caliburn.Micro defines an INavigationService interface that includes methods like Navigate() and GoBack(). The implementation, called a FrameAdapter, calls the equivalent methods on the Frame control.

The best way to apply the FrameAdapter is in the bootstrapper, once the RootVisual has been loaded. There is a bit of fiddling around initially, and we cannot inject a Frame into the ShellViewModel’s constructor because the ShellView’s Frame isn’t loaded yet. So there is a precise order we need to apply to bootstrap this properly. All is done for you in the sample. We load the ShellView, find the frame, and then inject it back into the ShellViewModel.

	protected override void OnStartup(object sender, System.Windows.StartupEventArgs e)
	{
	    DisplayRootViewFor<IShell>();

            // finds the Frame control in the ShellView, 
            // registers it, 
            var frame = FrameAdapter.FindFrame(App.Current.RootVisual, null);
            container.RegisterInstance(typeof(System.Windows.Controls.Frame), null, frame);

            // and then reinitialize the shellviewmodel
            BuildUp((App.Current.RootVisual as System.Windows.Controls.UserControl).DataContext);
	}

Here’s a sample ShellViewModel that gets injected with INavigationService during the BuildUp() call.

public class ShellViewModel
{
        public INavigationService NavigationService { get; set; }

        public void Link1()
        {
            NavigationService.UriFor<Page1ViewModel>().WithParam<int>(p => p.PageId, 42).Navigate();
        }
}

Getting started with component.js

Component JS is a package manager of client-side components, in the similar way npm works for server-side code.

“Components” is a standard way of packaging js, stylesheets and declaring dependencies so that they can be used across different applications. It is agnostic to the type of server-framework used, i.e. you can use it with asp.net, php etc.

However, the utility itself is built around npm infrastructure (I think!), so you will need a working npm Node Package Manager to get started.

Declaring components required

Just like package.json declares dependencies for nodejs, and Gemfile declares dependencies for Ruby on Rails, component.json declares dependencies on client-side components.

{
    "name": "myapp",
    "dependencies": {
       "component/popup": "*",
       "component/popover": "*",
       "component/tip": "*",
       "component/dialog": "*"
    }
}

Installing components

Next install the components declared:

teyc@seotoma:~/myapp$ component install

     install : component/popup@master
     install : component/popover@master
     install : component/tip@master
     install : component/dialog@master
    complete : component/tip
    complete : component/popup
    complete : component/dialog
    complete : component/popover

You can also install components from the command-line using

component install component/dialog

Building aggregated js and css


teyc@seotoma:~/myapp$ component build -v

       write : build/build.js
       write : build/build.css
          js : 315kb
         css : 1kb
    duration : 65ms

Using build.js and build.css

The HTML page should refer to two compiled files – build.css and build.js:

<html>
  <head>
   <link rel="stylesheet" type="text/css" href="build/build.css" />
  </head>
  <body>
   <script src="build/build.js"></script>
  </body>
</html>

Points of interest

The components aren’t all thrown into one namespace. They use github-style namespacing. In fact, you have to use standard requirejs style declarations to use components. For example:

var Popover = require("component-popover");

For larger apps, it may be better to declare a super-component that requires all the subcomponents. In component.json, declare a single script index.js:

{
    "name": "myapp",
    "dependencies": {
       "component/popup": "*",
       "component/popover": "*",
       "component/tip": "*",
       "component/dialog": "*"
    },
    "scripts": [
       "index.js"
    ]
}

and index.js does all the requires. Interestingly, note that a namespace is not required. You can declare “popover” instead of “component-popover”.

var Popover = require("popover");
popover = new Popover("A hello world message", "header - Component.io");
popover.show("#example")

Then the require script

<html>
 <head>
  <link rel="stylesheet" href="build/build.css" type="text/css"></link>
 </head>
 <body>
  <script src="build/build.js"></script>
  <script>
    require("myapp");
  </script>
  <h1>Component example</h1>
  <p id="example">Pop over me</p> 
 </body>
</html>

WebMatrix 1.0 Reset Passwords

The token generated by WebMatrix 1.0 used base64 encoding, and caused odd problems when copy and pasted into web browsers. The following hack addresses the issue.

resetToken = WebSecurity.GeneratePasswordResetToken(email); //Optionally specify an expiration date for the token
                
// Workaround - WebSecurity v1 generates Base64 encoded strings, 
// and are not URL friendly. Use UrlTokenEncodeInstead
try { resetToken = HttpServerUtility.UrlTokenEncode(Convert.FromBase64String(resetToken));}
catch (Exception exc) { // do nothing, GeneratePasswordResetToken may return a previously stored token from database };

  db.Execute(
  "UPDATE webpages_Membership SET PasswordVerificationToken=@1 WHERE UserId=@0", 
       userId,
       resetToken);