Hoptoad and Javascript, Sitting in a Tree, S-E-N-D-I-N-G – GIANT ROBOTS SMASHING INTO OTHER GIANT ROBOTS

Hoptoad and Javascript, Sitting in a Tree, S-E-N-D-I-N-G – GIANT ROBOTS SMASHING INTO OTHER GIANT ROBOTS.

I’m really excited about this new feature of HopToad.  I’ve played around with ExceptionHub but it was missing some important features like team management.  Leveraging HopToad to do this kind of JavaScript/browser level error tracking really cleanly combines two useful and similar tools for debugging a running system.

I should add that I echo the concerns of some of the commenters on the linked to blog post about security concerns.  It would be helpful if ThoughtBot followed this up with a post to address this concern in a bit more detail.

All in all though, this is nice

Up and running with MagLev

The MagLev alpha was released recently.  Before I get too far in to this post I need to make it clear that I’m not affiliated with the MagLev development team.  I’m not really even much of a Ruby interpreter hacker.  I’m a curious ruby developer that has heard some interesting things about the project and wanted to get it up and running now that it’s available.  I decided to make this post because the install and setup procedure is anything but standard.  It’s not complicated, just not what you normally would expect.

First lets get the code:

$ git clone git://github.com/MagLev/maglev.git

Initialized empty Git repository in /Users/rgarver/Sources/maglev/.git/
remote: Counting objects: 28955, done.
remote: Compressing objects: 100% (12671/12671), done.
remote: Total 28955 (delta 15669), reused 28427 (delta 15200)
Receiving objects: 100% (28955/28955), 14.97 MiB | 539 KiB/s, done.
Resolving deltas: 100% (15669/15669), done.
Checking out files: 100% (2180/2180), done.
Initialized empty Git repository in /Users/rgarver/Sources/maglev/.git/remote: Counting objects: 28955, done.remote: Compressing objects: 100% (12671/12671), done.remote: Total 28955 (delta 15669), reused 28427 (delta 15200)Receiving objects: 100% (28955/28955), 14.97 MiB | 539 KiB/s, done.Resolving deltas: 100% (15669/15669), done.Checking out files: 100% (2180/2180), done.

$ cd maglev

Great, we have the code.  Next step is to do a base install.  This installs the base libraries and GemStone which is the fabled persistence layer that MagLev has integrated.  GemStone is a object persistence layer originally built for Smalltalk.  If you haven’t ever played with Smalltalk or some of the variants (eg: Squeak) I recommend it.  It will turn your head upside down.

$ ./install.sh
[Info] Starting installation of MagLev-22578.MacOSX on sirius.local
Password:
Sat Nov 21 09:22:44 PST 2009
[Info] Setting up shared memory
  Total memory available is 4096 MB
  Max shared memory segment size is 4 MB
  Max shared memory allowed is 4 MB
[Info] Increasing max shared memory segment size to 2048 MB
kern.sysv.shmmax: 4194304 -> 2147483648
[Info] Increasing max shared memory allowed to 2048 MB
kern.sysv.shmall: 1024 -> 524288
[Info] Adding the following section to /etc/sysctl.conf
# kern.sysv.shm* settings added by MagLev installation
kern.sysv.shmmax=2147483648
kern.sysv.shmall=524288
kern.sysv.shmmin=1
kern.sysv.shmmni=32
kern.sysv.shmseg=8
[Info] Setting up GemStone netldi service port
[Info] Adding "gs64ldi  51456/tcp" to /etc/services
[Info] Downloading GemStone archive using /opt/local/bin/wget
--2009-11-21 09:22:44--  http://glass-downloads.gemstone.com/maglev/GemStone-22578.MacOSX.zip
Resolving glass-downloads.gemstone.com... 207.171.185.197
Connecting to glass-downloads.gemstone.com|207.171.185.197|:80... connected.
HTTP request sent, awaiting response... 200 OK
Length: 74858717 (71M) [application/zip]
Saving to: `GemStone-22578.MacOSX.zip'

100%[==========================================================================>] 74,858,717   847K/s   in 1m 45s

2009-11-21 09:24:32 (694 KB/s) - `GemStone-22578.MacOSX.zip' saved [74858717/74858717]

[Info] Uncompressing GemStone archive into /Users/rgarver/Sources
[Info] Linking gemstone to /Users/rgarver/Sources/GemStone-22578.MacOSX
[Info] updating MSpec, RubySpec, and RBS submodules
Submodule 'benchmark' (git://github.com/acangiano/ruby-benchmark-suite.git) registered for path 'benchmark'
Submodule 'spec/mspec' (git://github.com/rubyspec/mspec.git) registered for path 'spec/mspec'
Submodule 'spec/rubyspec' (git://github.com/rubyspec/rubyspec.git) registered for path 'spec/rubyspec'
Initialized empty Git repository in /Users/rgarver/Sources/maglev/benchmark/.git/
remote: Counting objects: 7332, done.
remote: Compressing objects: 100% (5521/5521), done.
remote: Total 7332 (delta 1595), reused 6917 (delta 1274)
Receiving objects: 100% (7332/7332), 9.90 MiB | 578 KiB/s, done.
Resolving deltas: 100% (1595/1595), done.
Submodule path 'benchmark': checked out 'd807eea7f7b2f38240bc177a0c22e599081882ea'
Initialized empty Git repository in /Users/rgarver/Sources/maglev/spec/mspec/.git/
remote: Counting objects: 2745, done.
remote: Compressing objects: 100% (1080/1080), done.
remote: Total 2745 (delta 1848), reused 2484 (delta 1644)
Receiving objects: 100% (2745/2745), 378.57 KiB | 383 KiB/s, done.
Resolving deltas: 100% (1848/1848), done.
Submodule path 'spec/mspec': checked out 'bcec47c70e0678a29fd0c1345358c4daf7b971a3'
Initialized empty Git repository in /Users/rgarver/Sources/maglev/spec/rubyspec/.git/
remote: Counting objects: 26787, done.
remote: Compressing objects: 100% (8705/8705), done.
remote: Total 26787 (delta 18332), reused 25672 (delta 17482)
Receiving objects: 100% (26787/26787), 3.71 MiB | 520 KiB/s, done.
Resolving deltas: 100% (18332/18332), done.
Submodule path 'spec/rubyspec': checked out 'b0a18cf80dc706d39ee550831b8b941224b60fb6'
[Info] Creating new default 'maglev' repository
[Info] Generating the MagLev HTML documentation
[Info] Finished upgrade to MagLev-22578.MacOSX on sirius.local

[Info] MagLev version information:
maglev 0.6 (ruby 1.8.6) (2009-11-20 rev 22578-1067) [x86_64-linux]
GEMSTONE: 3.0.0 Build: 64bit-22578
MONTICELLO: MagLev-ao.1067.mcz
MAGLEV: commit e2a4fe2e0f7ca85cdcb141e6b56913eba802eefd
        Author: Allen Otis <otisa@abaco.gemstone.com>
        Date:   Thu Nov 19 19:57:09 2009 -0800
[Info] GemStone version information:
GemStone/S 64 Bit
3.0.0 Build: 64bit-22578
Fri Nov 20  8:22:00 2009

[Info] Adding these to your .bashrc will make it easier to run MagLev
export MAGLEV_HOME=/Users/rgarver/Sources/maglev
export PATH=$MAGLEV_HOME/bin:$PATH

[Info] After you complete this upgrade and verify MagLev is working, run
  rake stwrappers
to generate the .rb files for the GemStone/Smalltalk FFI
in MAGLEV_HOME/lib/ruby/site_ruby/1.8/smalltalk/

As you can see on OS X it will build everything for 64bit which is pretty cool.  It also downloaded a bunch of support libraries and updated all of the submodules.  If you ever update the code locally you are supposed to run ‘$ ./update.sh’ to rebuild everything and get it all up and running.

Once you have it installed you should add the following lines to your .profile or .bashrc

export MAGLEV_HOME=/Users/rgarver/Sources/maglev
export PATH=$MAGLEV_HOME/bin:$PATH

You’ll need to make sure you run those lines on the command line also.  Once the environment is setup you can run ‘$ rake maglev:start’.  This command apparently boots up the core MagLev engine.

$ rake maglev:start
(in /Users/rgarver/Sources/maglev)
startstone[Info]: Starting Stone repository monitor "maglev".
startstone[Info]: GemStone server 'maglev' has been started.

Once that is started you are good to go:

$ maglev-irb
/Users/rgarver/.irbrc
error , no such file to load -- readline,
          during /Users/rgarver/Sources/maglev/lib/ruby/1.8/irb/completion.rb
error , no such file to load -- readline,
          during /Users/rgarver/.irbrc
irb(main):001:0> puts 'hi'
hi
=> nil
irb(main):002:0>

SPDY looks… possible

Google recently announced their SPDY protocol that they’ve been working on to address a number of inherent non-performant aspects of the HTTP protocol that most of the web depends on.  In the last few years the web has shifted much more towards real-time applications.  Web application development is starting to think about interaction experiences much closer to desktop apps.  It’s not out of bounds to consider the response times of certain queries on a website in terms of keystrokes (~200ms).  Moving the request/transmission protocols to catchup with this change makes sense.

One thing that I am happy about with SPDY is that is appears to be built with deployment clearly in mind.  This isn’t the first attempt to improve web speeds, it’s not even the best, but it does appear to be the simplest to deploy in to the wild and see rapid adoption.  If Apache and Firefox gained support for SDPY out of the box, and it was show that using the protocol would improve server throughput, it would be enough to shift most websites over.  That’s only two players.  That’s pretty promising.

Podcast.local – localhost podcasting

Last week I discovered a set of mp3′s covering Lean practices and principles.  You can access them here.  I’ve been on a bit of a management optimization stint lately and Lean is a very natural extension of Agile software development in to a broader management context.  It largely predates modern software techniques and represents one of the early generalizations of the Toyota Production System.

In any case that is not what I’m here to talk to you about.  In looking through these mp3′s the list of webinars was not collected in to any sort of podcast format.  This is frustrating because this would be ideal commute time listening on my iPhone.  Out of this frustration came podcast.local.  Podcast.local is a simple Rails application (really simple) that allows you quickly create a podcast through a series of forms.  The name comes from the naming convention provided by the Passenger preference pane on OS X.  If you set it up through the pref pane you will just need to go to http://podcast.local.  From there you can create your podcast one episode at a time and then subscribe to them through your iTunes.  The coole thing is that because it’s on the web iTunes just picks it and starts downloading episodes.

Like I said above, this application is too simple to go in to much detail.  I used it to do some experimentation with a few technologies that I haven’t had much time to mess around with.  Namely Blueprint CSS, jQuery, jQuery UI, and Paperclip.  Enjoy!

Back to jQuery

So I tried Red for a while (short while) and was all excited and thought it was really cool and I’d be using it forever. Then I tried to make a Ajax call to a rails app and got back JSON, crap. Red doesn’t support parsing JSON. I eventually figured it out and made a pretty cool billing summary widget using Red. But that took me a few days. And it was really hard. Much harder than it needed to be.

I like what Red was trying to do, but looking back I think I knew it was too good to be true. It’s not quite there and requires a lot of hacking to do most practical things. I’m now using jQuery. I reimplemented the billing summary using jQuery in a couple of hours, and most of that time was spent re-learning jQuery. I’m actually pretty happy with it after using it for a few weeks. I thought I would always return to Prototype.

In my excitement for learning a new tool I discovered the extension jQuery UI and their Themeroller. This has got to be one of the cooler javascript library extensions that I’ve seen. ExtJS tries to provide a will UI toolkit and has a theme API, but the Themeroller for jQuery UI is really sweet and super simple. As a basis for a back office admin it is ideal, and I can see a number of opportunities in a broader set of situations. The icon library alone has made producing simple, intuitive interfaces really easy.

JSON for Red

I’ve been playing around more with Red.  I alternate between really liking it and totally pulling my hair out.  On a order form app that I’m building I made some very quick work of a dynamically updating billing summary div.  It came together very quickly until I added the AJAX piece.  AJAX support in Red is actually very good, but JSON support is non-existent.  This made Ryan a sad boy.  I dug around to see what other people have done and found that they haven’t done much.  There is some stub code for a Request::JSON that my be what I’m looking for at some point, but I need it now.  So here is what I did:

class Module
  def define_method(sym, &block)
    `this.prototype['m$'+sym.__value__]=block.__block__.__unbound__`
    `Red.updateChildren(this)`
    `Red.updateIncluders(this)`
    return `block`
  end
end

class Object
  def self.from_json(text)
    ret = Object.new
    meths = []
    `var v = eval("("+#{text}.__value__+")")`
    `for(var member in v){#{meths}.push(new Array($q(member), $q(v[member])))}`
    meths.each do |meth|
      ret.class.send(:define_method, meth[0]) do
        meth[1]
      end
    end
    return ret
  end
end

Now doing a simple AJAX call that returns JSON becomes really easy:

@req = Request.new(:url => '/orders')
@req.upon(:response) do |response|
  new_data = Object.from_json(response.text)
  @summary = new_data.summary
  @subtotal = new_data.subtotal
  @total = new_data.total
end
@req.execute(:data => {'plan_id' => @plan, 'promo' => @promo})

A few things to note here.  The section that defines `define_method` on `Module` is actually back ported from the current master branch of Red.  This works pretty well, though I haven’t tried it with a JSON string that describes a living object.  But I don’t think it’s too far from being able to handle that.