InquiryLabs

Politics, Programming and Possibilities

Mass Bank Withdrawal Next Month?

I’m not sure how I feel about ThisJune5th. On one hand, it could potentially cause a lot of damage to our financial infrastructure—it’s basically an organized bank run. But on the other hand, actively supporting something like this is a peaceful and legal way to support a (possibly abrupt) transition to honest (commodity-backed) money and require accountability at the hands of the Federal Reserve and large investment banks for years of dollar debasement and moral hazard.

The funny thing is, whoever made this site might get me to do what they suggest regardless of my leanings… I don’t want to find out that, come June 5th, I can’t withdraw my money.

  • 0 Comments
  • Filed under: Politics
  • TextMate Footnotes 3.0

    José Valim has improved the Footnotes plugin and kindly taken the lead on maintaining it for Rails 2.0. Read about his awesome new features here. Thanks, José!

    Victory! (Part I)

    B.J. Lawson became the Republican nominee in his North Carolina district 4 last Tuesday. Congratulations, Dr. Lawson!

  • 0 Comments
  • Filed under: Politics
  • A Visit With Lance Walley

    I had a fascinating conversation last Thursday with Lance Walley (of Engine Yard) regarding life, religion, economics and building businesses. There were so many gems that came out of the conversation that I’m afraid this post may be a little haphazard. In any case, I was pleased to finally meet him and to have a night on the town here in Chicago.

    On economics, Lance mentioned a friend who had lived in Finland for a while. This friend observed that the people there were generally happy, but the interesting thing is that they’ve essentially “squelched” the amplitude of their economy—there are fewer really poor people, and fewer really rich people. The middle “band” of the economic wave is the place of the majority. Here in America, on the other hand, the capitalist economy is a little different. People have the potential for greater wealth as well as greater disaster and poverty.

    We talked about the advantages of capitalism, especially in the context of a book called The Commanding Heights by Daniel Yergen. From what I understood, Yergen makes a convincing case for capitalism by observing the many economic systems throughout the world and through time. I brought up the point that capitalism does not work in the context of families, however. That may be somewhat absurd (applying capitalism within a family structure), but the absurdity just shows how at some level of the social structure, capitalism loses touch with humanity. So we have competing ideologies that want more or less social responsibility and redistribution of wealth.

    On another subject, Lance mentioned a book that I will definitely have to get my hands on, called “The Singularity is Near”. Apparently it’s quite popular, even though I hadn’t heard of it (but when did my having heard about it ever mean anything? :) ) The premise of the book is the the pace of progress is itself progressing, and that at some point in the near future, something that we humans create (e.g. self-replicating artificial intelligence) will be born and it will forever change the trajectory of our evolution and our planet.

    We also had a chance to talk about EngineYard and the cool things going on there. Rubinius, Merb and a full stack hosted Rails solution are all enticing projects. They’re on the edge, pushing the technology forward and for that I applaud their willingness to take risks, as well as their vision for the future.

  • 0 Comments
  • Filed under: Uncategorized
  • Installing Merb in Your Home Directory

    I have a shared account on a server where Ruby 1.8.5 is installed but Merb is not. To install gems, I added “$HOME/lib/ruby/gems/1.8/bin” to my path, and the following 3 lines to my .profile:

    export GEM_HOME=$HOME/lib/ruby/gems/1.8
    export RUBYLIB=$HOME/lib/ruby:$HOME/lib/site_ruby/1.8
    export RB_USER_INSTALL=true
    

    I had to add the last line because hpricot is a compiled extension that uses the “install” command to put it in the correct directory once it’s done. Tip came from this site. Without RB_USER_INSTALL set to true, I received the following error:

    /usr/bin/install -c -o root -g wheel -m 0755 hpricot_scan.so
    install: /…/hpricot_scan.so: chown/chgrp:
    Operation not permitted *** Error code 71
    

    Next, I installed rubygems:

    wget http://rubyforge.org/frs/download.php/20989/\
      rubygems-0.9.4.tgz
    tar xzvf rubygems-0.9.4.tgz
    cd rubygems-0.9.4
    
    ruby setup.rb all –prefix=$HOME –siterubyver=$HOME\
      /lib/site_ruby/1.8

    And last but not least:

    gem install -y merb

    Thanks to Ian Mckellar for starting me off.

    Update: For the record, the following gems were needed for my project:

    • mongrel (installs fastthread, daemons, gem_plugin, cgi_multipart_eof_fix)
    • sqlite3-ruby
    • ruby2ruby (installs ParseTree, RubyInline, hoe, rubyforge
    • merb_sequel (installs sequel, sequel_core, metaid, sequel_model, assistance)

    What Makes jQuery a Good Choice?

    I’ve been told that jQuery has been around since January of 2006. At some point during the last year, many developers within the Ruby community began to embrace it as an alternative to Prototype and Scriptaculous. Many of the programmer friends I look up to in the Merb community, specifically, are big advocates of jQuery.

    So this post is an attempt at summarizing the strengths I’ve found in jQuery as opposed to the two other javascript libraries that I’ve worked closely with: mooTools and Prototype / Scriptaculous. My motivation for this is a soon-to-be-made decision regarding the javascript library that will be used in a browser-based application that I’m working on at a company in Chicago. The application needs a simple user interface and fairly powerful front-end. I’ve advocated the use of jQuery, and thought it would be useful to set out the reasons for my preference here on the InquiryLabs blog.

    jQuery is well-documented

    There is a fine set of documentation at jquery.com. Scriptaculous hasn’t seen much improvement in its documentation in over a year. Prototype’s documentation is (in my opinion) pretty, but still lacking.

    jQuery is concise

    It uses as its central paradigm the idea of “querying” the DOM for the desired elements and returning a collection (like a dataset, but with DOM elements) and then acting on the result, or set of elements. The reason it can be concise is that the element sets are chainable. For example:

    document.ready(function() {
      for (var i = 0; i <= 6; i++)
        $(h + i +  [@id]).each(function() {
          $(<a class=”anchorlink”>\u00B6</a>).
            attr(href, # + this.id).
            attr(title, Permalink to this headline).
            appendTo(this);
        });
    });
    

    (Hat tip, lucumr) In the above example, anchor tags are added to all headlines in the document. Note the clever use of chaining which reduces the size of the code, yet retains its expressiveness.

    jQuery is easily extended

    Whether it’s a simple function or an entire plugin, jQuery is built for extending. The ability to query for “element sets” and then act directly on those results is not limited by the core code. Since it’s so easy to add custom functions to element sets, it becomes natural. For example, I found that I often needed to add or subtract a value from a CSS property. I solved this problem by extending the jQuery core element set, like so:

    jQuery.fn.cssDelta = function(property, delta) {
      var value = parseInt(this.css(property));
      return this.css(property, (value + delta) + px);
    };
    

    Using the above code, I can query for a set of elements and adjust the height property (for example) in one fell swoop. This will now add 5 pixels to the height of each “rack-item” element:

    $(.rack-item).cssDelta(height, 5);
    

    jQuery is small

    According to Jeff Robbins and John Resig, the Drupal team chose it over Prototype because it is a mere 15k compared to Prototype’s 80k. The Dojo library is even larger.

    Update:I decided to test this out myself to see what results I’d get. Resig’s comment was probably from jQuery’s earlier days when it was a micro framework. As far as I understand, it’s still possible to compress the jQuery library down to 18k or so, but that’s possible for Prototype, too. In fact, my tests show that un-gzipped, compressed code gets both down to 51k using Dojo’s ShrinkSafe online app.

    Update 2:Thanks to Peter Higgins below for commenting on the size of Dojo. For comparison, its compressed (but un-gzipped) size is 77k.

    jQuery has broad acceptance

    Feedburner, Technorati, Drupal, Edgewall Trac, etc.

    Contrasting Prototype

    Here are some examples of the concise nature of jQuery, taken from the jQuery blog:

    // AJAX Updater in Prototype:
    
    new Ajax.Updater(placeholder, url, { method: get, parameters: par });
    
    // AJAX Updater In jQuery:
    
    $(#placeholder).load(url + par);
    
    // Note: This example doesn’t deal with the obvious
    // iteration benefits we get if we wanted to load the
    // response into every <p> object, for instance.
    
    // Adding a class to an element in Prototype:
    
    Element.addClassName(element, className);
    
    // Adding a class to an element in jQuery:
    
    $(#element).addClass(className);
    
    // Adding a class to a group of elements in Prototype:
    
    $$(.element).each(function(node) {
      Element.addClassName(node, className);
    }
    
    // Adding a class to a group of elements in jQuery:
    
    $(.element).addClass(className);
    

    “That last one is the clearest example of the difference in methodology. Because jQuery is passing messages to jQuery objects, the code is barely changed. jQuery doesn’t care that we’re now adding a class to a group of objects instead of one object; the underlying code is the same (add the class to the set of elements in the object). Prototype, on the other hand, requires an iterator.”

    “And as your code becomes more complex, jQuery’s scales easily, while nested loops become the norm in frameworks like Prototype.”

    Hey, Graduate! I Love You!

    Extraordinary as it may seem, my loving and persistent wife, Kelty, has finally graduated from BYU! I’m so happy for her, and relieved to finally see her on the other side of the divide. Now we just have to get me over there :)

    Here’s a 3-minute video I made for her. Feel free to share this moment with us and send her your thoughts!

  • 1 Comment
  • Filed under: Life and Family
  • Notes on the Facets Gem

    The Facets gem is fairly popular, and for good reason. I was poking through the documentation on the plane home from Chicago (I have a contract position there for the next month) and found a couple of neat things to share:

    Facets library

    • Autoarray class—an Array that autovivifies any number of dimensions. For example:a = Autoarray.new
      a[3][4][5] = 1
      would create a 3-dimensional array with values initialized to ‘nil’ and the appropriate cell set to 1.
    • Dictionary class—a Hash that retains order. The order, by default, is whatever order its contents were given in; however, it can also enforce any arbitrary ordering that you provide.
    • Enumerable extensions—a (very nice) module that extends the Enumerable mixin. It’s huge! There are so many idioms captured in this that I can’t explain them all. But if you like Ruby for it’s concise syntax and easy chaining of things like ‘each’, ‘map’ and ’select’, you’ll like what you see in here.
    • File.rewrite—open, modify, write back to disk, all in a single ruby block.
    • FileUtils.head and FileUtils.tail—handy functions that let you get at the first few or last few lines of a file.

    There’s plenty more to look at in the Facets gem… these are just a few that caught my attention. Install the gem and then use “gem server” to check out the documentation ;)

    Did You Know About “gem server”?

    I can’t believe I didn’t know about this until recently… it’s such a gem of a tip. :)

    If you type “gem server” in the shell, you’ll start a webrick server that’s listening on port 8808 to dish out all of the help files for your installed ruby gems. Here’s a little alias I made that helps me get right to the documentation from the console:

    
    alias gemdocs="gem server >/dev/null 2>&1 & \
        sleep 0.2 ; open http://localhost:8808"
    

    Basically, it starts the gem server and ignores the log output. Next, it waits a fraction of a second for the server to start listening on port 8808, and then uses the Mac OS “open” command to open the default browser and points it to the gem server so you can start looking at your documentation.

    Having a gem server is Brilliant!

    Merb ActiveAdmin

    Introduction

    Merb ActiveAdmin is a drop-in backend for Merb applications that use the Sequel ORM. It gives application administrators direct access to specific models so they can add, edit or delete anything they need to. It also provides a way to add or remove associated data, e.g. one-to-many, or many-to-many relationships between models. These plugin features are provided with very low configuration so that setting it up is as easy as possible.

    Watch the Screencast

    The screencast is available here on a separate page.

    Links

    Download and installation instructions can be found at the github repository. See the README.markdown file.

    The git repository is hosted at my account on github.

    Final Words

    Let me know what you think. I’m curious to know, specifically, how many people use Sequel as their ORM of choice. DataMapper and Stone have also been proposed as possible ORMs to support. And of course, ActiveRecord would be a nice choice too :)

    I hope you enjoy it!