Sunday, May 27, 2012

Short comparison of Ember.js and GWT

Its been a while since I posted anything here, really hard to make continuous post.  Well try again for the n-th time.

I have been using Google Web Toolkit (GWT) for while, as this is what we use at work.  Its pretty good and has lots of positives, however it also has it's own negatives.

Lets go with the positives first:
  • For some people that knows Java they don't have to learn JS to develop full featured web apps
  • Existing java tooling works on GWT projects.  Re-factoring, IDE support, etc.
  • Performance of GWT is still the best among any JS frameworks
  • Pretty good documentation and examples
Now for the negatives:
  • Not learning JS, or some people will need to learn Java to develop JS code  
  • GWT seems to be on its own eco system outside of the wider JS eco system
  • Sometimes hard to control the html, making iterative changes with a web designer significantly more harder.  This is even using ui binder
  • REST/JSON still seems to be 2nd citizen in GWT.  There is autobeans in GWT now, however still lots of plumbing to do or use 3rd party library.
Using GWT to architect a full blown web app is great.  Using established patterns such as Model View Presenter (MVP), a cousin of the more popular Model View Controller (MVC) pattern.  For the past few years there has been a lot of JS MVC frameworks coming out.  A quick look of the Todo MVC project will give us a lot of different implementation.  (The GWT implementation hasn't been pulled yet).  One of the JS MVC framework that's been gathering a bit of attention is Ember.js.

I gave ember.js a try over the weekend, its been initially a bit frustrating.  Like always when you learn something new, sometimes we just need to unlearn our own old learnings.  Ember documentation is a bit confusing, as its formatted on how to use the different features.  Some of the materials I have found to helpful in getting me running are:


After things started to fall in place, ember.js seems to be pretty straight forward.  Compared to GWT there is really significantly less abstractions.  As ember.js really tries get you in the middle of JS, HTML and CSS.  I am still unsure on how unit testing will be done, haven't look at ember data yet, etc.  However with this initial code:

var App = Em.Application.create();

App.Plant = Ember.Object.extend({
 id: 0,
 name: null,
 description: null
});

App.PlantsView = Em.View.extend({
 plantsBinding: 'App.PlantsController.content'
});


App.PlantsController = Em.ArrayProxy.create({
 content: [],
 
 init: function() {
  var me = this;
  var url = 'http://localhost/plants';
  $.getJSON(url,function(data){
    me.set('content', []);
    $(data.plants).each(function(index,value){
        var plant = App.Plant.create({
            id: value.id,
            name: value.name,
            description: value.description,
        });
        me.pushObject(plant);
    });
  });
 }
 
});

  

As you can see its really straight forward to get data from a rest/json server.  I have an equivalent GWT project, but its too big to post here.  However the equivalent GWT functionality would include.  A model class, a ui binder file, an entry point class, a presenter interface, a view interface, a presenter implementation, a view implementation, http get code, etc.

This doesn't mean longer code is worse code, I am not in the camp of Java is bad too much typing.  I still use Java, although less these days as Scala has pretty much filled the space.  Even with the above code, one can see JS short coming of not having name spaces and no real support for OOP.  However one can see also there is a lot less boiler plate and more natural integration with JS and HTML.  When I mean less boiler, I do not mean about Java's verbose code but the bindings are straight forward.  More natural integration, I just used jQuery's getJSON function straight out of the box and handlebars' template inside html.  GWT has JSNI to call jQuery, but that is less natural and not used often.

Ember.js seems to be promising for organizing web apps.  Then coupled with other mature JS frameworks like jQuery, I think it may make GWT a bit heavy for some use cases.  I am still thinking of looking at Scala+GWT, aside from getting to use Scala to do JS I don't see a lot of difference from normal GWT.

Sunday, September 18, 2011

Verify TRIM support on Linux

Wasted my time today puzzling why the trim support of my ssd does not work, or I thought it wasn't but was working alright. When you google "linux trim verify" the link below and most people link to the site below. Apparently the tests is not fully correct. Most of the time it works for others, but not me. Maybe it has to do that I formatted my ext4 w/ -E stripe-width=128
Anyway this is a better test I found, but I can't seem to see the link anymore. Using my bash history for reference.
dd if=/dev/urandom of=tmpfile bs=1M count=10 && sync
hdparm --fibmap tmpfile
hdparm --read-sector [address between begin_LBA and end_LBA of previous command] # expecting random numbers here
rm tmpfile && sync && sleep 120
hdparm --read-sector [address between begin_LBA and end_LBA of previous command] # expecting zeroes
The real key is the sector address is somewhere in between and NOT the start sector, as its possible the trim command will not set things to zeroes if files overlap. As it had happened to me 9 out of 10 tries using the test below I get random numbers still. The test above I get zeroes consistently.

Manual setup of UEFI, GPT and GRUB2

I recently got a Crucial m4.  I then have to transfer my existing HDD on it.  Its easier to do a clean install of Oneiric and it would pretty much do UEFI + GPT + GRUB2 for you.  However if you want to manually transfer everything I did the following steps:


  • Boot on Oneiric live CD or another boot this that will boot in UEFI mode. Its important that boot is on UEFI mode and not BIOS mode
  • Go to a shell and install gdisk as we want to partition the SSD w/ GPT and not MBR. fdisk only supports MBR
    apt-get install gdisk
    
  • Partition a EFI system partition.  This would hold grub2 files later and other boot loaders if needed.  I partitioned mine on sda1 as type EF00 (EFI System) w/ the size of 200mb.  Yes a bit bigger than what is needed however most people recommend 200mb as some boot loaders needs a bigger space.
  • Format the partitions.  The EFI System partition is formatted as vfat, as per EFI spec.
    mkfs.vat /dev/sda1
    mkswap /dev/sda2
    mkfs.ext4 -E stripe-width=128 /dev/sda3
    mkfs.ext4 -E stripe-width=128 /dev/sda4
    
    I put in a stripe width of 128 k as there are some recommendation this is optimal for SSD. However test suggest that your mileage may vary.
  • Mount and create the dirs on EFI system partition
    mkdir /boot/efi
    mount /dev/sda1 /boot/efi
    mkdir -p /boot/efi/efi
  • Install grub efi
    apt-get install grub-efi-amd64
    
  • Setup grub on the EFI system partition
    modprobe dm-mod
    grub-install --boot-directory=/boot/efi/efi --bootloader-id=GRUB2 --no-floppy --recheck
    cp /usr/share/grub/unicode.pf2 /boot/efi/efi/grub/
    cp /boot/grub/grub.cfg /boot/efi/efi/grub/grub.cfg
    
    I copied my old grub.cfg and update the UUID to point to the new SSD
  • Setup the EFI boot entry
    modprobe efivars
    efibootmgr --create --gpt --disk /dev/sda --part 1 --write-signature --label "GRUB2" --loader "\\EFI\\grub\\grub.efi"
    
    GRUB2 is the entry that would appear on the EFI bootloader.
The following resource helped me a lot
https://help.ubuntu.com/community/UEFIBooting#Install_GRUB2_in_.28U.29EFI_systems

I am still working out on the graphics output,  This would only give you a text based grub.

Saturday, January 8, 2011

HP 6910p 3G on linux

I got the 3G hs2300 on the 6910p running before, but it was a long time ago. I would need internet access again on the road. I detached the battery and put in the sim card to test. It seems modem can't be detected. Doesn't appear on lsusb, not much clue on dmesg, I verified that its turned on bios, started to look around forums, tried various modprobe, was going to start using usb-modeswitch.

I then decided to reboot to Windows after several years of not going there. HP wireless assistant tells that its disabled as that the gsm sim is accessible and suggest to close or put the battery back. I put the battery back, HP wireless assistant changes status to still disabled but now suggest to fix via Device Manager. No luck, Device Manager can't find drivers, etc. So did not want to spend it running on Windows and maybe putting the battery back is enough to get it running on Linux again.

Reboot to linux, network manager picks it up. Nothing to setup aside from APN, etc. No driver install, etc. Just put the battery back. Hopefully this post saves someone a few hours diagnosing the problem. Just put the battery back and linux should see the hs2300 3G modem.

Tuesday, August 31, 2010

More on Scala

Get Started on Debian/Ubuntu


Install scala, this would install version 2.7.7 though, 2.8.0 has just been out recently

apt-get install scala

Run the scala shell

scala

(optional) Quick upgrade to scala 2.8.0, install scala as per above and just copy the newer jars
Download scala from http://www.scala-lang.org/downloads and extract the tarball

tar xzf scala-2.8.0.final.tgz
cd scala-2.8.0.final/lib
cp scala-compiler.jar scala-library.jar scala-dbc.jar /usr/share/java


Get Started on Eclipse


Get the eclipse scala plugin http://www.scala-ide.org/ this would include the scala jar, compiler, console, etc.
When you have the plugin the following options are available

  • create a new scala project

  • right click on existing java project and add scala nature and you can now start coding both java and scala together

  • run the scala console inside eclipse



Reference and Links


Below are some useful reference

Scala Tutorial - useful w/ Java Background

Scala by Example - a little long, more like a scala cookbook

Programming Scala

First Steps to Scala - a bit old but still useful

Scala Idioms, Step 1, Lists and Maps - a bit old but quick way to learn about lists. Tuples are using old syntax of {x, y} which is now changed to (x, y)

Who is using Scala




Frameworks and OSS Projects


Wednesday, August 18, 2010

Looking at Scala again

I have been look at scala and lift (web framework built on scala), on and off about a year now. I have revisited it again for the past few weeks. Scala as a language seems to be promising. For me it adds something new to the main stream languages today, like pattern matching (not regexp), functional programming, actors library. There are some languages that have these properties but I think scala has got some transitional properties giving some balance. Using scala you get to access java libraries natively, despite its terse syntax it is still a static language, this would mean tool developers will have an easier.

Scala
Lift

I have also been re-using emacs again. Some interesting scala emacs some stuff.

Scala emacs tools

Friday, July 16, 2010

Low tech stuff

I have started on computers when its wasn't hip yet. When I was a kid, I toyed around a PC XT on green monochrome monitor. Then on to doing BASIC, then to over clocking on a Pentium when Asus brought out the first overclock board. Buying a linux book to get a slackware CD as downloading over a 2400bps modem is very slow. Time has passed so fast.

Lately the latest and greatest tech stuff hasn't been appealing for me. I do get touch the nice smart phones at work. Although new tech stuff isn't as appealing as before. Not sure why, maybe just too many tech stuff going around these days.

Back in the 80s there was something cool, which wasn't computers. I am talking about RC. Remote Control cars, me and my son have a few them.



These are low tech stuff, but very interesting for me. Its one of the interesting things to me as kid back then, aside from playing space wars on a PC XT. This appeals for me especially now as my son is able to build and play with me right now.