Sunday, March 30, 2014

CoffeeScript vs TypeScript

Why do I prefer CoffeeScript over TypeScript?

There are some obvious syntax differences -

  • CS uses white space to define bocks,  TS uses curly braces 
  • CS uses the -> operator to define functions
  • CS uses @ to represent the current context, TS uses the 'this.' keyword

In addition, there are some higher level differences -

  • TS has a concept of modules, CS is not opinionated on this.
  • TS allows you to define a type when you declare vars.
  • TS resolves the super class at compile type, CS accepts a run-time reference.

The syntax differences are more a matter of preference. To me, CoffeeScript is cleaner looking, and requires less keyboard action to write. It also makes async and callbacks easier to follow, especially with the alternate bound function definition operator => for events.

Higher level differences make more of a difference when deigning your app. TypeScript restricts you to their own concept of modules. CoffeeScript is flexible on this matter, and I can use several different module libraries, from native node require on the server to RequireJS or Browserify on the client. 

All in all, I find CoffeeScript easier to code, and less restrictive, where TypeScript fights the dynamic nature of javascript, 

Sunday, March 23, 2014

Enabling the Java Plugin for Chrome in Mint

So, you've gone to the Oracle web site and installed Java. But when you visit a website that requires Java, you still get a message that directs you back to the Oracle web site to install Java. The problem is that your browser doesn't know that you've installed Java, so you need to tell it where to look.

Both Ubuntu and Mint use Firefox as a default browser.  If we tell Firefox where to look, Chrome will also know. So we actually get a 2 for 1 deal.

You'll need to know where Firefox is installed, as well as Java. On my machine, these are:
  • Firefox - /usr/lib/mozilla
  • Java - /usr/local/jdk1.7.0_45/jre
If you've only installed the java runtime, it's probably in /usr/local/jre1.7.0_45. Your folder structure may be for a different version. If you're not sure where Java is, you can open a terminal window and enter:

$ sudo find / -name libnpjp2.so

Armed with this information, open a terminal window, and go to the Firefox folder:

$ cd "/usr/lib/mozilla/plugins"

Now,  create a symbolic link in that folder that points back to the plugin:

$ sudo ln -s "/usr/local/jdk1.7.0_45/jre/lib/amd64/libnpjp2.so"

Now, you can restart your browser, and enable the plugin:

  • Firefox - Select Tools > Add-ons (Ctrl+Shift+A) from the Menu Bar.  Then select the Plugins panel, and enable Java(TM) Plug-in
  • Chrome - type chrome://plugins in the Navigation Bar to enable the plugin.

Now goto http://www.java.com/en/download/installed.jsp to verify the plugin is working.

I've recently upgraded from Xubuntu to Linux Mint. What is nice is that since Mint is based on Ubuntu, many of the tricks and tips that I've learned for Ubuntu also work on Mint. This tip that worked on Xubuntu 11.10 with Java 1.6, still works on Mint 16 Cinnamon with Java 1.7.

Saturday, March 22, 2014

Top 6 Web Conferencing Solutions for Linux

I'm looking for good online meeting software so I can collaborate with other developers, and hopefully some customers as well.

My criteria as simple - it has to run on linux, and it has to be free. I don't mind if there is a pro version that I can upgrade to if I find it to be that useful. But no 14 day free demos.

My laptop runs on Linux Mint 16 Cinnamon 64-bit. After reviewing many packages, here are the ones I found several that will run on my machine:

Meetin.gs

A nice modern look with Google calendar integration. The ui is easy to use, and the workflow is well thought out - after the meeting, I was emailed with a reminder to follow up on my action items. Meetin.gs also gives you a public Meet Me page where anyone can schedule a meeting with me. There is an Android app, but it's still beta.

Meeting Burner 

A full featured application, the ui reminds me of LiveMeeting. MeetingBurner uses Flash player for the presentation window. There is also a mobile app for android which requires Adobe AIR.

Veeting

Yeah, I know. If you google 'veeting' you'll find something completely different :)  Veeting claims to be very confidential due to Swiss hosting. You can schedule short one-off meeting with one other person without joining.

Vyew

Vyew has a lot of features, but has a steep learning curve.

Web Huddle

WebHuddle is beta, and feels like it. I'll have to check back later when it more finished.

WebEx

On linux, Cisco WebEx only works in Firefox with Java enabled. The features are comparable to MeetingBurner. There is also a android app.


I really like Meetin.gs. It's pure HTML, has a modern look, and I love the Meet Me page and Google integration. I also like MeetingBurner, it's packed with functionality and easy to use. There is an Android app, and it works great on my Nexus phone. In some respects, they can complement each other, and I will be using both of them.

Veeting is not bad either, but seems more like a Skype alternative. The remaining are in my opinion not very easy to use. I think a meeting app should be more intuitive, otherwise it get's in the way of the meeting. WebEx is fast and the android app updates almost instantly, but the ui reminds me of the admin page on my router - also a Cisco product... If they fix their UX, I'd probably use it.


Wednesday, March 5, 2014

Put Some Promise in your Cakefile

Cakefiles seem like such a simple solution, until you need asynchronous code. Even in coffeescript, the "pyramid of doom" becomes hard to handle. For example, take a look at the cakefile I use to build the huginn-liquid distribution:


util = require 'util'
{exec} = require "child_process"

task 'build:src', 'Build the Liquid source', ->

  #
  # Build the intermediate js
  #
  exec 'coffee -o lib -c src', ($err, $stdout, $stderr) ->

    util.log $err if $err if $err?
    util.log $stderr if $stderr if $stderr?
    util.log $stdout if $stdout if $stdout?
    util.log 'ok' unless $stdout?

    exec 'browserify  lib/liquid.js --debug --standalone Liquid > dist/liquid.dbg.js', ($err, $stdout, $stderr) ->

      util.log $err if $err if $err?
      util.log $stderr if $stderr if $stderr?
      util.log $stdout if $stdout if $stdout?
      util.log 'ok' unless $stdout?

      exec 'browserify lib/liquid.js --standalone Liquid | uglifyjs > dist/liquid.min.js', ($err, $stdout, $stderr) ->

        util.log $err if $err if $err?
        util.log $stderr if $stderr if $stderr?
        util.log $stdout if $stdout if $stdout?
        util.log 'ok' unless $stdout?

        exec 'browserify  lib/liquid.js --standalone Liquid > dist/liquid.js', ($err, $stdout, $stderr) ->

          util.log $err if $err if $err?
          util.log $stderr if $stderr if $stderr?
          util.log $stdout if $stdout if $stdout?
          util.log 'ok' unless $stdout?



As you can see, even with CoffeeScripts async friendly syntax, the code still starts to creep off that right edge. And adding more build steps will only get worse. But with Promises, we can fix that. First, install Q:

$ sudo npm install -g q


Now we can make some changes to Cakefile that will make it easier to read. We'll use Q's nfcall method.

util = require 'util'
{exec} = require "child_process"
{nfcall} = require 'q'

task 'build:src', 'Build the Liquid source', ->

  #
  # Build the intermediate js
  #

  start = new Date().getTime()

  nfcall exec, 'coffee -o lib -c src'

  .then ->
      nfcall exec, 'browserify  lib/liquid.js --debug --standalone Liquid > dist/liquid.dbg.js'

  .then ->
      nfcall exec, 'browserify lib/liquid.js --standalone Liquid | uglifyjs > dist/liquid.min.js'

  .then ->
      nfcall exec, 'browserify  lib/liquid.js --standalone Liquid > dist/liquid.js'

  .fail ($err) ->
      util.error $err

  .done ($args) ->
      util.log $text for $text in $args when not /\s*/.test $text
      util.log "Compiled in #{new Date().getTime() - start} ms"



Wow - that IS cleaner! And as I add more steps it will stay just as easy to read.