Saturday, April 19, 2014

Building opencv java module

Last week I tried to build OpenCV java module so I could use it for clj-drone so I could have more fun with AR Drone 2.0.  I couldn't figure out why the java module is set unavailable after cmake.  This happens on both Ubuntu 12.04 and OS X 10.9.  I have seen some issues regarding properly setting the JAVA_HOME and the cmake JNI file being incorrect.  I tried to look at this angle, seeing why the JNI interface would not work.

However it seems "ant" is a required component and not just a recommended install as indicated by the docs.  So after a "brew install ant" and "apt-get install ant" cmake is able to properly set the Java OpenCV module.  I never had ant for years in my system, right now only using mvn, sbt and lein.

OpenCV 2.4.5 built just fine on Ubuntu, OSX seems to be having some c++ compile issue...

Thursday, April 3, 2014

Learning Clojure by doing a simple things

I usually tinker around different languages or technology.  I have been learning a bit of Clojure for the last couple of weeks.  Tried it at the office, by making a simple REST client.  Now just making a simple web app, just to get a feel of the language and ecosystem around it.

Clojure reminds me of Tcl, I know its LISP and it should remind more of emacs.  It reminds me of Tcl as I done a lot of Tcl programming using aolserver and OpenACS before.  Unlike the first few times I used Ruby or Scala, where the first wow factor is the language.  Tcl and Clojure the wow factor is getting to do something really quick.  They both have quirky syntax, but simple and uniform.

Here is why I am learning Clojure:
  • Learning a new languages makes me better at the languages I already know.  Getting the nice feeling of being new, and learning a lot on the way... mistakes and aha moments.
  • Still on my journey to be a better Functional Oriented hipster.  Not that I am leaving Object Oriented or even procedural away, just learning a another way of thinking and solving computing issues.
  • Getting my son to learn something.  Clojure seems to have nice abstraction for sql, web and js.  Start with 1 language will be less intimidating, instead of learning a lot in 1 bang.
As a newbie, I started with a framework first.  I like get to know other people's opinion first before making my own.  I picked Luminus as it seem to be using some of things that the clojure community is using.  Here are some code snippets from bottom layer to top.  Its simple and lacks any real world complications yet, learn the ropes on the basic things first.

Data using Korma

It starts with a macro for defining an entity and I would guess the convention to tie with the backing rdbms tables.  Then you define some functions using Korma's sql dsl.  You deal with primarily 2 data structure "id" which is a string and "product" which is a map.

Web using Ring and Compojure

The above is defining the routes, which you tie to the application handler.  Real nice bits are the ability to define a context.  Which would mean enclosing routes will start with that path first.  Easy way to extract the request body from a key ":body-params", and to respond with body by setting the key ":body".

Finally the front end using Clojurescript, Gyr and Angular.js

It looks less Clojure idiomatic, however I wanted to start somewhere.  Angular.js is familiar to me, just realised that its been about 2 years ago I started looking at Angular.js.  We have been using it ever since, I am actually rusty on it already.  I saw the Gyr and Putnam project had pretty good documentation.  Gyr gives some macros such as def.factory, def.controller, etc.  which looks similar to normal angular.  Then the ability to use $ which is pretty nice.  You will need to use "obj" and "arr" to interact with normal Javascript objects and arrays.

Clojure is nice and simple (still on first impression).  Gets you up and running quick.  If its good for long big projects, I don't know yet.  However I will be happy if I can meet 2 out of my 3 objectives in learning Clojure.  Complete source code here for the curious.

Thursday, May 16, 2013

Flashing bios using a usb drive

If you are like me where most PC run's linux and has no optical drive.  I saw the following steps around the net to be helpful.
  1. Get the bios update iso
  2. Get 'geteltorito' and extract the boot image from the iso
    $ wget ''
    $ perl biosupdate.iso > biosupdate.img
  3. Copy the image to the usb thumdrive
  4. $ sudo dd if=biosupdate.img of=/dev/usbthumdrive bs=512K

Saturday, April 13, 2013

Small Android stick (mk808b) mini review

Me and my mates at the office just bought one of those Android mk808b.  Its dirt cheap, so we gave it a try.

So far its been pretty good.  I plugged to an existing TV with hdmi and I can now use the TV for browsing, watching streaming videos and skype.  Since I am a Linux user I got a UVC compliant webcam, which works on this device as Android uses a Linux kernel.  So with little a fraction of a cost I was able to turn my old TV into what they call a smart TV (didn't like the idea of smart tv, never bought one).  Normally before this TV had a laptop plugged into it, now Android stick pc replaced it.

Pros (would not elaborate on it too much, lots of people have put heaps of comments around the web)
  • Low cost.  These cost about $50-90 around the net.  Also as part of the low cost, is that you can use your existing TV as long as it has a hdmi input.
  • Small and low power.  This comes with a USB adapter.  However I had mine just plugged into my xbox 360 usb port, even way better.
  • Newer firmware comes pre-rooted.  Mine is already rooted.
  • Clearly Android is for touch.  I bought the bundled air mouse, you can also use normal usb mouse and keyboard.  However the experience is not as nice, same experience as running the Android developer emulator on your PC.  You can only use apps that will run with single touch operations or single touch swipes.  Youtube, web browsers, skype, angry birds will be ok.  However google maps (no pinch zoom, so I don't know how to zoom out.. zoom in can done via double tap).  My idea was to get my tablet back from my kids, however this clearly an inferior experience for them.  So it kinda did not work, and now they can tell me to use my stick Android and they will use the Android tablet.  Plan back-fired.
  • Its not well polished.  This can leave a poor impression on Android for users having this as their first Android device.   Though this is Jelly Bean, its really far away from the experience you have from a Nexus 4, even from a 2 year old Asus Transformer.
  • It seems the cpu stays at 1 ghz no matter what the load is.  Now sure why I haven't played with the governor yet.  So it doesn't go 1.6ghz or drops down to 200-400mhz.
  • The out display seems to be 16 bit (not sure but it looks like it), also always resets to 720p after every boots up.  I read that you will need to reflash so it renders the color in 24/32 bit.  Again doesn't look that good, but not too bad if don't look for image issues (gradients and dithers).
  • The air mouse is sensitive to interference.  I am still running on 2.4 wifi, I have not much other devices and neighbors are far away.  However you can see during real big burst of traffic the air mouse is getting cut off as seen by the lag.
So the android stick PC is not really dirt cheap as it seems to be.  This is probably not a good first Android device.  However is a great bargain if.  You have a TV that you want to run some basic computing needs (web browsing, video calls, streaming video, music playing).  You can upgrade the TV and replace an aging laptop that used to perform those computing needs.

In order for the stick PC to have a great experience you need to buy a good input device.  Which would now increase the cost.  It also doesn't have a screen, no battery, etc.  So a Nexus 7 would probably be cheaper as a first good Android device.

Sunday, August 26, 2012

Angular.js for ajax CRUD

Its been a busy weekend, not in terms of coding though.  Just did some quick coding now.  This is now a book-markable ajax CRUD talking to conventional REST/JSON backend.


angular.module('ratewatcher', ['ngResource']).
 config(function($routeProvider) {
   when('/lenders', {controller:LenderListController, templateUrl:'lender-list.html'}).
   when('/lenders/new', {controller:LenderCreateController, templateUrl:'lender-detail.html'}).
   when('/lenders/:id', {controller:LenderEditController, templateUrl:'lender-detail.html'}).
 factory('Lender', function($resource) {
  return $resource('/lenders/:id', {id: '@id'}, {});


function LenderListController($scope, Lender) {
  $scope.lenders = Lender.query();
  $scope.remove = function(lender) {
function LenderCreateController($scope, Lender) {
  $ = function() {
    var lender = new Lender({id: 0,
     name: $, 
     category: $scope.lender.category, 
     url: $scope.lender.url

function LenderEditController($scope, $location, $routeParams, Lender) {
 $scope.lender = Lender.get({id: $});
  $ = function() {

I thought the scala backend was really concise, but it turns you can also make the front end javascript just as concise.  Coupled with bootstrap css and basic html, this seems pretty good.

Suggested readings: - Wire Up a Backend example$resource$route

Thursday, August 23, 2012

Angular.js my first few mins impression

I have been looking at Javascript frameworks.  I have experience in GWT and lately trying to learn ember.js.  So far ember.js is really powerful, but the docs is not that great.  Ember.js has made a lot of changes and the only way to learn it seems to be to read the code/api.  Since my javascript is not that good, it was taking me a bit of time to learn the magic of ember.js.  This lead to me look again a bit, I found angular.js because it was in google's CDN api.

Having read the watch and read the front page of angular.js it seems to be just as powerful as ember.js.  Its got bi-directional binding, a template engine, name spaces.  The terminology they have is FP (ala Scala).  They have apply, future promise.  So gave a try.

function LenderController($scope, $http) {
 $scope.lenders = [];
  $scope.all = function() {
    $http.get('/lenders').success(function(data) {
      $scope.lenders = data;

<div class="span10" ng-controller="LenderController">
    <table class="table striped">
        <tr ng-repeat="lender in lenders"> 
            <td>{{}}</td> <td>{{lender.category}}</td> <td>{{lender.url}}</td> 
    <a href="" ng-click="all()">fetch all</a>
Pretty short and direct code for fetching from json/rest backend and displaying it on the view.  I think Angular.js is powerful and yet easy for a newbie to pickup.  That is my first few mins impression of it.

Thursday, July 12, 2012

Ruby was shiny before compared to Java, Tcl and Perl. Isn't as shiny when its beside Scala now.

Just looking at Ruby again.  My first encounter with Ruby like most people is through ROR, it was a few years back (era 1.x or maybe before that).  It was a very nice language and at that time, it wasn't that popular.  I did however convince a colleague of mine to push ROR with the help of Bruce Tate's From Java To Ruby book.  He was successful in getting ROR into a Java EE environment.  I had a quick glance of Ruby again today and in tutorial there was this code:
class MegaGreeter
  attr_accessor :names

  # Create the object
  def initialize(names = "World")
    @names = names

  # Say hi to everybody
  def say_hi
    if @names.nil?
      puts "..."
    elsif @names.respond_to?("each")

      # @names is a list of some kind, iterate!
      @names.each do |name|
        puts "Hello #{name}!"
      puts "Hello #{@names}!"

  # Say bye to everybody
  def say_bye
    if @names.nil?
      puts "..."
    elsif @names.respond_to?("join")
      # Join the list elements with commas
      puts "Goodbye #{@names.join(", ")}.  Come back soon!"
      puts "Goodbye #{@names}.  Come back soon!"


if __FILE__ == $0
  mg =

  # Change name to be "Zeke"
  mg.names = "Zeke"

  # Change the name to an array of names
  mg.names = ["Albert", "Brenda", "Charles",
    "Dave", "Englebert"]

  # Change to nil
  mg.names = nil
It's nice and concise, however it doesn't stand out as much as before.   My comparison was Java, Tcl and Perl a few years ago.  I then did a quick copy and paste, translated it to Scala.

class MegaGreeter(var names: Any = List("World")) {
  def say_hi {
    names match {
      case null => println("...")
      case listOfNames: List[String] => listOfNames foreach (n => println("Hello " + n)) 
      case _ => println("Hello " + names)

  def say_bye {
    names match {
      case null => println("...")
      case listOfNames: List[String] => println("Goodbye " + listOfNames mkString(",") + ".  Come back soon!") 
      case _ => println("Goodbye " + names + ".  Come back soon!")

object MegaGreeter {
  def main(args: Array[String]) {
    val mg = new MegaGreeter

    // Change name to be "Zeke"
    mg.names = "Zeke"

    // Change the name to an array of names
    mg.names = List("Albert", "Brenda", "Charles",
            "Dave", "Englebert")

    // Change to nil
    mg.names = null
Above is not really Scala idiomatic, but close to the original Ruby code especially how the class is created and used.  Ruby still looks nice, but not as shiny as a few years ago.  I am not here to say Scala is better than Ruby, but more of what is shiny before may not be as shiny today.  Just like Java was shiny when I first time used it about 1996, it seems these days people see Java as the wart language.  Scala will loose its shiny appeal in the next few years too.

I also been using the term "shiny", as its really about appeal.  I still use Java and occasionally Perl, even if the are not shiny anymore.  These older languages are still great in their own right.  C is still cool these days.. I think.