Thursday, August 30, 2007

refactoring Ruby in TextMate

I'd like to hear from TextMate+Rails users: what tools do you use to Refactor your Ruby code inside TextMate?

Monday, August 27, 2007

anatomy of a memcached daemon

Before you start experimenting with memcached, here's a quick description of the command line options that will be used when starting it up. (note there is no configuration file for memcached).

It seems as if the most common command line options are used: -l -d -p -m -c

Here is what each of them do, per the memcached man pages:

-l
Listen on ; default to INDRR_ANY. This is an important
option to consider as there is no other way to secure the
installation. Binding to an internal or firewalled network
interface is suggested.

-d Run memcached as a daemon.

-m
Use MB memory max to use for object storage; the default
is 64 megabytes.

-c
Use max simultaneous connections; the default is 1024.

-p
Listen on TCP port , the default is port 11211.

Here is an example command line script to fire up memcached with some options:

$ memcached -d -m 128 -l 10.0.0.40 -p 11211
This will start memcached as a daemon, allocate 128 MB memory max for storage of the memcached hashed query, listen on ip address 10.0.0.40, and listen on TCP port 11211.

So that's all there is to starting the daemon with a variety of options. Note there are more options in the man pages, but the above options are enough to give it a whirl. If you ever need to stop your memcached daemons, issue the following command:
$ killall memcached
Here is a couple helpful posts of using memcached with Rails:

http://townx.org/rails_and_memcached

http://nubyonrails.com/articles/2006/08/17/memcached-basics-for-rails

http://avoir.uwc.ac.za/avoir/index.php?module=wiki&pagename=MemcachedInstallDebianEtch&action=wikilink

installing MemCacheD on Mac OS X with MacPorts

installing MemCacheD on Mac OS X with MacPorts couldn't be easier:

1. as long as you have MacPorts (frmly DarwinPorts) installed on your Mac, just open up a bash shell and type the following:

$ sudo port install memcached
Because memcached utilizes libevent, MacPorts will check to see if libevent-dev is found... if it is not, it will fetch libevent-1.3d.tar.gz from http://monkey.org/~provos/, verify checksum, install... then likewise fetch memcached, verify checksum, extract, configure, install. This currently at the time of this post installs memcached 1.2.2_1.

Sunday, August 26, 2007

Rails stack on Mac OS X and Ubuntu 6.06

Been researching and practicing with Rails for a little while now, and went through the process of updating my setup on my Mac book pro (Mac OS X), as well as on an Ubuntu (Dapper, 6.06) test machine (actually a test VM).

Most of this is similar to what you would find inside of "Agile Web Development with Rails" by the esteemed DHH and Dave Thomas (by the way, if you're interested in Rails development, imho, it's the best book around by far -- very comprehensive and a smooth read). It is also similar to this post by James Duncan Davidson.

So why am I posting this here? Well because in order for me to get it to work on both my Mac and on Ubuntu 6.06, I had to tweak the instructions slightly for a variety of reasons (some version upgrades, etc).

Posting this on my blog not only to share, but for my own future reference. So here goes, for both Mac OS X and Ubuntu Dapper Drake 6.06, a line by line installs of a Rails stack: Apache 2.2, mySQL5 database server, SVN, Ruby 1.8.4, Ruby Gems, Ruby Termios Library, Mongrel, Mongrel Cluster, Capistrano 2.0.

For Mac OS X on Mac Book Pro (Intel-based Mac):

# first you need to download and install DarwinPorts (now known as MacPorts) 1.5.2:
http://darwinports.com/

# once you have MacPorts installed, you may commence with the Rails stack install...
$ sudo port install apache2
$ sudo port install mysql5 +server
$ sudo port install subversion +tools
$ sudo port install ruby
$ sudo port install rb-rubygems
$ sudo port install rb-termios
$ sudo gem install -y rake
$ sudo gem install -y rails
$ sudo gem install -y capistrano
$ sudo gem install -y mongrel
$ sudo gem install -y mongrel_cluster
For Ubuntu 6.06 VM on Mac Book Pro (Intel-based Mac):
$ sudo apt-get install apache2
$ sudo apt-get install mysql-server
$ sudo apt-get install openssl libssl-dev
$ sudo apt-get install libdb4.3 libdb4.3-dev db4.3-util libdb4.3++c2 libdb4.3++-dev
$ wget http://www.shiftingheat.com/packages/subversion/subversion_1.4.0-1_i386.deb
$ sudo dpkg -i subversion_1.4.0-1_i386.deb # install ruby gems from source:
$ sudo apt-get install ruby
$ wget http://rubyforge.org/frs/download.php/17190/rubygems-0.9.2.tgz
$ tar xzvf rubygems-0.9.2.tgz
$ cd rubygems-0.9.2
$ sudo ruby setup.rb
$ sudo gem update --system

# now install 'build-essential' before installing gems:
# Compilers (and manual pages [optional])
$ sudo apt-get install build-essential manpages-dev
$ sudo apt-get install ruby1.8-dev

# now install the following RubyGems: Rake, Rails, Capistrano, Mongrel, Mongrel_cluster...:
$ sudo gem install --include-dependencies rake
$ sudo gem install --include-dependencies rails
$ sudo gem install --include-dependencies termios
$ sudo gem install --include-dependencies capistrano
$ sudo gem install --include-dependencies mongrel
# selected: 2. mongrel 1.01 (ruby), 1. fastthread 1.0 (ruby)
$ sudo gem install --include-dependencies mongrel_cluster
I will try and make a follow up post on Configuring Mongrel and Deploying with Capistrano 2.0, and connecting Apache to Mongrel, installing MemCacheD... but this at least gets the Rails stack installed with gems.

Hope this saves you some time in your Rails development-

Thursday, August 23, 2007

memcached

Check out memcached, if you're into researching ways of making your web apps speedy through clever database caching. (used by LiveJournal, Slashdot, Wikipedia, SourceForge). Very very cool.

By having your app first check the memcache instead of going to the database directly, you reduce the overhead that is inherent with ACID properties in relational database management system transactions. --as I understand it from reading about it on a few sites, by hashing database records in a cache reading from that hash where possible and updating the hash when that data is not available, you end up greatly reducing the demand on the database.

Makes me excited to think about the possibilities of an upcoming RESTful Rails app deployed on an clustered Ubuntu instance on EC2, utilizing memcached, that is Gears-enabled for offline capability as well... whoops, I wandered off...

Here's some info on memcached. I'm going to definitely check it out and try to implement:

memcached is a high-performance, distributed memory object caching system, generic in nature, but intended for use in speeding up dynamic web applications by alleviating database load.

http://www.danga.com/memcached/

http://www.deveiate.org/projects/RMemCache/


http://nubyonrails.com/articles/2006/08/17/memcached-basics-for-rails

Tuesday, August 21, 2007

domo arigato, Shiira

...if you drive a Mac, check out Shiira. Came across it during a Rails/Capistrano Peepcode by Geoff Grosenbach (which are all awesome, btw, if you're interested in Rails development. Peepcode is like a microwave oven for learning).

I had seen Geoff using Shiira in a few PeepCodes and decided to give it a whirl... it has some interesting features, and is SUPER FAST on my MacBook Pro. (that's a quantitative measurement ;)... but give it a try, doubt you'll disagree)

Shiira is based on on WebKit and written in Cocoa. (in case you haven't noticed, there is a lot of momentum with WebKit, given Safari, iPhone, Adobe AIR...)

Wednesday, August 01, 2007

podcast on Ajaxian : Joe Hewitt interview

This dude is cool. A Titan.

I highly recommend skating over to Ajaxian.com and queue-ing up the podcast

Hewitt …orig worked at Netscape since 2000 …… DHTML ever since… worked on Netscape 6 and 7… …then helped create FireFox (he says “we wanted to create a browser that didn’t suck”)… pretty much single-handedly created Firebug (which pretty much every Ajax dev uses nowadays)… created Parakey spinoff from Firefox with fellow FireFox dev Blake Ross…acquired by FaceBook this month. [It sounds like, from Joe, we will see the fruits of Parakey’s labors in the near future. As prolific as Joe Hewitt is, they have not yet released the product they have been working on for 2 years, and Facebook bought it. It's going to be fun to watch what happens there]

(…check out iUI…)

Hewitt sayz:

‘Apple has the lead in CSS (WebKit)’

‘Mozilla has the lead in JavaScript (Gecko)’

‘Python is my favorite language’

“between Mozilla and Microsoft, my grandchildren will write some great apps”

“Mozilla has a large legacy codebase… spending a lot of time refactoring code, instead of creating new features”

“I liked what Flock did… would have liked to see more of that with FireFox… maybe they’re right, because Flock is struggling”

iPhone: “I’m as cynical as it gets with mobile development. But the iPhone is going to be huge. Every other manufacturer will copy the form factor. Hopefully many will follow by using WebKit … Nokia uses WebKit …WebKit is amazing. Open Source. Small and Light. Nothing stopping anyone who doesn’t have political reasons for using WebKit”

This is pretty funny conversation from the podcast:

When asked ‘how come you are able to churn out so many apps, side projects like Firebug, iUI, in addition to parakey work, etc’:

Hewitt: “No no… I decided a few years ago I was going to do nothing else but write code”

[big laughter from Ben, Dion]

Hewitt: “I’m not even kidding… my girlfriend and I broke up, I have this routine where I--

Almaer [jokes]: “...the dog died…”

Hewitt: “hey you have to put food in the bowl, who has time for that?!”

Great stuff. And awesome information.

The Forever Inspirational, Howard Armstrong

Howard Armstrong ...a true genius, and incredibly driven man. ...an earth mover. He was made, not by politics or marketing, but by his own authentic understanding of the science behind his inventions, and his effort to drive them to fruition. What an innovator.

Most of Armstrong's life was a phenomenal inspiration. But he was ultimately broken by David Sarnoff, his long time colleague. RCA's cutthroat tactics coming after 20 years of a futile legal battle with the boastful and baseless Lee DeForest.

Despite his greatness, Armstrong's demise was largely because he never learned to compromise, always seeking the absolute victory, on his own.