2011 New Year’s Resolutions

Never been too big on New Year’s Resolutions, at least not writing them down and reviewing them a year later. Thought I would give it a try… Happy New Year!

  1. Eat better, eat out less
  2. Less gym, more jogging/walking/biking/hiking
  3. Learn Ruby on Rails and complete a project using it
  4. Create and learn to live within a budget
  5. (Re)Learn to play the guitar
  6. (Re)Learn to make beer
Posted in Uncategorized | 1 Comment

Rails and MySQL on Ubuntu 10.10


Learning Ruby on Rails with MySQL on a Ubuntu machine is quick and easy with sqlite3 – the default for a Rails project. On a production project though you will probably need a database with a little bit more muscle. Let’s install MySQL and the needed connectors to get Rails to talk to it.


Make sure MySQL and all the necessary development packages are installed:

sudo apt-get install mysql-client-5.1 mysql-server-5.1 \
libmysqlclient16 libmysqlclient16-dev

Then get the needed RubyGems packages:

sudo gem install mysql

Then if you start a new project with MySQL:

rails new mysqltest -d mysql

And try to run the console:

cd mysqltest/
rails console

You will probably get an error like this:

Could not find gem 'mysql2 (>= 0, runtime)' 
      in any of the gem sources listed in your Gemfile.
Try running `bundle install`.

Easy enough… do as it says:

bundle install

You should see “Installing mysql2 () with native extensions” and hopefully no errors. Just edit your config/database.yml and you’re all set.

Posted in Linux, Ruby on Rails | Leave a comment

Installing Rails 3 on Ubuntu 10.10



Installing Ruby on Rails using Ubuntu’s native package manager certainly has its advantages — namely keeping the packages up to date for you — but currently, this will get you older versions of Ruby and Rails.  Ruby 1.8.7 and Rails 2.3.5 are fine, but Rails 3 has many improvements and new Ruby developers should probably start with this version.

Get the latest version of Ruby here:

http://www.ruby-lang.org/en/downloads/

tar zxvf ruby-<version>.tar.gz
cd ruby-<version>
./configure
sudo make && make install

To avoid a “no such file to load: zlib” error later, get ruby-zlib here:

http://raa.ruby-lang.org/project/ruby-zlib

tar zxvf ruby-zlib-<version>.tar.gz
cd ruby-zlib-<version>/
sudo ruby extconf.rb
sudo make && make install

Download and install RubyGems here:

http://rubyforge.org/frs/?group_id=126

tar zxvf rubygems-<version>.tgz
cd rubygems-<version>/
sudo ruby setup.rb

Then install Rails 3 with RubyGems:

sudo gem install rails

Use apt-get to install ‘sqlite3′ and ‘libsqlite3-ruby-<most-recent-version>’, and then:

bundle install

… will install ‘sqlite3-ruby’ for you.

That’s it!  Decide on a directory where you want to do your development and then:

rails new testsite

Jump into your new ‘testsite’ directory and try to start the server:

rails server

Posted in Linux, Ruby on Rails | 1 Comment

webOS Submit on Enter

Palm webOS Submit TextField on Enter
webOS Button widgets are cool, but they are HUGE!  In most cases, I hate sacrificing the screen real estate required to add a Button just to submit a TextField on a Scene.

So if you want to skip the button and process the input when the user hits enter, how do you make that work?  The webOS documentation doesn’t really make this clear or obvious.

I found this cool little trick on webOS 101, but the problem I ran into was that my “keyupHandler” function then did not have access to the TextField value.  “keyupHandler” is now scoped to this.controller.document and I wasn’t able to get back to this.controller.   The code below doesn’t work:

MyProgram.prototype.setup = function() {
    this.txtModel = { value: "", disabled: false };
    this.txtAttr    = { multiline: true, enterSubmits: true };
    this.controller.setupWidget('txtField',
        this.txtAttr,
        this.txtModel
    );
    this.controller.document.addEventListener("keyup",
        this.keyupHandler,
        true
    );
};

MyProgram.prototype.keyupHandler = function() {
    var text = this.txtModel.value;
};

I kept getting a “cannot get value of undefined” error. So firing the “keyup” event from this.controller.document changes the scope of the handler function? Maybe somebody with more Javascript skillz than me can comment on that…

But I knew there must be a better way… a more “webOS way”…

An itty-bitty little blurb in Frank Zammetti‘s excellent book Practical Palm Pre webOS Projects mentioning the requiresEnterKey attribute. Aha! “… will make the user have to press the Enter key… to fire the Mojo.Event.propertyChanged event”. Sweet! Now I can detect the enter key because it is the only key press that will fire an event in the TextField. The code below does the trick:

MyProgram.prototype.setup = function() {
    this.txtModel = { value: "", disabled: false };
    this.txtAttr    = {
        multiline: true,
        enterSubmits: true,
        requiresEnterKey: true
    };
    this.controller.setupWidget('txtField',
        this.txtAttr,
        this.txtModel
    );
    this.controller.listen("txtField",
        Mojo.Event.propertyChange,
        this.submitHandler.bindAsEventListener(this)
    );
};
MyProgram.prototype.submitHandler = function() {
    var text = this.txtField.value;
};
Posted in Palm, webOS | Tagged | Leave a comment

Debian 6 Audio Problems

I love Debian and prefer to use it over Ubuntu, but one of the main things that keeps driving me back to Ubuntu is audio problems in Debian. Or… at least I’ve always assumed it’s a Debian problem.  You start up the machine and audio works great.  At some point you realize the audio has stopped working.  Nothing works — system sounds, TweetDeck notifications, VLC…  I think the problem actually stems from the Flash plugin though. Any time I view a video clip in my browser’s Flash plugin, the plugin seems to “grab” control of the sound server and doesn’t let go – even after I kill the clip, close the tab, even quit the browser.

Restarting the sound server seems to do the trick though. You will need to run this command as root and *warning* – it will crash the Flash plugin. So don’t restart sound in the middle of your favorite YouTube vid.

# alsa force-reload
Posted in Linux | Tagged | Leave a comment