<?xml version="1.0" encoding="utf-8"?>
<feed xmlns="http://www.w3.org/2005/Atom">
 
 <title>Code Like Zell</title>
 <link href="http://feed.codelikezell.com/codelikezell" rel="self"/>
 <link href="http://codelikezell.com"/>
 <updated>2011-02-25T15:38:07-08:00</updated>
 <id>http://codelikezell.com</id>
 <author>
   <name>Lou Zell</name>
   <email>lzell11@gmail.com</email>
 </author>

 
 <entry>
   <title>Setting up Rails, MySQL, PHP, Apache, and Git on EC2</title>
   <link href="http://codelikezell.com/setting-up-rails-mysql-php-apache-and-git-on-ec2"/>
   <updated>2011-02-19T00:00:00-08:00</updated>
   <id>http://codelikezell.com/setting-up-rails-mysql-php-apache-and-git-on-ec2</id>
   <content type="html">&lt;p&gt;This is a step by step tutorial on setting up an Amazon Linux EC2 instance with Rails, &lt;span class=&quot;caps&quot;&gt;PHP&lt;/span&gt;, MySQL, Apache, and Git.  You will have three &lt;a href=&quot;http://aws.amazon.com/ebs/&quot;&gt;&lt;span class=&quot;caps&quot;&gt;EBS&lt;/span&gt;&lt;/a&gt; volumes mounted, one for each of the following:&lt;/p&gt;
&lt;ul&gt;
	&lt;li&gt;MySQL data and logs&lt;/li&gt;
	&lt;li&gt;httpd virtual hosts and logs&lt;/li&gt;
	&lt;li&gt;Git repositories&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;You will bundle your instance into it&amp;#8217;s own &lt;span class=&quot;caps&quot;&gt;AMI&lt;/span&gt;, launch an instance from that &lt;span class=&quot;caps&quot;&gt;AMI&lt;/span&gt;, and recreate the state of your first instance by moving &lt;span class=&quot;caps&quot;&gt;EBS&lt;/span&gt; volumes.&lt;/p&gt;
&lt;h3&gt;Launching and Accessing Your First Instance&lt;/h3&gt;
&lt;p&gt;The first thing we need is a set of command line tools for accessing &lt;span class=&quot;caps&quot;&gt;AWS&lt;/span&gt;.  For this tutorial we will be using &lt;a href=&quot;http://timkay.com/aws&quot;&gt;Tim Kay&amp;#8217;s &lt;span class=&quot;caps&quot;&gt;AWS&lt;/span&gt;&lt;/a&gt;.  To install:&lt;/p&gt;
&lt;pre class=&quot;boxed&quot;&gt;
  $ cd /usr/bin
  $ sudo curl https://github.com/timkay/aws/raw/master/aws -o aws
  $ sudo chmod +x aws
&lt;/pre&gt;
&lt;p&gt;Next, get your &lt;span class=&quot;caps&quot;&gt;AWS&lt;/span&gt; access keys by going to your &lt;a href=&quot;http://aws.amazon.com/account&quot;&gt;&lt;span class=&quot;caps&quot;&gt;AWS&lt;/span&gt; Account page&lt;/a&gt; and clicking on Security Credentials.  Under Access Credentials will be two keys: an Access Key and a Secret Access Key.  Substitute your keys into the following:&lt;/p&gt;
&lt;pre class=&quot;boxed&quot;&gt;
  $ echo &quot;&amp;lt;your-access-key&amp;gt;&quot; &amp;gt;&amp;gt; ~/.awssecret
  $ echo &quot;&amp;lt;your-secret-key&amp;gt;&quot; &amp;gt;&amp;gt; ~/.awssecret
  $ chmod 600 ~/.awssecret
&lt;/pre&gt;
&lt;p&gt;Now we can see what regions are available for our EC2 instance:&lt;/p&gt;
&lt;pre class=&quot;boxed&quot;&gt;
  $ aws describe-regions
&lt;/pre&gt;
&lt;p&gt;Let&amp;#8217;s tell aws what region to use.  For pricing on the various regions, go &lt;a href=&quot;http://aws.amazon.com/ec2/pricing&quot; title=&quot;EC2 Pricing&quot;&gt;here&lt;/a&gt;.  I am using us-east-1:&lt;/p&gt;
&lt;pre class=&quot;boxed&quot;&gt;
  $ echo &quot;--region=us-east-1&quot; &amp;gt;&amp;gt; ~/.awsrc
&lt;/pre&gt;
&lt;p&gt;And let&amp;#8217;s see what zones are available within the region we selected:&lt;/p&gt;
&lt;pre class=&quot;boxed&quot;&gt;
  $ aws describe-availability-zones
&lt;/pre&gt;
&lt;p&gt;Before we launch an instance, we need to setup a key pair and security group.  The key pair will be used to access the instance for the first time, we will name the key pair ec2temp:&lt;/p&gt;
&lt;pre class=&quot;boxed&quot;&gt;
  $ aws add-keypair ec2temp &amp;gt; ~/.ssh/ec2temp.key
  $ chmod 400 ~/.ssh/ec2temp.key
&lt;/pre&gt;
&lt;p&gt;The security group specifies what ports to open on the instance.  We will open ports 22, 80, and 443; you can leave off 443 if you do not need &lt;span class=&quot;caps&quot;&gt;HTTPS&lt;/span&gt;.  Let&amp;#8217;s name the security group Web1:&lt;/p&gt;
&lt;pre class=&quot;boxed&quot;&gt;
  $ aws add-group Web1 -d &quot;Ports 22 (ssh), 80 (http), and 443 (https) are open&quot;
  $ aws auth Web1 -P tcp -p 22 -s 0.0.0.0/0
  $ aws auth Web1 -P tcp -p 80 -s 0.0.0.0/0
  $ aws auth Web1 -P tcp -p 443 -s 0.0.0.0/0
&lt;/pre&gt;
&lt;p&gt;We are now ready to launch an instance.  We are going to start with an Amazon Linux S3-Backed 32-bit &lt;span class=&quot;caps&quot;&gt;AMI&lt;/span&gt;, found &lt;a href=&quot;http://aws.amazon.com/amazon-linux-ami&quot; title=&quot;Amazon Linux&quot;&gt;here&lt;/a&gt;.  The &lt;span class=&quot;caps&quot;&gt;AMI&lt;/span&gt; ID is &lt;code&gt;ami-d59d6bbc&lt;/code&gt;.  Here I am launching a small instance in the us-east-1a zone with the ec2temp key pair and the Web1 security group:&lt;/p&gt;
&lt;pre class=&quot;boxed&quot;&gt;
  $ aws run ami-d59d6bbc -k ec2temp -g Web1 -z us-east-1a
&lt;/pre&gt;
&lt;p&gt;Your instance will take a minute to finish launching.  You can check the status of your instance with aws din (short for describe-instances):&lt;/p&gt;
&lt;pre class=&quot;boxed&quot;&gt;
  $ aws din | awk -F '[+|]' '{print $2,$4,$6}'
&lt;/pre&gt;
&lt;p&gt;Repeat the command above until the instance state changes to running. At that point, copy the public &lt;span class=&quot;caps&quot;&gt;DNS&lt;/span&gt; name of your instance.  Now you can access your instance using ec2-user:&lt;/p&gt;
&lt;pre class=&quot;boxed&quot;&gt;
  $ echo &quot;export EC2_HOST=&amp;lt;your-public-dns&amp;gt;&quot; &amp;gt;&amp;gt; ~/.bash_profile
  $ source ~/.bash_profile
  $ ssh -i ~/.ssh/ec2temp.key ec2-user@$EC2_HOST
&lt;/pre&gt;
&lt;p&gt;&lt;br /&gt;&lt;/p&gt;
&lt;h3&gt;Setting up User Accounts&lt;/h3&gt;
&lt;p&gt;You are now logged in as ec2-user, which has sudo access by default.  Now create your user accounts, in my case Lou and Todd will be using this server.&lt;/p&gt;
&lt;pre class=&quot;boxed&quot;&gt;
  $ sudo useradd lou
  $ sudo useradd todd
&lt;/pre&gt;
&lt;p&gt;In another window, use ssh-keygen to create a keypair called id_rsa_ec2, then scp it to your instance and append it to your authorized_keys file:&lt;/p&gt;
&lt;pre class=&quot;boxed&quot;&gt;
  local$ ssh-keygen
  local$ cd ~/.ssh
  local$ scp -i ec2temp.key id_rsa_ec2.pub ec2-user@$EC2_HOST:~
&lt;/pre&gt;
&lt;p&gt;Now, back on the instance:&lt;/p&gt;
&lt;pre class=&quot;boxed&quot;&gt;
  ec2-user$ sudo su lou 
       lou$ mkdir -m 700 ~/.ssh
       lou$ touch ~/.ssh/authorized_keys
       lou$ chmod 600 ~/.ssh/authorized_keys
       lou$ exit
  ec2-user$ cat ~/id_rsa_ec2.pub | sudo tee -a /home/lou/.ssh/authorized_keys
  &lt;/pre&gt;
&lt;p&gt;Locally, &lt;strong&gt;verify&lt;/strong&gt; that you can ssh in using your new user account:&lt;/p&gt;
&lt;pre class=&quot;boxed&quot;&gt;
local$ ssh -i ~/.ssh/id_rsa_ec2 lou@$EC2_HOST
  lou$ exit
&lt;/pre&gt;
&lt;p&gt;If you are getting denied, tail &lt;code&gt;/var/log/secure&lt;/code&gt; for clues.  Next, as ec2-user, let&amp;#8217;s set some passwords:&lt;/p&gt;
&lt;pre class=&quot;boxed&quot;&gt;
  $ sudo passwd root
  $ sudo passwd lou
  $ sudo passwd todd
&lt;/pre&gt;
&lt;p&gt;And set colorful prompts so we can tell who we are:&lt;/p&gt;
&lt;pre class=&quot;boxed&quot;&gt;
  $ echo 'export PS1=&quot;\e[1;31m[\u@\h \w]\\$ \e[m&quot;' | sudo tee -a /root/.bashrc
  $ echo 'export PS1=&quot;\e[0;35m[\u@\h \w]\$ \e[m&quot;' | sudo tee -a /home/lou/.bashrc
  $ echo 'export PS1=&quot;\e[0;32m[\u@\h \w]\$ \e[m&quot;' | sudo tee -a /home/todd/.bashrc
  $ source ~/.bash_profile
&lt;/pre&gt;
&lt;p&gt;Now let&amp;#8217;s remove ec2-user.  But first, we need to edit sudoers:&lt;/p&gt;
&lt;pre class=&quot;boxed&quot;&gt;
  $ sudo vim /etc/sudoers

  Change this line of the file:
    ec2-user ALL = NOPASSWD: ALL
  
  To this (in this case lou is the admin): 
    lou ALL=(ALL) ALL
&lt;/pre&gt;
&lt;p&gt;And then remove the ec2-user:&lt;/p&gt;
&lt;pre class=&quot;boxed&quot;&gt;
  ec2-user$ exit
     local$ ssh -i ~/.ssh/id_rsa_ec2 lou@$EC2_HOST
       lou$ sudo userdel -r ec2-user
&lt;/pre&gt;
&lt;p&gt;While we are tightening things up, let&amp;#8217;s wipe out the authorized_key file for root:&lt;/p&gt;
&lt;pre class=&quot;boxed&quot;&gt;
  lou$ sudo su root -c '&amp;gt; ~/.ssh/authorized_keys'
  lou$ exit
&lt;/pre&gt;
&lt;p&gt;&lt;br /&gt;&lt;/p&gt;
&lt;h3&gt;Modifying Your &lt;span class=&quot;caps&quot;&gt;SSH&lt;/span&gt; Config File&lt;/h3&gt;
&lt;p&gt;To make it easier to access your instance, add the following to your local &lt;code&gt;~/.ssh/config&lt;/code&gt;:&lt;/p&gt;
&lt;pre class=&quot;boxed&quot;&gt;
  Host=*compute-1.amazonaws.com
  User=&amp;lt;your-user-name&amp;gt;
  IdentityFile=~/.ssh/id_rsa_ec2
&lt;/pre&gt;
&lt;p&gt;Now you can ssh into your instance with:&lt;/p&gt;
&lt;pre class=&quot;boxed&quot;&gt;
  $ ssh $EC2_HOST
&lt;/pre&gt;
&lt;p&gt;&lt;br /&gt;&lt;/p&gt;
&lt;h3&gt;Setting up Git&lt;/h3&gt;
&lt;p&gt;The git repositories will be on an &lt;span class=&quot;caps&quot;&gt;EBS&lt;/span&gt;.  On the filesystem, they will be at &lt;code&gt;/home/git/repos&lt;/code&gt;.  Let&amp;#8217;s create a git user and add our other users to the git group.  I am going to use root for the remaining commands; if you aren&amp;#8217;t comfortable doing this, then prefix each command with sudo.&lt;/p&gt;
&lt;pre class=&quot;boxed&quot;&gt;
  $ sudo su
  # yum install -y git
  # useradd git
  # usermod -a -G git lou
  # usermod -a -G git todd
&lt;/pre&gt;
&lt;p&gt;And make the git directory group read and writeable.&lt;/p&gt;
&lt;pre class=&quot;boxed&quot;&gt;
  # chmod -R g+rwX /home/git
&lt;/pre&gt;
&lt;p&gt;Also, we want all files and directories created under &lt;code&gt;/home/git&lt;/code&gt; to retain the git group:&lt;/p&gt;
&lt;pre class=&quot;boxed&quot;&gt;
  # chmod g+s /home/git
&lt;/pre&gt;
&lt;p&gt;Let&amp;#8217;s allocate an &lt;span class=&quot;caps&quot;&gt;EBS&lt;/span&gt; to hold your repositories.  Do this from your local machine, and be sure to create your volume in the same zone as your instance:&lt;/p&gt;
&lt;pre class=&quot;boxed&quot;&gt;
  local$ aws create-volume --size 5 --zone us-east-1a
&lt;/pre&gt;
&lt;p&gt;A volume ID will be returned.  We need that ID and the ID of your instance to attach the &lt;span class=&quot;caps&quot;&gt;EBS&lt;/span&gt;.  To get the instance ID:&lt;/p&gt;
&lt;pre class=&quot;boxed&quot;&gt;
  local$ aws din | cut -b -15
&lt;/pre&gt;
&lt;p&gt;And then to attach:&lt;/p&gt;
&lt;pre class=&quot;boxed&quot;&gt;
  local$ aws attach-volume -i &amp;lt;instance-id&amp;gt; -d /dev/sdf &amp;lt;volume-id&amp;gt;
&lt;/pre&gt;

&lt;p&gt;When I attach the &lt;span class=&quot;caps&quot;&gt;EBS&lt;/span&gt; as &lt;code&gt;/dev/sdf&lt;/code&gt; it shows up on my instance as &lt;code&gt;/dev/xvdf&lt;/code&gt;, your mileage may vary.  Also, as far as I can tell there is no way to tag the volume using &lt;code&gt;aws&lt;/code&gt;.  We are going to create three volumes by the time this tutorial is over, and we need to be able to distinguish between them.  So, go to the &lt;a href=&quot;https://console.aws.amazon.com/ec2/home&quot;&gt;EC2 Console&lt;/a&gt;, select Volumes, right click your volume, and tag it with the name &amp;#8220;&lt;span class=&quot;caps&quot;&gt;GIT&lt;/span&gt;&amp;#8221;.&lt;/p&gt;
&lt;p&gt;While you are in the Console, create two additional Volumes.  Attach them as &lt;code&gt;/dev/sdg&lt;/code&gt; and &lt;code&gt;/dev/sdh&lt;/code&gt;; label them MySQL and Apache, respectively.&lt;/p&gt;
&lt;p&gt;Back on the instance, format your volume for Git:&lt;/p&gt;
&lt;pre class=&quot;boxed&quot;&gt;
  # mkfs -t ext3 /dev/xvdf
&lt;/pre&gt;
&lt;p&gt;And mount it:&lt;/p&gt;
&lt;pre class=&quot;boxed&quot;&gt;
  # echo &quot;/dev/xvdf /mnt/vol1 ext3 noatime 0 0&quot; &amp;gt;&amp;gt; /etc/fstab
  # mkdir /mnt/vol1
  # mount /mnt/vol1
&lt;/pre&gt;
&lt;p&gt;Now we will bind the &lt;code&gt;/mnt/vol1/repos&lt;/code&gt; directory to &lt;code&gt;/home/git/repos&lt;/code&gt;:&lt;/p&gt;
&lt;pre class=&quot;boxed&quot;&gt;
  # echo &quot;/mnt/vol1/repos /home/git/repos none bind&quot; &amp;gt;&amp;gt; /etc/fstab
  # mkdir -m 770 /mnt/vol1/repos
  # su git -c 'mkdir -m 770 ~/repos'
  # mount /home/git/repos
  # chown git /home/git/repos
  # chgrp git /home/git/repos
&lt;/pre&gt;
&lt;p&gt;Let&amp;#8217;s make our first git repo:&lt;/p&gt;
&lt;pre class=&quot;boxed&quot;&gt;
  # su git
  git$ mkdir -m 770 ~/repos/testing.git
  git$ cd ~/repos/testing.git
  git$ git init --bare --shared=group
  git$ exit
&lt;/pre&gt;

&lt;p&gt;From your local machine, verify that you can push to the new repo:&lt;/p&gt;
&lt;pre class=&quot;boxed&quot;&gt;
  local$ mkdir testing
  local$ cd testing
  local$ git init 
  local$ git remote add origin ssh://&amp;lt;user&amp;gt;@$EC2_HOST/home/git/repos/testing.git
  local$ echo &quot;nothing here&quot; &amp;gt; README
  local$ git add .
  local$ git commit -m &quot;initial commit&quot;
  local$ git push origin head
&lt;/pre&gt;
&lt;p&gt;One final note regarding git: if you are moving repositories from an old location to your instance, clone them with the &lt;code&gt;--bare&lt;/code&gt; option, e.g.&lt;/p&gt;
&lt;pre class=&quot;boxed&quot;&gt;
  $ git clone --bare ssh://user@an.old.host...
&lt;/pre&gt;
&lt;p&gt;&lt;br /&gt;&lt;/p&gt;
&lt;h3&gt;Setting up MySQL&lt;/h3&gt;
&lt;p&gt;First, install MySQL:&lt;/p&gt;
&lt;pre class=&quot;boxed&quot;&gt;
  # yum install -y mysql mysql-server
  # mysql_install_db
  # service mysqld start
  # mysql_secure_installation
&lt;/pre&gt;
&lt;p&gt;Next, let&amp;#8217;s put the data and log directories on an &lt;span class=&quot;caps&quot;&gt;EBS&lt;/span&gt;.  The majority of these steps are from Eric Hammond&amp;#8217;s &lt;a href=&quot;http://aws.amazon.com/articles/1663&quot; title=&quot;mysql on ec2 with ebs&quot;&gt;excellent tutorial&lt;/a&gt;.&lt;/p&gt;
&lt;p&gt;We already allocated an &lt;span class=&quot;caps&quot;&gt;EBS&lt;/span&gt; and attached it as &lt;code&gt;/dev/xvdg&lt;/code&gt; in a previous step.  Next, format and mount it:&lt;/p&gt;
&lt;pre class=&quot;boxed&quot;&gt;
  #  yum install -y xfsprogs
  #  grep -q xfs /proc/filesystems || modprobe xfs
  #  mkfs -t xfs /dev/xvdg
  #  echo &quot;/dev/xvdg /mnt/vol2 xfs noatime 0 0&quot; &amp;gt;&amp;gt; /etc/fstab
  #  mkdir /mnt/vol2
  #  mount /mnt/vol2
&lt;/pre&gt;
&lt;p&gt;We have an &lt;span class=&quot;caps&quot;&gt;EBS&lt;/span&gt; volume formatted with xfs at &lt;code&gt;/mnt/vol2&lt;/code&gt;.  We can now move&lt;br /&gt;
our MySQL data and log directories to the volume:&lt;/p&gt;
&lt;pre class=&quot;boxed&quot;&gt;
  # service mysqld stop

  # mkdir /mnt/vol2/lib
  # mv /var/lib/mysql /mnt/vol2/lib/

  # mkdir -p /mnt/vol2/log/mysql
  # mkdir /var/log/mysql /var/lib/mysql

  # cp /etc/my.cnf /etc/my.cnf.bak
  # sed -i 's|/var/log/|/var/log/mysql/|g' /etc/my.cnf

  # echo &quot;/mnt/vol2/lib/mysql /var/lib/mysql none bind&quot; &amp;gt;&amp;gt; /etc/fstab
  # mount /var/lib/mysql
  # echo &quot;/mnt/vol2/log/mysql /var/log/mysql none bind&quot; &amp;gt;&amp;gt; /etc/fstab
  # mount /var/log/mysql

  # chown -R mysql /var/lib/mysql /var/log/mysql
  # chgrp -R mysql /var/lib/mysql /var/log/mysql
&lt;/pre&gt;
&lt;p&gt;Start up mysqld&lt;/p&gt;
&lt;pre class=&quot;boxed&quot;&gt;
  # service mysqld start
&lt;/pre&gt;
&lt;p&gt;&lt;br /&gt;&lt;/p&gt;
&lt;h3&gt;Setting up Apache&lt;/h3&gt;
&lt;p&gt;We are going to have our httpd logs and virtual hosts on a third &lt;span class=&quot;caps&quot;&gt;EBS&lt;/span&gt;.  The process is very similar to what we just went through with MySQL.  Our virtual hosts will be at &lt;code&gt;/var/www/vhosts&lt;/code&gt;, and the httpd logs at &lt;code&gt;/var/log/httpd&lt;/code&gt;.&lt;/p&gt;
&lt;p&gt;First install Apache:&lt;/p&gt;
&lt;pre class=&quot;boxed&quot;&gt;
  # yum install -y httpd
&lt;/pre&gt;
&lt;p&gt;Our final &lt;span class=&quot;caps&quot;&gt;EBS&lt;/span&gt; was attached to our instance as &lt;code&gt;/dev/xvdh&lt;/code&gt;.  Format and mount:&lt;/p&gt;
&lt;pre class=&quot;boxed&quot;&gt;
  # mkfs -t xfs /dev/xvdh
  # echo &quot;/dev/xvdh /mnt/vol3 xfs noatime 0 0&quot; &amp;gt;&amp;gt; /etc/fstab
  # mkdir /mnt/vol3
  # mount /mnt/vol3
&lt;/pre&gt;
&lt;p&gt;Now let&amp;#8217;s bind &lt;code&gt;/var/www/vhosts&lt;/code&gt; to &lt;code&gt;/mnt/vol3/vhosts&lt;/code&gt; and &lt;code&gt;/var/log/httpd&lt;/code&gt; to &lt;code&gt;/mnt/vol3/log/httpd&lt;/code&gt;:&lt;/p&gt;
&lt;pre class=&quot;boxed&quot;&gt;
  # mkdir /mnt/vol3/log
  # mv /var/log/httpd /mnt/vol3/log/

  # mkdir -p /mnt/vol3/www/vhosts
  # mkdir /var/www/vhosts /var/log/httpd

  # echo &quot;/mnt/vol3/www/vhosts /var/www/vhosts none bind&quot; &amp;gt;&amp;gt; /etc/fstab
  # echo &quot;/mnt/vol3/log/httpd /var/log/httpd none bind&quot; &amp;gt;&amp;gt; /etc/fstab

  # mount /var/www/vhosts
  # mount /var/log/httpd

  # service httpd start
&lt;/pre&gt;
&lt;p&gt;You can convince yourself that the httpd log is on the &lt;span class=&quot;caps&quot;&gt;EBS&lt;/span&gt; by tailing the access_log at &lt;code&gt;/mnt/vol3/log/httpd/access_log&lt;/code&gt; and pointing your browser to the public &lt;span class=&quot;caps&quot;&gt;DNS&lt;/span&gt; of your instance.  You should see the Apache test page.&lt;/p&gt;
&lt;p&gt;&lt;br /&gt;&lt;/p&gt;
&lt;h3&gt;Testing &lt;span class=&quot;caps&quot;&gt;PHP&lt;/span&gt;, Apache, and MySQL&lt;/h3&gt;
&lt;p&gt;First let&amp;#8217;s get php and verify that Apache serves a simple php file:&lt;/p&gt;
&lt;pre class=&quot;boxed&quot;&gt;
  # yum install -y php
  # echo '&amp;lt;?php echo(&quot;hello from php&quot;); ?&amp;gt;' &amp;gt;&amp;gt; /var/www/html/index.php
  # chgrp apache /var/www/html/index.php
&lt;/pre&gt;
&lt;p&gt;Restart Apache:&lt;/p&gt;
&lt;pre class=&quot;boxed&quot;&gt;
  # service httpd restart
&lt;/pre&gt;
&lt;p&gt;And point your browser to the public &lt;span class=&quot;caps&quot;&gt;DNS&lt;/span&gt; of your instance.  You should see &amp;#8220;hello from php&amp;#8221;.  Next, let&amp;#8217;s test the php mysql connection. To do this, we will manually enter a single row using the mysql client, then fetch it with php:&lt;/p&gt;
&lt;pre class=&quot;boxed&quot;&gt;
  # yum install -y php-mysql
  # mysql -u root -p
  
  mysql&amp;gt; CREATE DATABASE phptest;
  mysql&amp;gt; GRANT ALL PRIVILEGES ON phptest.* TO foo@localhost IDENTIFIED BY 'nachos';
  mysql&amp;gt; USE phptest;
  mysql&amp;gt; CREATE TABLE posts(id int(11) NOT NULL AUTO_INCREMENT, title varchar(255),
                            PRIMARY KEY (id)) ENGINE=InnoDB;
  mysql&amp;gt; INSERT INTO posts (title) VALUES ('hello from mysql');
  mysql&amp;gt; exit;
&lt;/pre&gt;
&lt;p&gt;Now, to retrieve that row, edit &lt;code&gt;/var/www/html/index.php&lt;/code&gt; to look like this:&lt;/p&gt;
&lt;pre class=&quot;boxed&quot;&gt;
&amp;lt;?php 
  mysql_connect(&quot;localhost&quot;, &quot;foo&quot;, &quot;nachos&quot;);
  mysql_select_db(&quot;phptest&quot;); 
  $result=mysql_query(&quot;SELECT * FROM posts LIMIT 1&quot;);
  mysql_close();
  echo(mysql_result($result,0,&quot;title&quot;)); 
?&amp;gt;
&lt;/pre&gt;
&lt;p&gt;Restart Apache, then refresh your browser and verify that it says &amp;#8220;hello from mysql&amp;#8221;.  If it does not, tail the default apache error log for clues:&lt;/p&gt;
&lt;pre class=&quot;boxed&quot;&gt;
  # tail -f /var/log/httpd/error_log
&lt;/pre&gt;
&lt;p&gt;Once your test works, do a little cleanup:&lt;/p&gt;
&lt;pre class=&quot;boxed&quot;&gt;
  # rm /var/www/html/index.php
  # mysql -u root -p
  mysql&amp;gt; drop user foo@localhost;
  mysql&amp;gt; drop database phptest;
  mysql&amp;gt; exit;
&lt;/pre&gt;
&lt;p&gt;&lt;br /&gt;&lt;/p&gt;
&lt;h3&gt;On to Ruby and Rubygems!&lt;/h3&gt;
&lt;p&gt;First we need some ruby packages and gcc-c++ for building native extensions:&lt;/p&gt;
&lt;pre class=&quot;boxed&quot;&gt;
  # yum install -y gcc-c++ ruby ruby-libs ruby-devel ruby-irb rubygems
  # gem --version
&lt;/pre&gt;
&lt;p&gt;I prefer not to install rdoc and ri files when installing gems on a server (feel free to skip this):&lt;/p&gt;
&lt;pre class=&quot;boxed&quot;&gt;
  # echo &quot;gem: --no-ri --no-rdoc&quot; &amp;gt;&amp;gt; ~/.gemrc
&lt;/pre&gt;
&lt;p&gt;&lt;br /&gt;&lt;/p&gt;
&lt;h3&gt;Installing Passenger (mod_rails)&lt;/h3&gt;
&lt;pre class=&quot;boxed&quot;&gt;
  # yum install -y curl-devel httpd-devel openssl-devel zlib-devel
  # gem install passenger 
  # passenger-install-apache2-module
&lt;/pre&gt;
&lt;p&gt;Follow the instructions that are spit out by the passenger install (by editing /etc/httpd/conf/httpd.conf).&lt;/p&gt;
&lt;p&gt;&lt;br /&gt;&lt;/p&gt;
&lt;h3&gt;Testing Rails&lt;/h3&gt;
&lt;p&gt;Let&amp;#8217;s test out a rails app.  We will need the mysql gem:&lt;/p&gt;
&lt;pre class=&quot;boxed&quot;&gt;
  # yum install -y mysql-devel
  # gem install mysql 
&lt;/pre&gt;
&lt;p&gt;Next, install Rails (I still use 2.3.8):&lt;/p&gt;
&lt;pre class=&quot;boxed&quot;&gt;
  # gem install rails -v=2.3.8
&lt;/pre&gt;
&lt;p&gt;Then, create a test app:&lt;/p&gt;
&lt;pre class=&quot;boxed&quot;&gt;
  # cd /var/www/vhosts
  # rails -d mysql news
&lt;/pre&gt;
&lt;p&gt;And edit httpd.conf to add a virtual host:&lt;/p&gt;
&lt;pre class=&quot;boxed&quot;&gt;
&amp;lt;VirtualHost *:80&amp;gt;
    # ServerName codelikezell.com
    DocumentRoot /var/www/vhosts/news/public
    &amp;lt;Directory /var/www/vhosts/news/public&amp;gt;
      AllowOverride all 
      Options -MultiViews
    &amp;lt;/Directory&amp;gt;
&amp;lt;/VirtualHost&amp;gt;
&lt;/pre&gt;
&lt;p&gt;Restart Apache and refresh your browser, you should see the Riding Rails page.  Let&amp;#8217;s get the database involved to test the Rails MySQL connection:&lt;/p&gt;
&lt;pre class=&quot;boxed&quot;&gt;
  # cd /var/www/vhosts/news
  # rm public/index.html
  # mysqladmin -u root -p create news_production
  # vim config/database.yml
  
  Edit the production username and password: 
    username: news
    password: nachos
&lt;/pre&gt;
&lt;p&gt;Grant privileges to the db user:&lt;/p&gt;
&lt;pre class=&quot;boxed&quot;&gt;
  # mysql -u root -p
  mysql&amp;gt; grant all privileges on news_production.* to news@localhost identified by 'nachos';
  mysql&amp;gt; exit
&lt;/pre&gt;
&lt;p&gt;And generate some scaffolding:&lt;/p&gt;
&lt;pre class=&quot;boxed&quot;&gt;
  # script/generate scaffold Post title:string
  # RAILS_ENV=production rake db:migrate
  # vim config/routes.rb
&lt;/pre&gt;
&lt;p&gt;Edit routes.rb to look like this:&lt;/p&gt;
&lt;pre class=&quot;boxed&quot;&gt;
  ActionController::Routing::Routes.draw do |map|
    map.resources :posts
    map.root :controller =&amp;gt; &quot;posts&quot;
  end
&lt;/pre&gt;
&lt;p&gt;Restart Apache, reload your browser, and (hopefully) behold a functioning Rails site!  Put a few entries into the app so when we launch a second instance we can test whether the data stays intact.&lt;/p&gt;
&lt;p&gt;&lt;br /&gt;&lt;/p&gt;
&lt;h3&gt;Get Ready to Bundle&lt;/h3&gt;
&lt;p&gt;Let&amp;#8217;s bundle up what we have into a new &lt;span class=&quot;caps&quot;&gt;AMI&lt;/span&gt;.  We need an X.509 certificate from Amazon to create a bundle.  Go to your &lt;a href=&quot;http://aws.amazon.com/account&quot;&gt;&lt;span class=&quot;caps&quot;&gt;AWS&lt;/span&gt; account page&lt;/a&gt; and select Security Credentials.  Under Access Credentials there is a tab for X.509 Certificates, select it.  Create a new certificate and download the Private Key and X.509 pair to your ~/.ec2 directory.&lt;/p&gt;
&lt;p&gt;While you are on the Security Credentials page, make note of your &lt;span class=&quot;caps&quot;&gt;AWS&lt;/span&gt; Account ID, Access Key, and Secret Key&amp;#8212;you will need all of these.&lt;/p&gt;
&lt;p&gt;Next, scp the key and cert files to your instance.  From the &lt;a href=&quot;http://docs.amazonwebservices.com/AWSEC2/latest/UserGuide/ami-from-existing-image.html&quot;&gt;EC2 User  Guide&lt;/a&gt;: &amp;#8220;It is important to upload the key and cert files into /mnt to prevent them from being bundled with the new &lt;span class=&quot;caps&quot;&gt;AMI&lt;/span&gt;.&amp;#8221;  So, let&amp;#8217;s do that:&lt;/p&gt;
&lt;pre class=&quot;boxed&quot;&gt;
  local$ cd ~/.ec2
  local$ scp pk-xyz.pem cert-xyz.pem lou@$EC2_HOST:~
  local$ ssh lou@$EC2_HOST
    lou$ sudo mv cert-xyz.pem /mnt
    lou$ sudo mv pk-xyz.pem /mnt
&lt;/pre&gt;
&lt;p&gt;Stop mysqld and httpd, and unmount the &lt;span class=&quot;caps&quot;&gt;EBS&lt;/span&gt; volumes:&lt;/p&gt;
&lt;pre class=&quot;boxed&quot;&gt;
  # service httpd stop
  # service mysqld stop
  
  # umount /var/www/vhosts
  # umount /var/log/httpd
  # umount /var/lib/mysql
  # umount /var/log/mysql
  # umount /home/git/repos
  # umount /mnt/vol*
&lt;/pre&gt;
&lt;p&gt;Verify that your &lt;span class=&quot;caps&quot;&gt;EBS&lt;/span&gt; volumes are all unmounted by running the &lt;code&gt;mount&lt;/code&gt; command with no arguments.&lt;/p&gt;
&lt;p&gt;From your &lt;strong&gt;local&lt;/strong&gt; machine, detach the &lt;span class=&quot;caps&quot;&gt;EBS&lt;/span&gt; volumes.  We will attach these again on an instance created from a new &lt;span class=&quot;caps&quot;&gt;AMI&lt;/span&gt;.  Get the volume ids, detach them, and then verify they are detached:&lt;/p&gt;
&lt;pre class=&quot;boxed&quot;&gt;
  $ aws describe-volumes | cut -b -150
  $ aws detach-volume &amp;lt;vol1-id&amp;gt;
  $ aws detach-volume &amp;lt;vol2-id&amp;gt;
  $ aws detach-volume &amp;lt;vol3-id&amp;gt;
  $ aws describe-volumes | cut -b -150
&lt;/pre&gt;

&lt;p&gt;Now we can bundle:&lt;/p&gt;
&lt;pre class=&quot;boxed&quot;&gt;
   lou$ sudo su
  root# ec2-bundle-vol -k /mnt/pk-xyz.pem -c /mnt/cert-xyz.pem -u &amp;lt;your-aws-id-WITHOUT-dashes&amp;gt;
&lt;/pre&gt;
&lt;p&gt;Next, let&amp;#8217;s upload the bundle to S3.  The bucket and subfolder will be created automatically if they do not already exist.  As an example, in the command below I would use &lt;code&gt;-b zell-amis/web1-image&lt;/code&gt; to upload my bundle to the web1-image subfolder of the zell-amis bucket:&lt;/p&gt;
&lt;pre class=&quot;boxed&quot;&gt;
  # cd /tmp
  # ec2-upload-bundle -b &amp;lt;bucket&amp;gt;/&amp;lt;subfolder&amp;gt; -m image.manifest.xml -a &amp;lt;aws-access-key&amp;gt; -s &amp;lt;aws-secret-key&amp;gt;
&lt;/pre&gt;
&lt;p&gt;Note: if you get an error such as &amp;#8220;Error talking to S3: Server.AccessDenied(403): Access Denied&amp;#8221;, it could be because the S3 bucket name you chose is already taken&amp;#8212;S3 buckets have a global namespace.&lt;/p&gt;
&lt;p&gt;Finally, register your image from your &lt;strong&gt;local&lt;/strong&gt; machine:&lt;/p&gt;
&lt;pre class=&quot;boxed&quot;&gt;
  $ aws register-image &amp;lt;bucket&amp;gt;/&amp;lt;subfolder&amp;gt;/image.manifest.xml -n &amp;lt;name-your-image&amp;gt;
&lt;/pre&gt;
&lt;h3&gt;Creating an instance of your new &lt;span class=&quot;caps&quot;&gt;AMI&lt;/span&gt;&lt;/h3&gt;
&lt;p&gt;The last command should have returned an &lt;span class=&quot;caps&quot;&gt;AMI&lt;/span&gt; id in the response.  Let&amp;#8217;s launch an instance of it:&lt;/p&gt;
&lt;pre class=&quot;boxed&quot;&gt;
  $ aws run &amp;lt;your-new-ami-id&amp;gt; -g Web1 -z us-east-1a
&lt;/pre&gt;
&lt;p&gt;Now, just like last time, monitor the status of your launching instance:&lt;/p&gt;
&lt;pre class=&quot;boxed&quot;&gt;
  $ aws din | awk -F '[+|]' '{print $2,$3,$4,$6}'
&lt;/pre&gt;
&lt;p&gt;Once it is running, note the public &lt;span class=&quot;caps&quot;&gt;DNS&lt;/span&gt; name.  Before we login let&amp;#8217;s attach the three &lt;span class=&quot;caps&quot;&gt;EBS&lt;/span&gt; volumes.  We need their volume IDs:&lt;/p&gt;
&lt;pre class=&quot;boxed&quot;&gt;
  $ aws describe-volumes
&lt;/pre&gt;
&lt;p&gt;Examine the tagSet column, then:&lt;/p&gt;
&lt;pre class=&quot;boxed&quot;&gt;
  $ aws attach-volume -i &amp;lt;instance-id&amp;gt; -d /dev/sdf &amp;lt;GIT-volume-id&amp;gt;
  $ aws attach-volume -i &amp;lt;instance-id&amp;gt; -d /dev/sdg &amp;lt;MySQL-volume-id&amp;gt;
  $ aws attach-volume -i &amp;lt;instance-id&amp;gt; -d /dev/sdh &amp;lt;Apache-volume-id&amp;gt;
&lt;/pre&gt;
&lt;p&gt;Now ssh into the new instance as your admin user:&lt;/p&gt;
&lt;pre class=&quot;boxed&quot;&gt;
  $ ssh &amp;lt;public-DNS&amp;gt;
&lt;/pre&gt;
&lt;p&gt;And go mount crazy:&lt;/p&gt;
&lt;pre class=&quot;boxed&quot;&gt;
  $ sudo mkdir /mnt/vol1 /mnt/vol2 /mnt/vol3
  
  $ sudo mount /mnt/vol1
  $ sudo mount /mnt/vol2
  $ sudo mount /mnt/vol3

  $ sudo mount /home/git/repos
  $ sudo mount /var/log/mysql
  $ sudo mount /var/lib/mysql
  $ sudo mount /var/log/httpd
  $ sudo mount /var/www/vhosts
&lt;/pre&gt;
&lt;p&gt;Next, start mysqld and httpd and hold on to your privates:&lt;/p&gt;
&lt;pre class=&quot;boxed&quot;&gt;
  $ sudo service mysqld start
  $ sudo service httpd start
&lt;/pre&gt;
&lt;p&gt;Browse to the public &lt;span class=&quot;caps&quot;&gt;DNS&lt;/span&gt; of this instance and you should be staring at the Rails app with any entries you previously put into it.&lt;/p&gt;
&lt;p&gt;A couple final things:&lt;/p&gt;
&lt;h3&gt;Starting httpd and mysqld at Boot&lt;/h3&gt;
&lt;pre class=&quot;boxed&quot;&gt;
  $ sudo chkconfig --levels 235 mysqld on
  $ sudo chkconfig --levels 235 httpd on
&lt;/pre&gt;
&lt;p&gt;Test it!&lt;/p&gt;
&lt;pre class=&quot;boxed&quot;&gt;
  $ sudo reboot
&lt;/pre&gt;
&lt;p&gt;When your instance comes back, all the volumes should be mounted and mysqld and httpd should be running.&lt;/p&gt;
&lt;h3&gt;Cleanup&lt;/h3&gt;
&lt;pre class=&quot;boxed&quot;&gt;
  $ sudo rm -rf /home/git/repos/testing.git
  $ sudo rm -rf /var/www/vhosts/news
  $ mysql -u root -p 
  mysql&amp;gt; drop user news@localhost;
  mysql&amp;gt; drop database news_production;
  mysql&amp;gt; exit;
&lt;/pre&gt;
&lt;h3&gt;Attaching an Elastic IP&lt;/h3&gt;
&lt;p&gt;Through the &lt;span class=&quot;caps&quot;&gt;AWS&lt;/span&gt; Management console, allocate an Elastic IP address and attach it to your instance by right clicking on it.  Now, locally, add the following to &lt;code&gt;~/.ssh/config&lt;/code&gt;:&lt;/p&gt;
&lt;pre class=&quot;boxed&quot;&gt;
  Host ec2
  Hostname=&amp;lt;your-elastic-ip-address&amp;gt;
  User=&amp;lt;your-user-name&amp;gt;
  IdentityFile=~/.ssh/id_rsa_ec2
&lt;/pre&gt;
&lt;p&gt;Now you can ssh into your instance with:&lt;/p&gt;
&lt;pre class=&quot;boxed&quot;&gt;
  $ ssh ec2
&lt;/pre&gt;
&lt;p&gt;Further Reading:&lt;/p&gt;
&lt;p&gt;Snapshotting, automatic backups, and restoring your database: &lt;br /&gt;
http://aws.amazon.com/articles/1663&lt;/p&gt;
&lt;p&gt;Using the aws tools: &lt;br /&gt;
http://timkay.com/aws/howto.html&lt;/p&gt;
&lt;p&gt;EC2 User Guide: &lt;br /&gt;
http://docs.amazonwebservices.com/AWSEC2/latest/UserGuide&lt;/p&gt;</content>
 </entry>
 
 <entry>
   <title>Rails callback order</title>
   <link href="http://codelikezell.com/rails-callback-order"/>
   <updated>2009-07-20T00:00:00-07:00</updated>
   <id>http://codelikezell.com/rails-callback-order</id>
   <content type="html">&lt;p&gt;Here is a snippet to print the name of the Rails callback when called, as well as the receiving class:&lt;/p&gt;
&lt;div class='highlight'&gt;&lt;pre&gt;&lt;code class='ruby'&gt;  &lt;span class='c1'&gt;# Tested on Rails 2.3.8, put me in the config/initializers directory&lt;/span&gt;
  &lt;span class='k'&gt;module&lt;/span&gt; &lt;span class='nn'&gt;ActiveRecord&lt;/span&gt;
    &lt;span class='k'&gt;module&lt;/span&gt; &lt;span class='nn'&gt;Callbacks&lt;/span&gt;
      &lt;span class='kp'&gt;private&lt;/span&gt;

      &lt;span class='k'&gt;alias&lt;/span&gt; &lt;span class='ss'&gt;:callback_orig&lt;/span&gt; &lt;span class='ss'&gt;:callback&lt;/span&gt;
      &lt;span class='k'&gt;def&lt;/span&gt; &lt;span class='nf'&gt;callback&lt;/span&gt;&lt;span class='p'&gt;(&lt;/span&gt;&lt;span class='nb'&gt;method&lt;/span&gt;&lt;span class='p'&gt;)&lt;/span&gt;
        &lt;span class='vg'&gt;$stdout&lt;/span&gt;&lt;span class='o'&gt;.&lt;/span&gt;&lt;span class='n'&gt;puts&lt;/span&gt; &lt;span class='s2'&gt;&amp;quot;&lt;/span&gt;&lt;span class='si'&gt;#{&lt;/span&gt;&lt;span class='nb'&gt;self&lt;/span&gt;&lt;span class='o'&gt;.&lt;/span&gt;&lt;span class='n'&gt;class&lt;/span&gt;&lt;span class='o'&gt;.&lt;/span&gt;&lt;span class='n'&gt;name&lt;/span&gt;&lt;span class='si'&gt;}&lt;/span&gt;&lt;span class='s2'&gt; &lt;/span&gt;&lt;span class='si'&gt;#{&lt;/span&gt;&lt;span class='nb'&gt;method&lt;/span&gt;&lt;span class='si'&gt;}&lt;/span&gt;&lt;span class='s2'&gt;&amp;quot;&lt;/span&gt;
        &lt;span class='n'&gt;callback_orig&lt;/span&gt;&lt;span class='p'&gt;(&lt;/span&gt;&lt;span class='nb'&gt;method&lt;/span&gt;&lt;span class='p'&gt;)&lt;/span&gt;
      &lt;span class='k'&gt;end&lt;/span&gt;
    &lt;span class='k'&gt;end&lt;/span&gt;
  &lt;span class='k'&gt;end&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;
&lt;/div&gt;
&lt;p&gt;Now to test it out, let&amp;#8217;s create a couple models:&lt;/p&gt;
&lt;pre class='boxed'&gt;
  ~$ script/generate model Foo 
  ~$ script/generate model Bar foo_id:integer
  ~$ rake db:migrate
&lt;/pre&gt;
&lt;p&gt;Set their associations:&lt;/p&gt;
&lt;div class='highlight'&gt;&lt;pre&gt;&lt;code class='ruby'&gt;  &lt;span class='k'&gt;class&lt;/span&gt; &lt;span class='nc'&gt;Foo&lt;/span&gt; &lt;span class='o'&gt;&amp;lt;&lt;/span&gt; &lt;span class='no'&gt;ActiveRecord&lt;/span&gt;&lt;span class='o'&gt;::&lt;/span&gt;&lt;span class='no'&gt;Base&lt;/span&gt;
    &lt;span class='n'&gt;has_many&lt;/span&gt; &lt;span class='ss'&gt;:bars&lt;/span&gt;
  &lt;span class='k'&gt;end&lt;/span&gt;  

  &lt;span class='k'&gt;class&lt;/span&gt; &lt;span class='nc'&gt;Bar&lt;/span&gt; &lt;span class='o'&gt;&amp;lt;&lt;/span&gt; &lt;span class='no'&gt;ActiveRecord&lt;/span&gt;&lt;span class='o'&gt;::&lt;/span&gt;&lt;span class='no'&gt;Base&lt;/span&gt;
    &lt;span class='n'&gt;belongs_to&lt;/span&gt; &lt;span class='ss'&gt;:foo&lt;/span&gt;
  &lt;span class='k'&gt;end&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;
&lt;/div&gt;
&lt;p&gt;Then start script/console and instantiate and save them:&lt;/p&gt;
&lt;div class='highlight'&gt;&lt;pre&gt;&lt;code class='ruby'&gt;  &lt;span class='n'&gt;f&lt;/span&gt; &lt;span class='o'&gt;=&lt;/span&gt; &lt;span class='no'&gt;Foo&lt;/span&gt;&lt;span class='o'&gt;.&lt;/span&gt;&lt;span class='n'&gt;new&lt;/span&gt;
  &lt;span class='n'&gt;f&lt;/span&gt;&lt;span class='o'&gt;.&lt;/span&gt;&lt;span class='n'&gt;bars&lt;/span&gt;&lt;span class='o'&gt;.&lt;/span&gt;&lt;span class='n'&gt;build&lt;/span&gt;
  &lt;span class='n'&gt;f&lt;/span&gt;&lt;span class='o'&gt;.&lt;/span&gt;&lt;span class='n'&gt;save&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;
&lt;/div&gt;
&lt;p&gt;The result for this situation was:&lt;/p&gt;
&lt;pre class='boxed'&gt;
  Foo before_validation
  Foo before_validation_on_create
  Bar before_validation
  Bar before_validation_on_create
  Bar after_validation
  Bar after_validation_on_create
  Foo after_validation
  Foo after_validation_on_create
  Foo before_save
  Foo before_create
  Foo after_create
  Bar before_validation
  Bar before_validation_on_create
  Bar after_validation
  Bar after_validation_on_create
  Bar before_save
  Bar before_create
  Bar after_create
  Bar after_save
  Foo after_save
&lt;/pre&gt;
&lt;p&gt;I&amp;#8217;m not sure why the Bar validation callbacks are called twice.&lt;/p&gt;</content>
 </entry>
 
 <entry>
   <title>How to send email with Ruby and Gmail</title>
   <link href="http://codelikezell.com/how-to-send-email-with-ruby-and-gmail"/>
   <updated>2009-07-08T00:00:00-07:00</updated>
   <id>http://codelikezell.com/how-to-send-email-with-ruby-and-gmail</id>
   <content type="html">&lt;p&gt;For sending emails from my gmail account, I wanted to an interface like this:&lt;/p&gt;
&lt;div class='highlight'&gt;&lt;pre&gt;&lt;code class='ruby'&gt;  &lt;span class='n'&gt;gmail&lt;/span&gt; &lt;span class='o'&gt;=&lt;/span&gt; &lt;span class='no'&gt;GmailSender&lt;/span&gt;&lt;span class='o'&gt;.&lt;/span&gt;&lt;span class='n'&gt;new&lt;/span&gt;&lt;span class='p'&gt;(&lt;/span&gt;&lt;span class='ss'&gt;:login&lt;/span&gt; &lt;span class='o'&gt;=&amp;gt;&lt;/span&gt; &lt;span class='s1'&gt;&amp;#39;yourgmail@example.com&amp;#39;&lt;/span&gt;&lt;span class='p'&gt;,&lt;/span&gt; 
                          &lt;span class='ss'&gt;:password&lt;/span&gt; &lt;span class='o'&gt;=&amp;gt;&lt;/span&gt; &lt;span class='s1'&gt;&amp;#39;yourpass&amp;#39;&lt;/span&gt;&lt;span class='p'&gt;)&lt;/span&gt;

  &lt;span class='n'&gt;gmail&lt;/span&gt;&lt;span class='o'&gt;.&lt;/span&gt;&lt;span class='n'&gt;deliver&lt;/span&gt;&lt;span class='p'&gt;(&lt;/span&gt;&lt;span class='ss'&gt;:to&lt;/span&gt; &lt;span class='o'&gt;=&amp;gt;&lt;/span&gt; &lt;span class='s1'&gt;&amp;#39;friend@example.com&amp;#39;&lt;/span&gt;&lt;span class='p'&gt;,&lt;/span&gt; 
                &lt;span class='ss'&gt;:subject&lt;/span&gt; &lt;span class='o'&gt;=&amp;gt;&lt;/span&gt; &lt;span class='s1'&gt;&amp;#39;hello friend&amp;#39;&lt;/span&gt;&lt;span class='p'&gt;,&lt;/span&gt;
                &lt;span class='ss'&gt;:body&lt;/span&gt; &lt;span class='o'&gt;=&amp;gt;&lt;/span&gt; &lt;span class='s1'&gt;&amp;#39;omgyay&amp;#39;&lt;/span&gt;&lt;span class='p'&gt;)&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;
&lt;/div&gt;
&lt;p&gt;Here is one implementation:&lt;/p&gt;
&lt;div class='highlight'&gt;&lt;pre&gt;&lt;code class='ruby'&gt;&lt;span class='nb'&gt;require&lt;/span&gt; &lt;span class='s1'&gt;&amp;#39;net/smtp&amp;#39;&lt;/span&gt;
&lt;span class='nb'&gt;require&lt;/span&gt; &lt;span class='s1'&gt;&amp;#39;rubygems&amp;#39;&lt;/span&gt;
&lt;span class='nb'&gt;require&lt;/span&gt; &lt;span class='s1'&gt;&amp;#39;tlsmail&amp;#39;&lt;/span&gt;
  
&lt;span class='no'&gt;Net&lt;/span&gt;&lt;span class='o'&gt;::&lt;/span&gt;&lt;span class='no'&gt;SMTP&lt;/span&gt;&lt;span class='o'&gt;.&lt;/span&gt;&lt;span class='n'&gt;enable_tls&lt;/span&gt;&lt;span class='p'&gt;(&lt;/span&gt;&lt;span class='no'&gt;OpenSSL&lt;/span&gt;&lt;span class='o'&gt;::&lt;/span&gt;&lt;span class='no'&gt;SSL&lt;/span&gt;&lt;span class='o'&gt;::&lt;/span&gt;&lt;span class='no'&gt;VERIFY_PEER&lt;/span&gt;&lt;span class='p'&gt;)&lt;/span&gt;
  
&lt;span class='k'&gt;class&lt;/span&gt; &lt;span class='nc'&gt;GmailSender&lt;/span&gt;
  &lt;span class='no'&gt;SMTP_ADDR&lt;/span&gt; &lt;span class='o'&gt;=&lt;/span&gt; &lt;span class='s1'&gt;&amp;#39;smtp.gmail.com&amp;#39;&lt;/span&gt;
  
  &lt;span class='k'&gt;def&lt;/span&gt; &lt;span class='nf'&gt;initialize&lt;/span&gt;&lt;span class='p'&gt;(&lt;/span&gt;&lt;span class='n'&gt;opts&lt;/span&gt; &lt;span class='o'&gt;=&lt;/span&gt; &lt;span class='p'&gt;{})&lt;/span&gt;
    &lt;span class='k'&gt;unless&lt;/span&gt; &lt;span class='n'&gt;opts&lt;/span&gt;&lt;span class='o'&gt;[&lt;/span&gt;&lt;span class='ss'&gt;:login&lt;/span&gt;&lt;span class='o'&gt;]&lt;/span&gt; &lt;span class='o'&gt;&amp;amp;&amp;amp;&lt;/span&gt; &lt;span class='n'&gt;opts&lt;/span&gt;&lt;span class='o'&gt;[&lt;/span&gt;&lt;span class='ss'&gt;:password&lt;/span&gt;&lt;span class='o'&gt;]&lt;/span&gt;
      &lt;span class='k'&gt;raise&lt;/span&gt; &lt;span class='no'&gt;ArgumentError&lt;/span&gt;&lt;span class='o'&gt;.&lt;/span&gt;&lt;span class='n'&gt;new&lt;/span&gt;&lt;span class='p'&gt;(&lt;/span&gt;&lt;span class='s2'&gt;&amp;quot;provide a login and password&amp;quot;&lt;/span&gt;&lt;span class='p'&gt;)&lt;/span&gt;
    &lt;span class='k'&gt;end&lt;/span&gt;
    &lt;span class='vi'&gt;@login&lt;/span&gt;    &lt;span class='o'&gt;=&lt;/span&gt; &lt;span class='n'&gt;opts&lt;/span&gt;&lt;span class='o'&gt;[&lt;/span&gt;&lt;span class='ss'&gt;:login&lt;/span&gt;&lt;span class='o'&gt;]&lt;/span&gt;
    &lt;span class='vi'&gt;@password&lt;/span&gt; &lt;span class='o'&gt;=&lt;/span&gt; &lt;span class='n'&gt;opts&lt;/span&gt;&lt;span class='o'&gt;[&lt;/span&gt;&lt;span class='ss'&gt;:password&lt;/span&gt;&lt;span class='o'&gt;]&lt;/span&gt;
    &lt;span class='vi'&gt;@domain&lt;/span&gt;   &lt;span class='o'&gt;=&lt;/span&gt; &lt;span class='vi'&gt;@login&lt;/span&gt;&lt;span class='o'&gt;[/&lt;/span&gt;&lt;span class='err'&gt;@&lt;/span&gt;&lt;span class='p'&gt;(&lt;/span&gt;&lt;span class='o'&gt;.&lt;/span&gt;&lt;span class='n'&gt;+&lt;/span&gt;&lt;span class='p'&gt;)&lt;/span&gt;&lt;span class='vg'&gt;$/&lt;/span&gt;&lt;span class='p'&gt;,&lt;/span&gt;&lt;span class='mi'&gt;1&lt;/span&gt;&lt;span class='o'&gt;]&lt;/span&gt;
  &lt;span class='k'&gt;end&lt;/span&gt;

  
  &lt;span class='k'&gt;def&lt;/span&gt; &lt;span class='nf'&gt;deliver&lt;/span&gt;&lt;span class='p'&gt;(&lt;/span&gt;&lt;span class='n'&gt;opts&lt;/span&gt; &lt;span class='o'&gt;=&lt;/span&gt; &lt;span class='p'&gt;{})&lt;/span&gt;
    &lt;span class='vi'&gt;@recipients&lt;/span&gt; &lt;span class='o'&gt;=&lt;/span&gt; &lt;span class='n'&gt;opts&lt;/span&gt;&lt;span class='o'&gt;[&lt;/span&gt;&lt;span class='ss'&gt;:to&lt;/span&gt;&lt;span class='o'&gt;]&lt;/span&gt;
    &lt;span class='vi'&gt;@subject&lt;/span&gt; &lt;span class='o'&gt;=&lt;/span&gt; &lt;span class='n'&gt;opts&lt;/span&gt;&lt;span class='o'&gt;[&lt;/span&gt;&lt;span class='ss'&gt;:subject&lt;/span&gt;&lt;span class='o'&gt;]&lt;/span&gt;
    &lt;span class='vi'&gt;@body&lt;/span&gt; &lt;span class='o'&gt;=&lt;/span&gt; &lt;span class='n'&gt;opts&lt;/span&gt;&lt;span class='o'&gt;[&lt;/span&gt;&lt;span class='ss'&gt;:body&lt;/span&gt;&lt;span class='o'&gt;]&lt;/span&gt;
    &lt;span class='n'&gt;smtp_args&lt;/span&gt; &lt;span class='o'&gt;=&lt;/span&gt; &lt;span class='o'&gt;[&lt;/span&gt;&lt;span class='no'&gt;SMTP_ADDR&lt;/span&gt;&lt;span class='p'&gt;,&lt;/span&gt; &lt;span class='mi'&gt;25&lt;/span&gt;&lt;span class='p'&gt;,&lt;/span&gt; &lt;span class='vi'&gt;@domain&lt;/span&gt;&lt;span class='p'&gt;,&lt;/span&gt; &lt;span class='vi'&gt;@login&lt;/span&gt;&lt;span class='p'&gt;,&lt;/span&gt; &lt;span class='vi'&gt;@password&lt;/span&gt;&lt;span class='p'&gt;,&lt;/span&gt; &lt;span class='ss'&gt;:login&lt;/span&gt;&lt;span class='o'&gt;]&lt;/span&gt;
    &lt;span class='no'&gt;Net&lt;/span&gt;&lt;span class='o'&gt;::&lt;/span&gt;&lt;span class='no'&gt;SMTP&lt;/span&gt;&lt;span class='o'&gt;.&lt;/span&gt;&lt;span class='n'&gt;start&lt;/span&gt;&lt;span class='p'&gt;(&lt;/span&gt;&lt;span class='o'&gt;*&lt;/span&gt;&lt;span class='n'&gt;smtp_args&lt;/span&gt;&lt;span class='p'&gt;)&lt;/span&gt; &lt;span class='k'&gt;do&lt;/span&gt; &lt;span class='o'&gt;|&lt;/span&gt;&lt;span class='n'&gt;smtp&lt;/span&gt;&lt;span class='o'&gt;|&lt;/span&gt;
      &lt;span class='n'&gt;status&lt;/span&gt; &lt;span class='o'&gt;=&lt;/span&gt; &lt;span class='n'&gt;smtp&lt;/span&gt;&lt;span class='o'&gt;.&lt;/span&gt;&lt;span class='n'&gt;send_message&lt;/span&gt; &lt;span class='n'&gt;message&lt;/span&gt;&lt;span class='p'&gt;,&lt;/span&gt; &lt;span class='vi'&gt;@login&lt;/span&gt;&lt;span class='p'&gt;,&lt;/span&gt; &lt;span class='vi'&gt;@recipients&lt;/span&gt; 
      &lt;span class='nb'&gt;puts&lt;/span&gt; &lt;span class='n'&gt;status&lt;/span&gt;
    &lt;span class='k'&gt;end&lt;/span&gt;
  &lt;span class='k'&gt;end&lt;/span&gt;

  &lt;span class='kp'&gt;private&lt;/span&gt;

  &lt;span class='k'&gt;def&lt;/span&gt; &lt;span class='nf'&gt;message&lt;/span&gt;
&lt;span class='o'&gt;&amp;lt;&amp;lt;-&lt;/span&gt;&lt;span class='no'&gt;EOS&lt;/span&gt;
&lt;span class='sh'&gt;FROM: #{@login}&lt;/span&gt;
&lt;span class='sh'&gt;TO: #{@recipients.is_a?(Array) ? @recipients.join(&amp;#39;, &amp;#39;) : @recipients}&lt;/span&gt;
&lt;span class='sh'&gt;SUBJECT: #{@subject}&lt;/span&gt;

&lt;span class='sh'&gt;#{@body}&lt;/span&gt;
&lt;span class='no'&gt;EOS&lt;/span&gt;
  &lt;span class='k'&gt;end&lt;/span&gt;
&lt;span class='k'&gt;end&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;
&lt;/div&gt;
&lt;p&gt;Turn this into a local gem and you are ready to write command line email hacks to your heart&amp;#8217;s content.&lt;/p&gt;</content>
 </entry>
 
 <entry>
   <title>Using javascript to pre-fill forms in development</title>
   <link href="http://codelikezell.com/using-javascript-to-pre-fill-forms-in-development"/>
   <updated>2009-07-05T00:00:00-07:00</updated>
   <id>http://codelikezell.com/using-javascript-to-pre-fill-forms-in-development</id>
   <content type="html">&lt;p&gt;I often want to click through the many pages of my application without slowing down to fill in form data. To do this, I use javascript to pre-fill forms with a click. Say I have an order form that takes a first name, last name, and credit card type. Like this:&lt;/p&gt;
&lt;div class='highlight'&gt;&lt;pre&gt;&lt;code class='html'&gt;  &lt;span class='nt'&gt;&amp;lt;form&amp;gt;&lt;/span&gt;
    &lt;span class='nt'&gt;&amp;lt;input&lt;/span&gt; &lt;span class='na'&gt;name=&lt;/span&gt;&lt;span class='s'&gt;&amp;quot;order[first_name]&amp;quot;&lt;/span&gt; &lt;span class='na'&gt;type=&lt;/span&gt;&lt;span class='s'&gt;&amp;quot;text&amp;quot;&lt;/span&gt;&lt;span class='nt'&gt;&amp;gt;&lt;/span&gt;
    &lt;span class='nt'&gt;&amp;lt;input&lt;/span&gt; &lt;span class='na'&gt;name=&lt;/span&gt;&lt;span class='s'&gt;&amp;quot;order[last_name]&amp;quot;&lt;/span&gt; &lt;span class='na'&gt;type=&lt;/span&gt;&lt;span class='s'&gt;&amp;quot;text&amp;quot;&lt;/span&gt;&lt;span class='nt'&gt;&amp;gt;&lt;/span&gt;
    &lt;span class='nt'&gt;&amp;lt;select&lt;/span&gt; &lt;span class='na'&gt;name=&lt;/span&gt;&lt;span class='s'&gt;&amp;quot;order[card_type]&amp;quot;&lt;/span&gt;&lt;span class='nt'&gt;&amp;gt;&lt;/span&gt;
      &lt;span class='nt'&gt;&amp;lt;option&lt;/span&gt; &lt;span class='na'&gt;value=&lt;/span&gt;&lt;span class='s'&gt;&amp;quot;visa&amp;quot;&lt;/span&gt;&lt;span class='nt'&gt;&amp;gt;&lt;/span&gt;Visa&lt;span class='nt'&gt;&amp;lt;/option&amp;gt;&lt;/span&gt;
      &lt;span class='nt'&gt;&amp;lt;option&lt;/span&gt; &lt;span class='na'&gt;value=&lt;/span&gt;&lt;span class='s'&gt;&amp;quot;american_express&amp;quot;&lt;/span&gt;&lt;span class='nt'&gt;&amp;gt;&lt;/span&gt;American Express&lt;span class='nt'&gt;&amp;lt;/option&amp;gt;&lt;/span&gt;
    &lt;span class='nt'&gt;&amp;lt;/select&amp;gt;&lt;/span&gt;
  ...
  &lt;span class='nt'&gt;&amp;lt;/form&amp;gt;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;
&lt;/div&gt;
&lt;p&gt;I could write a javascript file that I only include in my development environment that would look like this:&lt;/p&gt;
&lt;div class='highlight'&gt;&lt;pre&gt;&lt;code class='javascript'&gt;  &lt;span class='nx'&gt;fill&lt;/span&gt;&lt;span class='p'&gt;(&lt;/span&gt;&lt;span class='s1'&gt;&amp;#39;order[first_name]&amp;#39;&lt;/span&gt;&lt;span class='p'&gt;,&lt;/span&gt; &lt;span class='s2'&gt;&amp;quot;Lou&amp;quot;&lt;/span&gt;&lt;span class='p'&gt;);&lt;/span&gt;
  &lt;span class='nx'&gt;fill&lt;/span&gt;&lt;span class='p'&gt;(&lt;/span&gt;&lt;span class='s1'&gt;&amp;#39;order[last_name]&amp;#39;&lt;/span&gt;&lt;span class='p'&gt;,&lt;/span&gt; &lt;span class='s2'&gt;&amp;quot;Zell&amp;quot;&lt;/span&gt;&lt;span class='p'&gt;);&lt;/span&gt;
  &lt;span class='nx'&gt;select&lt;/span&gt;&lt;span class='p'&gt;(&lt;/span&gt;&lt;span class='s1'&gt;&amp;#39;order[card_type]&amp;#39;&lt;/span&gt;&lt;span class='p'&gt;,&lt;/span&gt; &lt;span class='s2'&gt;&amp;quot;American Express&amp;quot;&lt;/span&gt;&lt;span class='p'&gt;);&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;
&lt;/div&gt;
&lt;p&gt;The javascript functions that enable me to do this:&lt;/p&gt;
&lt;div class='highlight'&gt;&lt;pre&gt;&lt;code class='javascript'&gt;  &lt;span class='kd'&gt;function&lt;/span&gt; &lt;span class='nx'&gt;find&lt;/span&gt;&lt;span class='p'&gt;(&lt;/span&gt;&lt;span class='nx'&gt;name&lt;/span&gt;&lt;span class='p'&gt;){&lt;/span&gt;
    &lt;span class='nx'&gt;n&lt;/span&gt; &lt;span class='o'&gt;=&lt;/span&gt; &lt;span class='nb'&gt;document&lt;/span&gt;&lt;span class='p'&gt;.&lt;/span&gt;&lt;span class='nx'&gt;forms&lt;/span&gt;&lt;span class='p'&gt;.&lt;/span&gt;&lt;span class='nx'&gt;length&lt;/span&gt;
    &lt;span class='k'&gt;for&lt;/span&gt; &lt;span class='p'&gt;(&lt;/span&gt;&lt;span class='kd'&gt;var&lt;/span&gt; &lt;span class='nx'&gt;i&lt;/span&gt;&lt;span class='o'&gt;=&lt;/span&gt;&lt;span class='mi'&gt;0&lt;/span&gt;&lt;span class='p'&gt;;&lt;/span&gt; &lt;span class='nx'&gt;i&lt;/span&gt; &lt;span class='o'&gt;&amp;lt;&lt;/span&gt; &lt;span class='nx'&gt;n&lt;/span&gt;&lt;span class='p'&gt;;&lt;/span&gt; &lt;span class='nx'&gt;i&lt;/span&gt;&lt;span class='o'&gt;++&lt;/span&gt;&lt;span class='p'&gt;){&lt;/span&gt;
      &lt;span class='nx'&gt;k&lt;/span&gt; &lt;span class='o'&gt;=&lt;/span&gt; &lt;span class='nb'&gt;document&lt;/span&gt;&lt;span class='p'&gt;.&lt;/span&gt;&lt;span class='nx'&gt;forms&lt;/span&gt;&lt;span class='p'&gt;[&lt;/span&gt;&lt;span class='nx'&gt;i&lt;/span&gt;&lt;span class='p'&gt;].&lt;/span&gt;&lt;span class='nx'&gt;elements&lt;/span&gt;&lt;span class='p'&gt;.&lt;/span&gt;&lt;span class='nx'&gt;length&lt;/span&gt;
      &lt;span class='k'&gt;for&lt;/span&gt;&lt;span class='p'&gt;(&lt;/span&gt;&lt;span class='kd'&gt;var&lt;/span&gt; &lt;span class='nx'&gt;j&lt;/span&gt;&lt;span class='o'&gt;=&lt;/span&gt;&lt;span class='mi'&gt;0&lt;/span&gt;&lt;span class='p'&gt;;&lt;/span&gt; &lt;span class='nx'&gt;j&lt;/span&gt; &lt;span class='o'&gt;&amp;lt;&lt;/span&gt; &lt;span class='nx'&gt;k&lt;/span&gt;&lt;span class='p'&gt;;&lt;/span&gt; &lt;span class='nx'&gt;j&lt;/span&gt;&lt;span class='o'&gt;++&lt;/span&gt;&lt;span class='p'&gt;){&lt;/span&gt;
        &lt;span class='k'&gt;if&lt;/span&gt;&lt;span class='p'&gt;(&lt;/span&gt;&lt;span class='nb'&gt;document&lt;/span&gt;&lt;span class='p'&gt;.&lt;/span&gt;&lt;span class='nx'&gt;forms&lt;/span&gt;&lt;span class='p'&gt;[&lt;/span&gt;&lt;span class='nx'&gt;i&lt;/span&gt;&lt;span class='p'&gt;].&lt;/span&gt;&lt;span class='nx'&gt;elements&lt;/span&gt;&lt;span class='p'&gt;[&lt;/span&gt;&lt;span class='nx'&gt;j&lt;/span&gt;&lt;span class='p'&gt;].&lt;/span&gt;&lt;span class='nx'&gt;name&lt;/span&gt; &lt;span class='o'&gt;==&lt;/span&gt; &lt;span class='nx'&gt;name&lt;/span&gt;&lt;span class='p'&gt;){&lt;/span&gt;
          &lt;span class='k'&gt;return&lt;/span&gt;&lt;span class='p'&gt;(&lt;/span&gt;&lt;span class='nb'&gt;document&lt;/span&gt;&lt;span class='p'&gt;.&lt;/span&gt;&lt;span class='nx'&gt;forms&lt;/span&gt;&lt;span class='p'&gt;[&lt;/span&gt;&lt;span class='nx'&gt;i&lt;/span&gt;&lt;span class='p'&gt;].&lt;/span&gt;&lt;span class='nx'&gt;elements&lt;/span&gt;&lt;span class='p'&gt;[&lt;/span&gt;&lt;span class='nx'&gt;j&lt;/span&gt;&lt;span class='p'&gt;])&lt;/span&gt;
        &lt;span class='p'&gt;}&lt;/span&gt;
      &lt;span class='p'&gt;}&lt;/span&gt;
    &lt;span class='p'&gt;}&lt;/span&gt;
  &lt;span class='p'&gt;}&lt;/span&gt;
    
  &lt;span class='kd'&gt;function&lt;/span&gt; &lt;span class='nx'&gt;fill&lt;/span&gt;&lt;span class='p'&gt;(&lt;/span&gt;&lt;span class='nx'&gt;name&lt;/span&gt;&lt;span class='p'&gt;,&lt;/span&gt; &lt;span class='nx'&gt;content&lt;/span&gt;&lt;span class='p'&gt;){&lt;/span&gt;
    &lt;span class='nx'&gt;find&lt;/span&gt;&lt;span class='p'&gt;(&lt;/span&gt;&lt;span class='nx'&gt;name&lt;/span&gt;&lt;span class='p'&gt;).&lt;/span&gt;&lt;span class='nx'&gt;value&lt;/span&gt; &lt;span class='o'&gt;=&lt;/span&gt; &lt;span class='nx'&gt;content&lt;/span&gt;&lt;span class='p'&gt;;&lt;/span&gt;
  &lt;span class='p'&gt;}&lt;/span&gt;
    
  &lt;span class='kd'&gt;function&lt;/span&gt; &lt;span class='nx'&gt;select&lt;/span&gt;&lt;span class='p'&gt;(&lt;/span&gt;&lt;span class='nx'&gt;name&lt;/span&gt;&lt;span class='p'&gt;,&lt;/span&gt; &lt;span class='nx'&gt;content&lt;/span&gt;&lt;span class='p'&gt;){&lt;/span&gt;
    &lt;span class='nx'&gt;s&lt;/span&gt; &lt;span class='o'&gt;=&lt;/span&gt; &lt;span class='nx'&gt;find&lt;/span&gt;&lt;span class='p'&gt;(&lt;/span&gt;&lt;span class='nx'&gt;name&lt;/span&gt;&lt;span class='p'&gt;)&lt;/span&gt;
    &lt;span class='k'&gt;for&lt;/span&gt; &lt;span class='p'&gt;(&lt;/span&gt;&lt;span class='kd'&gt;var&lt;/span&gt; &lt;span class='nx'&gt;i&lt;/span&gt; &lt;span class='o'&gt;=&lt;/span&gt; &lt;span class='mi'&gt;0&lt;/span&gt;&lt;span class='p'&gt;;&lt;/span&gt; &lt;span class='nx'&gt;i&lt;/span&gt; &lt;span class='o'&gt;&amp;lt;&lt;/span&gt; &lt;span class='nx'&gt;s&lt;/span&gt;&lt;span class='p'&gt;.&lt;/span&gt;&lt;span class='nx'&gt;options&lt;/span&gt;&lt;span class='p'&gt;.&lt;/span&gt;&lt;span class='nx'&gt;length&lt;/span&gt;&lt;span class='p'&gt;;&lt;/span&gt; &lt;span class='nx'&gt;i&lt;/span&gt;&lt;span class='o'&gt;++&lt;/span&gt;&lt;span class='p'&gt;){&lt;/span&gt;
      &lt;span class='k'&gt;if&lt;/span&gt; &lt;span class='p'&gt;(&lt;/span&gt;&lt;span class='nx'&gt;s&lt;/span&gt;&lt;span class='p'&gt;.&lt;/span&gt;&lt;span class='nx'&gt;options&lt;/span&gt;&lt;span class='p'&gt;[&lt;/span&gt;&lt;span class='nx'&gt;i&lt;/span&gt;&lt;span class='p'&gt;].&lt;/span&gt;&lt;span class='nx'&gt;innerHTML&lt;/span&gt; &lt;span class='o'&gt;==&lt;/span&gt; &lt;span class='nx'&gt;content&lt;/span&gt;&lt;span class='p'&gt;){&lt;/span&gt;
        &lt;span class='nx'&gt;s&lt;/span&gt;&lt;span class='p'&gt;.&lt;/span&gt;&lt;span class='nx'&gt;selectedIndex&lt;/span&gt; &lt;span class='o'&gt;=&lt;/span&gt; &lt;span class='nx'&gt;i&lt;/span&gt;&lt;span class='p'&gt;;&lt;/span&gt;
        &lt;span class='k'&gt;return&lt;/span&gt;&lt;span class='p'&gt;;&lt;/span&gt;
      &lt;span class='p'&gt;}&lt;/span&gt;
    &lt;span class='p'&gt;}&lt;/span&gt;
  &lt;span class='p'&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;
&lt;/div&gt;
&lt;p&gt;These functions don’t rely on any library, and they also shouldn’t be used in production because they are far from optimized. Yes, I am 100% sure there is a much more efficient way to write them, but they work just fine for what I need them to do.&lt;/p&gt;

&lt;p&gt;You could even create different sets of data to fill a form with, and attach each fill function to a link’s click event. Something like:&lt;/p&gt;
&lt;div class='highlight'&gt;&lt;pre&gt;&lt;code class='html'&gt;&lt;span class='nt'&gt;&amp;lt;a&lt;/span&gt; &lt;span class='na'&gt;id=&lt;/span&gt;&lt;span class='s'&gt;&amp;quot;fill_with_bob&amp;quot;&lt;/span&gt;&lt;span class='nt'&gt;&amp;gt;&lt;/span&gt;fill with bob&amp;#39;s info&lt;span class='nt'&gt;&amp;lt;/a&amp;gt;&lt;/span&gt;
&lt;span class='nt'&gt;&amp;lt;a&lt;/span&gt; &lt;span class='na'&gt;id=&lt;/span&gt;&lt;span class='s'&gt;&amp;quot;fill_with_jane&amp;quot;&lt;/span&gt;&lt;span class='nt'&gt;&amp;gt;&lt;/span&gt;fill with jane&amp;#39;s info&lt;span class='nt'&gt;&amp;lt;/a&amp;gt;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;
&lt;/div&gt;
&lt;p&gt;And the javascript:&lt;br /&gt;&lt;/p&gt;
&lt;div class='highlight'&gt;&lt;pre&gt;&lt;code class='javascript'&gt;  &lt;span class='nx'&gt;$&lt;/span&gt;&lt;span class='p'&gt;(&lt;/span&gt;&lt;span class='s1'&gt;&amp;#39;#fill_with_bob&amp;#39;&lt;/span&gt;&lt;span class='p'&gt;).&lt;/span&gt;&lt;span class='nx'&gt;click&lt;/span&gt;&lt;span class='p'&gt;(&lt;/span&gt;&lt;span class='kd'&gt;function&lt;/span&gt;&lt;span class='p'&gt;(){&lt;/span&gt;
    &lt;span class='nx'&gt;fill&lt;/span&gt;&lt;span class='p'&gt;(&lt;/span&gt;&lt;span class='s1'&gt;&amp;#39;order[first_name]&amp;#39;&lt;/span&gt;&lt;span class='p'&gt;,&lt;/span&gt; &lt;span class='s2'&gt;&amp;quot;Bob&amp;quot;&lt;/span&gt;&lt;span class='p'&gt;);&lt;/span&gt;
    &lt;span class='nx'&gt;fill&lt;/span&gt;&lt;span class='p'&gt;(&lt;/span&gt;&lt;span class='s1'&gt;&amp;#39;order[last_name]&amp;#39;&lt;/span&gt;&lt;span class='p'&gt;,&lt;/span&gt; &lt;span class='s2'&gt;&amp;quot;Jones&amp;quot;&lt;/span&gt;&lt;span class='p'&gt;);&lt;/span&gt;
    &lt;span class='nx'&gt;select&lt;/span&gt;&lt;span class='p'&gt;(&lt;/span&gt;&lt;span class='s1'&gt;&amp;#39;order[card_type]&amp;#39;&lt;/span&gt;&lt;span class='p'&gt;,&lt;/span&gt; &lt;span class='s2'&gt;&amp;quot;American Express&amp;quot;&lt;/span&gt;&lt;span class='p'&gt;);&lt;/span&gt;
  &lt;span class='p'&gt;});&lt;/span&gt;
    
  &lt;span class='nx'&gt;$&lt;/span&gt;&lt;span class='p'&gt;(&lt;/span&gt;&lt;span class='s1'&gt;&amp;#39;#fill_with_jane&amp;#39;&lt;/span&gt;&lt;span class='p'&gt;).&lt;/span&gt;&lt;span class='nx'&gt;click&lt;/span&gt;&lt;span class='p'&gt;(&lt;/span&gt;&lt;span class='kd'&gt;function&lt;/span&gt;&lt;span class='p'&gt;(){&lt;/span&gt;
    &lt;span class='nx'&gt;fill&lt;/span&gt;&lt;span class='p'&gt;(&lt;/span&gt;&lt;span class='s1'&gt;&amp;#39;order[first_name]&amp;#39;&lt;/span&gt;&lt;span class='p'&gt;,&lt;/span&gt; &lt;span class='s2'&gt;&amp;quot;Jane&amp;quot;&lt;/span&gt;&lt;span class='p'&gt;);&lt;/span&gt;
    &lt;span class='nx'&gt;fill&lt;/span&gt;&lt;span class='p'&gt;(&lt;/span&gt;&lt;span class='s1'&gt;&amp;#39;order[last_name]&amp;#39;&lt;/span&gt;&lt;span class='p'&gt;,&lt;/span&gt; &lt;span class='s2'&gt;&amp;quot;Jones&amp;quot;&lt;/span&gt;&lt;span class='p'&gt;);&lt;/span&gt;
    &lt;span class='nx'&gt;select&lt;/span&gt;&lt;span class='p'&gt;(&lt;/span&gt;&lt;span class='s1'&gt;&amp;#39;order[card_type]&amp;#39;&lt;/span&gt;&lt;span class='p'&gt;,&lt;/span&gt; &lt;span class='s2'&gt;&amp;quot;Visa&amp;quot;&lt;/span&gt;&lt;span class='p'&gt;);&lt;/span&gt;
  &lt;span class='p'&gt;});&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;
&lt;/div&gt;
&lt;p&gt;I used jquery for that last part.&lt;/p&gt;</content>
 </entry>
 
 <entry>
   <title>Steer clear of Paypal</title>
   <link href="http://codelikezell.com/steer-clear-of-paypal"/>
   <updated>2009-06-23T00:00:00-07:00</updated>
   <id>http://codelikezell.com/steer-clear-of-paypal</id>
   <content type="html">&lt;p&gt;If you are considering using Paypal’s Website Payments Pro service for $30 per month, I would think twice. I was warned that their customer service was atrocious, but it’s much worse. If you are currently using them, you already know that every phone number they provide to reach merchant services directly takes you through the same automated system as every other Paypal number. Here are the steps I recommend to get you through to someone that can help, without losing your mind:&lt;/p&gt;
&lt;p&gt;1. Take a shot (and one additional shot for each time you are disconnected)&lt;br /&gt;
2. Call any of several “direct lines” to merchant services&lt;br /&gt;
3. Say “no” when the automated system picks up&lt;br /&gt;
4. Say “agent” three times in a row, you will be placed on hold&lt;br /&gt;
5. You will get an agent, but they will be in the wrong department. They will inevitably discover that they cannot help you, and will transfer you to the merchant support group (which is the one you wanted in the first place). So save yourself the pain and demand an immediate transfer to merchant support. You will be on hold again for a while.&lt;/p&gt;
&lt;p&gt;Good luck!&lt;/p&gt;</content>
 </entry>
 
 <entry>
   <title>ShirtsTasteGood.com, YouTube Inspired T-Shirts</title>
   <link href="http://codelikezell.com/shirtstastegood-youtube-inspired-t-shirts"/>
   <updated>2009-06-16T00:00:00-07:00</updated>
   <id>http://codelikezell.com/shirtstastegood-youtube-inspired-t-shirts</id>
   <content type="html">&lt;p&gt;**March 2010 Update: Shirts Taste Good has been shutdown.&lt;/p&gt;
&lt;p&gt;I am very proud to announce &lt;a href=&quot;http://www.shirtstastegood.com&quot;&gt;Shirts Taste Good&lt;/a&gt;, a collection of t-shirts inspired by our favorite YouTube videos. It’s a four man team consisting of &lt;a href=&quot;http://www.toddham.com&quot;&gt;Todd Hamilton&lt;/a&gt; on artwork and web design, Doug and George Cline on screen printing, and myself on web development. Doug and George ditched their custom screen printing business that they had been running for the last few years, and Todd and I both quit our contracting/freelancing gigs in the city to full time &lt;span class=&quot;caps&quot;&gt;STG&lt;/span&gt;. The operation  is run out of a barn that Doug and George converted to a print shop near their home in New Jersey. The video that inspired each shirt is embedded on the shirt’s home page, so even if you aren’t interested in buying a t-shirt, you can come hang out and watch some hilarious videos. There is also a suggestions page where we auto-embed any videos that you would like us to turn into shirts! The suggestions page is particularly useful during that 1-3pm slot when you pretend to be working. We hope you enjoy the site, and please feel free to post any suggestions, questions, or comments. Thanks!&lt;/p&gt;</content>
 </entry>
 
 <entry>
   <title>The Hudson Raft Project</title>
   <link href="http://codelikezell.com/the-hudson-raft-project"/>
   <updated>2009-06-04T00:00:00-07:00</updated>
   <id>http://codelikezell.com/the-hudson-raft-project</id>
   <content type="html">&lt;p&gt;&lt;a href=&quot;http://hudsonraftproject.com&quot;&gt;&lt;img src=&quot;http://hudsonraftproject.com/wp-content/uploads/2008/07/3rd-raft-41.jpg&quot;/&gt;&lt;/a&gt; &lt;p&gt;Over the last four years a few friends of mine, led by Dallas Trombley, have attempted to sail from Albany to Manhattan on homemade boats.  They now have a &lt;a href=&quot;http://hudsonraftproject.com/&quot;&gt;site&lt;/a&gt; up describing their &lt;a href=&quot;http://hudsonraftproject.com/the-uss-crab-legs/&quot;&gt;trials&lt;/a&gt; &lt;a href=&quot;http://hudsonraftproject.com/the-manhattan-project/&quot;&gt;and&lt;/a&gt; &lt;a href=&quot;http://hudsonraftproject.com/2008-construction/&quot;&gt;tribulations&lt;/a&gt;.  Most of their content is in the form of Wordpress pages rather than posts, so be sure to check out the left nav.  It&amp;#8217;s a really entertaining read.  Good luck this year Dallas, Rob, and Co.&lt;/p&gt;&lt;/p&gt;</content>
 </entry>
 
 <entry>
   <title>Disable SSL during Rails development</title>
   <link href="http://codelikezell.com/disable-ssl-during-rails-development"/>
   <updated>2009-05-26T00:00:00-07:00</updated>
   <id>http://codelikezell.com/disable-ssl-during-rails-development</id>
   <content type="html">&lt;p&gt;Assuming you are using &lt;a href=&quot;http://github.com/rails/ssl_requirement/tree/master&quot;&gt;ssl_requirement&lt;/a&gt;, to disable &lt;span class=&quot;caps&quot;&gt;SSL&lt;/span&gt; in your development environment:&lt;/p&gt;
&lt;div class=&quot;highlight&quot;&gt;&lt;pre&gt;&lt;code class=&quot;ruby&quot;&gt;  &lt;span class=&quot;k&quot;&gt;class&lt;/span&gt; &lt;span class=&quot;nc&quot;&gt;ApplicationController&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;&amp;lt;&lt;/span&gt; &lt;span class=&quot;no&quot;&gt;ActionController&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;::&lt;/span&gt;&lt;span class=&quot;no&quot;&gt;Base&lt;/span&gt;
    &lt;span class=&quot;kp&quot;&gt;include&lt;/span&gt; &lt;span class=&quot;no&quot;&gt;SslRequirement&lt;/span&gt;
  
    &lt;span class=&quot;kp&quot;&gt;protected&lt;/span&gt;
    &lt;span class=&quot;k&quot;&gt;def&lt;/span&gt; &lt;span class=&quot;nf&quot;&gt;ssl_required?&lt;/span&gt;
      &lt;span class=&quot;no&quot;&gt;RAILS_ENV&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;!=&lt;/span&gt; &lt;span class=&quot;s1&quot;&gt;&amp;#39;development&amp;#39;&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;&amp;amp;&amp;amp;&lt;/span&gt; &lt;span class=&quot;k&quot;&gt;super&lt;/span&gt;
    &lt;span class=&quot;k&quot;&gt;end&lt;/span&gt;
  &lt;span class=&quot;k&quot;&gt;end&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;
&lt;/div&gt;</content>
 </entry>
 
 <entry>
   <title>Deploying Wordpress with Rails on Passenger</title>
   <link href="http://codelikezell.com/deploying-wordpress-with-rails-on-passenger"/>
   <updated>2009-05-20T00:00:00-07:00</updated>
   <id>http://codelikezell.com/deploying-wordpress-with-rails-on-passenger</id>
   <content type="html">&lt;p&gt;I just finished integrating a Wordpress blog into a soon-to-be released Rails app, and I would like to share the steps I took to get it deployed on Phusion Passenger.  Getting the permalinks working correctly had me hung up for a bit, so I&amp;#8217;ll show you how to get around that.&lt;/p&gt;
&lt;p&gt;To get started we can drop the blog right into the public directory of our rails app:&lt;/p&gt;
&lt;pre class=&quot;boxed&quot;&gt;
  cd /yourapp/public
  wget http://wordpress.org/latest.tar.gz
  tar xzvf latest.tar.gz
  mv wordpress blog     &amp;lt;--- blog will be at http://yourapp/blog
  cd blog
  mv wp-config-sample.php wp-config.php
&lt;/pre&gt;
&lt;p&gt;Now edit the wp-config.php file (instructions are in the file) and be sure to grant database privileges to the user you specify.&lt;/p&gt;
&lt;p&gt;Next, you have to edit your apache config file to disable passenger for the blog directory:&lt;/p&gt;
&lt;pre class=&quot;boxed&quot;&gt;
  &amp;lt;VirtualHost ...&amp;gt;
      ServerName ...
      DocumentRoot ...
      &amp;lt;Location /blog&amp;gt;
         PassengerEnabled off
      &amp;lt;/Location&amp;gt;
  &amp;lt;/VirtualHost&amp;gt;
&lt;/pre&gt;&lt;p&gt;&lt;/p&gt;
&lt;p&gt;I found that snippet &lt;a href=&quot;http://groups.google.com/group/phusion-passenger/browse_thread/thread/8ceba77706d94fdd&quot;&gt;here&lt;/a&gt;.&lt;/p&gt;
&lt;p&gt;Restart Apache and point your browser to http://yourapp/blog/index.php to setup the rest of your blog through Wordpress&amp;#8217;s web interface.  One thing you will probably edit is the default permalink structure (Found at settings &amp;gt; permalink).  I prefer to set a custom structure of &amp;#8216;/%postname%&amp;#8217;.  Regardless of the structure you use, wordpress will tell you to edit the .htaccess file in your blog directory.  For the life of me I could not get a .htaccess file to be recognized, so as a workaround I copied the snippet that wordpress specified into my apache config as follows:&lt;/p&gt;
&lt;pre class=&quot;boxed&quot;&gt;
  &amp;lt;VirtualHost ...&amp;gt;
      ServerName ...
      DocumentRoot ...
      &amp;lt;Location /blog&amp;gt;
         PassengerEnabled off
         &amp;lt;IfModule mod_rewrite.c&amp;gt;
           RewriteEngine On
           RewriteBase /blog/
           RewriteCond %{REQUEST_FILENAME} !-f
           RewriteCond %{REQUEST_FILENAME} !-d
           RewriteRule . /blog/index.php [L]
         &amp;lt;/IfModule&amp;gt;
      &amp;lt;/Location&amp;gt;
  &amp;lt;/VirtualHost&amp;gt;
&lt;/pre&gt;
&lt;p&gt;Finally, restart Apache.&lt;/p&gt;</content>
 </entry>
 
 <entry>
   <title>A more readable sort by</title>
   <link href="http://codelikezell.com/a-more-readable-sort-by"/>
   <updated>2009-04-03T00:00:00-07:00</updated>
   <id>http://codelikezell.com/a-more-readable-sort-by</id>
   <content type="html">&lt;p&gt;Suppose we want to sort a collection of accounts by their account balance.  We could put them in ascending order like this:&lt;/p&gt;
&lt;div class=&quot;highlight&quot;&gt;&lt;pre&gt;&lt;code class=&quot;ruby&quot;&gt;  &lt;span class=&quot;vi&quot;&gt;@accounts&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;sort&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;{&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;|&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;x&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;y&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;|&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;x&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;balance&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;&amp;lt;=&amp;gt;&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;y&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;balance&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;
&lt;/div&gt;&lt;p&gt;Or descending order like this:&lt;/p&gt;
&lt;div class=&quot;highlight&quot;&gt;&lt;pre&gt;&lt;code class=&quot;ruby&quot;&gt;  &lt;span class=&quot;vi&quot;&gt;@accounts&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;sort&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;{&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;|&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;x&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;y&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;|&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;y&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;balance&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;&amp;lt;=&amp;gt;&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;x&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;balance&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;
&lt;/div&gt;&lt;p&gt;To me this isn&amp;#8217;t very readable.  How about this as an alternative:&lt;/p&gt;
&lt;div class=&quot;highlight&quot;&gt;&lt;pre&gt;&lt;code class=&quot;ruby&quot;&gt;  &lt;span class=&quot;vi&quot;&gt;@accounts&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;sort_by_ascending&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;ss&quot;&gt;:balance&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;
  &lt;span class=&quot;c1&quot;&gt;# or &lt;/span&gt;
  &lt;span class=&quot;vi&quot;&gt;@accounts&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;sort_by_descending&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;ss&quot;&gt;:balance&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;
&lt;/div&gt;&lt;p&gt;The implementation is pretty simple, first create the methods:&lt;/p&gt;
&lt;div class=&quot;highlight&quot;&gt;&lt;pre&gt;&lt;code class=&quot;ruby&quot;&gt;  &lt;span class=&quot;k&quot;&gt;module&lt;/span&gt; &lt;span class=&quot;nn&quot;&gt;ReadableSortBy&lt;/span&gt;
    &lt;span class=&quot;k&quot;&gt;def&lt;/span&gt; &lt;span class=&quot;nf&quot;&gt;sort_by_ascending&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;nb&quot;&gt;method&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;
      &lt;span class=&quot;n&quot;&gt;sort&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;{&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;|&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;x&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;y&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;|&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;x&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;send&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;nb&quot;&gt;method&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;&amp;lt;=&amp;gt;&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;y&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;send&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;nb&quot;&gt;method&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)}&lt;/span&gt;
    &lt;span class=&quot;k&quot;&gt;end&lt;/span&gt;
    &lt;span class=&quot;k&quot;&gt;def&lt;/span&gt; &lt;span class=&quot;nf&quot;&gt;sort_by_descending&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;nb&quot;&gt;method&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;
      &lt;span class=&quot;n&quot;&gt;sort&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;{&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;|&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;x&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;y&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;|&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;y&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;send&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;nb&quot;&gt;method&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;&amp;lt;=&amp;gt;&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;x&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;send&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;nb&quot;&gt;method&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)}&lt;/span&gt;
    &lt;span class=&quot;k&quot;&gt;end&lt;/span&gt;
  &lt;span class=&quot;k&quot;&gt;end&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;
&lt;/div&gt;&lt;p&gt;Then include them in Array:&lt;/p&gt;
&lt;div class=&quot;highlight&quot;&gt;&lt;pre&gt;&lt;code class=&quot;ruby&quot;&gt;  &lt;span class=&quot;k&quot;&gt;class&lt;/span&gt; &lt;span class=&quot;nc&quot;&gt;Array&lt;/span&gt;
    &lt;span class=&quot;kp&quot;&gt;include&lt;/span&gt; &lt;span class=&quot;no&quot;&gt;ReadableSortBy&lt;/span&gt;
  &lt;span class=&quot;k&quot;&gt;end&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;
&lt;/div&gt;&lt;p&gt;You could also make &lt;code&gt;sort_by_ascending!&lt;/code&gt; and &lt;code&gt;sort_by_descending!&lt;/code&gt; methods that modify the collection itself.  Do this by replacing &lt;code&gt;sort&lt;/code&gt; with &lt;code&gt;sort!&lt;/code&gt; in both cases.&lt;/p&gt;</content>
 </entry>
 
 <entry>
   <title>A cheap abstract class in Ruby</title>
   <link href="http://codelikezell.com/a-cheap-abstract-class-in-ruby"/>
   <updated>2009-03-29T00:00:00-07:00</updated>
   <id>http://codelikezell.com/a-cheap-abstract-class-in-ruby</id>
   <content type="html">&lt;p&gt;When I create a class that I don&amp;#8217;t want to be instantiated, I use the following pattern:&lt;/p&gt;
&lt;div class=&quot;highlight&quot;&gt;&lt;pre&gt;&lt;code class=&quot;ruby&quot;&gt;  &lt;span class=&quot;k&quot;&gt;class&lt;/span&gt; &lt;span class=&quot;nc&quot;&gt;MakeMeAbstract&lt;/span&gt;
    &lt;span class=&quot;k&quot;&gt;def&lt;/span&gt; &lt;span class=&quot;nf&quot;&gt;initialize&lt;/span&gt;
      &lt;span class=&quot;k&quot;&gt;raise&lt;/span&gt; &lt;span class=&quot;s2&quot;&gt;&amp;quot;Don&amp;#39;t instantiate me!&amp;quot;&lt;/span&gt; &lt;span class=&quot;k&quot;&gt;if&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;abstract_class?&lt;/span&gt;
      &lt;span class=&quot;nb&quot;&gt;puts&lt;/span&gt; &lt;span class=&quot;s2&quot;&gt;&amp;quot;Instantiated!&amp;quot;&lt;/span&gt;
    &lt;span class=&quot;k&quot;&gt;end&lt;/span&gt;
    &lt;span class=&quot;kp&quot;&gt;private&lt;/span&gt;
    &lt;span class=&quot;k&quot;&gt;def&lt;/span&gt; &lt;span class=&quot;nf&quot;&gt;abstract_class?&lt;/span&gt;
      &lt;span class=&quot;nb&quot;&gt;self&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;class&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;==&lt;/span&gt; &lt;span class=&quot;no&quot;&gt;MakeMeAbstract&lt;/span&gt;
    &lt;span class=&quot;k&quot;&gt;end&lt;/span&gt;
  &lt;span class=&quot;k&quot;&gt;end&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;
&lt;/div&gt;&lt;p&gt;It can&amp;#8217;t be instantiated:&lt;/p&gt;
&lt;div class=&quot;highlight&quot;&gt;&lt;pre&gt;&lt;code class=&quot;ruby&quot;&gt;  &lt;span class=&quot;no&quot;&gt;MakeMeAbstract&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;new&lt;/span&gt; &lt;span class=&quot;k&quot;&gt;rescue&lt;/span&gt; &lt;span class=&quot;nb&quot;&gt;puts&lt;/span&gt; &lt;span class=&quot;s2&quot;&gt;&amp;quot;I&amp;#39;m abstract&amp;quot;&lt;/span&gt;   &lt;span class=&quot;c1&quot;&gt;# =&amp;gt; &amp;quot;I&amp;#39;m abstract&amp;quot;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;
&lt;/div&gt;&lt;p&gt;But it can be subclassed, and the subclass can be instantiated:&lt;/p&gt;
&lt;div class=&quot;highlight&quot;&gt;&lt;pre&gt;&lt;code class=&quot;ruby&quot;&gt;  &lt;span class=&quot;k&quot;&gt;class&lt;/span&gt; &lt;span class=&quot;nc&quot;&gt;Child&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;&amp;lt;&lt;/span&gt; &lt;span class=&quot;no&quot;&gt;MakeMeAbstract&lt;/span&gt;
  &lt;span class=&quot;k&quot;&gt;end&lt;/span&gt;
  &lt;span class=&quot;no&quot;&gt;Child&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;new&lt;/span&gt;   &lt;span class=&quot;c1&quot;&gt;# =&amp;gt; &amp;quot;Instantiated!&amp;quot;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;
&lt;/div&gt;&lt;p&gt;This is a learning experience for me.  When subclassing an abstract class I wonder if it would be better to use a mixin instead: I could overwrite mixed in methods just as easily as methods in a parent class.  The structure changes from this:&lt;/p&gt;
&lt;div class=&quot;highlight&quot;&gt;&lt;pre&gt;&lt;code class=&quot;ruby&quot;&gt;  &lt;span class=&quot;k&quot;&gt;class&lt;/span&gt; &lt;span class=&quot;nc&quot;&gt;Bar&lt;/span&gt;
    &lt;span class=&quot;k&quot;&gt;def&lt;/span&gt; &lt;span class=&quot;nf&quot;&gt;status&lt;/span&gt;
      &lt;span class=&quot;nb&quot;&gt;print&lt;/span&gt; &lt;span class=&quot;s2&quot;&gt;&amp;quot;is full&amp;quot;&lt;/span&gt;
    &lt;span class=&quot;k&quot;&gt;end&lt;/span&gt;
  &lt;span class=&quot;k&quot;&gt;end&lt;/span&gt;
  &lt;span class=&quot;k&quot;&gt;class&lt;/span&gt; &lt;span class=&quot;nc&quot;&gt;WetBar&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;&amp;lt;&lt;/span&gt; &lt;span class=&quot;no&quot;&gt;Bar&lt;/span&gt;
    &lt;span class=&quot;k&quot;&gt;def&lt;/span&gt; &lt;span class=&quot;nf&quot;&gt;status&lt;/span&gt;
      &lt;span class=&quot;nb&quot;&gt;print&lt;/span&gt; &lt;span class=&quot;s2&quot;&gt;&amp;quot;is wet, &amp;quot;&lt;/span&gt;
      &lt;span class=&quot;k&quot;&gt;super&lt;/span&gt;
    &lt;span class=&quot;k&quot;&gt;end&lt;/span&gt;
  &lt;span class=&quot;k&quot;&gt;end&lt;/span&gt;
  &lt;span class=&quot;n&quot;&gt;wet_bar&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;no&quot;&gt;WetBar&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;new&lt;/span&gt;
  &lt;span class=&quot;n&quot;&gt;wet_bar&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;status&lt;/span&gt;    &lt;span class=&quot;c1&quot;&gt;# =&amp;gt; &amp;quot;is wet, is full&amp;quot;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;
&lt;/div&gt;&lt;p&gt;To this:&lt;/p&gt;
&lt;div class=&quot;highlight&quot;&gt;&lt;pre&gt;&lt;code class=&quot;ruby&quot;&gt;  &lt;span class=&quot;k&quot;&gt;module&lt;/span&gt; &lt;span class=&quot;nn&quot;&gt;Bar&lt;/span&gt;
    &lt;span class=&quot;k&quot;&gt;def&lt;/span&gt; &lt;span class=&quot;nf&quot;&gt;status&lt;/span&gt;
      &lt;span class=&quot;nb&quot;&gt;print&lt;/span&gt; &lt;span class=&quot;s2&quot;&gt;&amp;quot;is full&amp;quot;&lt;/span&gt;
    &lt;span class=&quot;k&quot;&gt;end&lt;/span&gt;
  &lt;span class=&quot;k&quot;&gt;end&lt;/span&gt;
  &lt;span class=&quot;k&quot;&gt;class&lt;/span&gt; &lt;span class=&quot;nc&quot;&gt;WetBar&lt;/span&gt;
    &lt;span class=&quot;kp&quot;&gt;include&lt;/span&gt; &lt;span class=&quot;no&quot;&gt;Bar&lt;/span&gt;
    &lt;span class=&quot;k&quot;&gt;def&lt;/span&gt; &lt;span class=&quot;nf&quot;&gt;status&lt;/span&gt;
      &lt;span class=&quot;nb&quot;&gt;print&lt;/span&gt; &lt;span class=&quot;s2&quot;&gt;&amp;quot;is wet, &amp;quot;&lt;/span&gt;
      &lt;span class=&quot;k&quot;&gt;super&lt;/span&gt;
    &lt;span class=&quot;k&quot;&gt;end&lt;/span&gt;
  &lt;span class=&quot;k&quot;&gt;end&lt;/span&gt;
  &lt;span class=&quot;n&quot;&gt;wet_bar&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;no&quot;&gt;WetBar&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;new&lt;/span&gt;
  &lt;span class=&quot;n&quot;&gt;wet_bar&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;status&lt;/span&gt;    &lt;span class=&quot;c1&quot;&gt;# =&amp;gt; &amp;quot;is wet, is full&amp;quot;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;
&lt;/div&gt;&lt;p&gt;Input is welcome in the comments.&lt;/p&gt;</content>
 </entry>
 
 <entry>
   <title>Introducing Nickel</title>
   <link href="http://codelikezell.com/introducing-nickel"/>
   <updated>2009-03-27T00:00:00-07:00</updated>
   <id>http://codelikezell.com/introducing-nickel</id>
   <content type="html">&lt;p&gt;Nickel is a client for &lt;a href=&quot;http://www.naturalinputs.com&quot;&gt;Natural Inputs&lt;/a&gt;&lt;/p&gt;
&lt;pre class=&quot;boxed&quot;&gt;
  sudo gem install lzell-nickel
&lt;/pre&gt;
&lt;p&gt;Then try it out:&lt;/p&gt;
&lt;div class=&quot;highlight&quot;&gt;&lt;pre&gt;&lt;code class=&quot;ruby&quot;&gt;  &lt;span class=&quot;nb&quot;&gt;require&lt;/span&gt; &lt;span class=&quot;s1&quot;&gt;&amp;#39;rubygems&amp;#39;&lt;/span&gt;
  &lt;span class=&quot;nb&quot;&gt;require&lt;/span&gt; &lt;span class=&quot;s1&quot;&gt;&amp;#39;nickel&amp;#39;&lt;/span&gt;
  &lt;span class=&quot;n&quot;&gt;n&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;no&quot;&gt;Nickel&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;query&lt;/span&gt; &lt;span class=&quot;s2&quot;&gt;&amp;quot;party this friday at 10pm&amp;quot;&lt;/span&gt;
  
  &lt;span class=&quot;n&quot;&gt;n&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;message&lt;/span&gt; &lt;span class=&quot;c1&quot;&gt;# =&amp;gt; party&lt;/span&gt;
  &lt;span class=&quot;n&quot;&gt;n&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;occurrences&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;first&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;start_date&lt;/span&gt; &lt;span class=&quot;c1&quot;&gt;# =&amp;gt; 20090403&lt;/span&gt;
  &lt;span class=&quot;n&quot;&gt;n&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;occurrences&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;first&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;start_time&lt;/span&gt; &lt;span class=&quot;c1&quot;&gt;# =&amp;gt; 22:00:00&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;
&lt;/div&gt;&lt;p&gt;Many more examples &lt;a href=&quot;http://github.com/lzell/nickel/tree/master&quot;&gt;here&lt;/a&gt;.&lt;/p&gt;</content>
 </entry>
 
 <entry>
   <title>How to Backup and Restore a MySQL Database</title>
   <link href="http://codelikezell.com/how-to-backup-and-restore-a-mysql-database"/>
   <updated>2009-03-25T00:00:00-07:00</updated>
   <id>http://codelikezell.com/how-to-backup-and-restore-a-mysql-database</id>
   <content type="html">&lt;p&gt;To dump your database:&lt;/p&gt;
&lt;pre class=&quot;boxed&quot;&gt;
  mysqldump -u USER -p PASS my_db &amp;gt; my_db.sql
&lt;/pre&gt;
&lt;p&gt;Then to restore:&lt;/p&gt;
&lt;pre class=&quot;boxed&quot;&gt;
  mysql -u USER -p PASS my_db &amp;lt; my_db.sql
&lt;/pre&gt;
&lt;p&gt;Or, using gzip for compression, dump with:&lt;/p&gt;
&lt;pre class=&quot;boxed&quot;&gt;
  mysqldump -u USER -p PASS my_db | gzip &amp;gt; my_db.sql.gz
&lt;/pre&gt;
&lt;p&gt;And restore with:&lt;/p&gt;
&lt;pre class=&quot;boxed&quot;&gt;
  gzip -cd my_db.sql.gz | mysql -u USER -p PASS my_db
&lt;/pre&gt;</content>
 </entry>
 
 <entry>
   <title>Using inject for nicer output in IRB</title>
   <link href="http://codelikezell.com/using-inject-for-nicer-output-in-irb"/>
   <updated>2009-03-01T00:00:00-08:00</updated>
   <id>http://codelikezell.com/using-inject-for-nicer-output-in-irb</id>
   <content type="html">&lt;p&gt;Sometimes you want to inspect an array in irb by iterating through it and printing out some key values, for example:&lt;/p&gt;
&lt;div class=&quot;highlight&quot;&gt;&lt;pre&gt;&lt;code class=&quot;ruby&quot;&gt;  &lt;span class=&quot;n&quot;&gt;events&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;each&lt;/span&gt; &lt;span class=&quot;k&quot;&gt;do&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;|&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;event&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;|&lt;/span&gt;
    &lt;span class=&quot;nb&quot;&gt;puts&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;event&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;title&lt;/span&gt;
  &lt;span class=&quot;k&quot;&gt;end&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;
&lt;/div&gt;&lt;p&gt;But if the array is large, you will first have to scroll up through the returned array to get to your desired printout. We can prevent that by using inject instead:&lt;/p&gt;
&lt;div class=&quot;highlight&quot;&gt;&lt;pre&gt;&lt;code class=&quot;ruby&quot;&gt;  &lt;span class=&quot;n&quot;&gt;events&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;inject&lt;/span&gt; &lt;span class=&quot;k&quot;&gt;do&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;|&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;x&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;event&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;|&lt;/span&gt;
    &lt;span class=&quot;nb&quot;&gt;puts&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;event&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;title&lt;/span&gt;
  &lt;span class=&quot;k&quot;&gt;end&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;
&lt;/div&gt;&lt;p&gt;Now nil will be returned instead of the events array, and your desired output is in view.&lt;/p&gt;</content>
 </entry>
 
 <entry>
   <title>Using Gmail with Rails</title>
   <link href="http://codelikezell.com/using-gmail-with-rails"/>
   <updated>2009-03-01T00:00:00-08:00</updated>
   <id>http://codelikezell.com/using-gmail-with-rails</id>
   <content type="html">&lt;p&gt;To send email from Rails using your &lt;a href=&quot;http://www.google.com/a&quot;&gt;Google Apps&lt;/a&gt; account, you will need &lt;span class=&quot;caps&quot;&gt;TLS&lt;/span&gt; support:&lt;/p&gt;
&lt;pre class=&quot;boxed&quot;&gt;
  sudo gem install tlsmail
&lt;/pre&gt;
&lt;p&gt;Next, edit environment.rb to look like this:&lt;/p&gt;
&lt;div class=&quot;highlight&quot;&gt;&lt;pre&gt;&lt;code class=&quot;ruby&quot;&gt;  &lt;span class=&quot;no&quot;&gt;Rails&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;::&lt;/span&gt;&lt;span class=&quot;no&quot;&gt;Initializer&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;run&lt;/span&gt; &lt;span class=&quot;k&quot;&gt;do&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;|&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;config&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;|&lt;/span&gt;
    &lt;span class=&quot;n&quot;&gt;config&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;gem&lt;/span&gt; &lt;span class=&quot;s2&quot;&gt;&amp;quot;tlsmail&amp;quot;&lt;/span&gt;
    &lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;
  &lt;span class=&quot;k&quot;&gt;end&lt;/span&gt;
  &lt;span class=&quot;no&quot;&gt;Net&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;::&lt;/span&gt;&lt;span class=&quot;no&quot;&gt;SMTP&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;enable_tls&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;no&quot;&gt;OpenSSL&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;::&lt;/span&gt;&lt;span class=&quot;no&quot;&gt;SSL&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;::&lt;/span&gt;&lt;span class=&quot;no&quot;&gt;VERIFY_PEER&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;
&lt;/div&gt;&lt;p&gt;Then add this to environments/development.rb:&lt;/p&gt;
&lt;div class=&quot;highlight&quot;&gt;&lt;pre&gt;&lt;code class=&quot;ruby&quot;&gt;  &lt;span class=&quot;n&quot;&gt;config&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;action_mailer&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;delivery_method&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;ss&quot;&gt;:smtp&lt;/span&gt;
  &lt;span class=&quot;n&quot;&gt;config&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;action_mailer&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;smtp_settings&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;{&lt;/span&gt;
    &lt;span class=&quot;ss&quot;&gt;:address&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&amp;gt;&lt;/span&gt; &lt;span class=&quot;s2&quot;&gt;&amp;quot;smtp.gmail.com&amp;quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt;
    &lt;span class=&quot;ss&quot;&gt;:port&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&amp;gt;&lt;/span&gt; &lt;span class=&quot;s2&quot;&gt;&amp;quot;25&amp;quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt;
    &lt;span class=&quot;ss&quot;&gt;:domain&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&amp;gt;&lt;/span&gt; &lt;span class=&quot;s2&quot;&gt;&amp;quot;your_domain.com&amp;quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt;
    &lt;span class=&quot;ss&quot;&gt;:user_name&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&amp;gt;&lt;/span&gt; &lt;span class=&quot;s2&quot;&gt;&amp;quot;your_login@your_domain.com&amp;quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt;
    &lt;span class=&quot;ss&quot;&gt;:password&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&amp;gt;&lt;/span&gt; &lt;span class=&quot;s2&quot;&gt;&amp;quot;your_password&amp;quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt;
    &lt;span class=&quot;ss&quot;&gt;:authentication&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&amp;gt;&lt;/span&gt; &lt;span class=&quot;ss&quot;&gt;:login&lt;/span&gt;
  &lt;span class=&quot;p&quot;&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;
&lt;/div&gt;&lt;p&gt;Test it out by sending an email to yourself, create the model mailer.rb:&lt;/p&gt;
&lt;div class=&quot;highlight&quot;&gt;&lt;pre&gt;&lt;code class=&quot;ruby&quot;&gt;  &lt;span class=&quot;k&quot;&gt;class&lt;/span&gt; &lt;span class=&quot;nc&quot;&gt;Mailer&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;&amp;lt;&lt;/span&gt; &lt;span class=&quot;no&quot;&gt;ActionMailer&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;::&lt;/span&gt;&lt;span class=&quot;no&quot;&gt;Base&lt;/span&gt;
    &lt;span class=&quot;k&quot;&gt;def&lt;/span&gt; &lt;span class=&quot;nf&quot;&gt;test&lt;/span&gt;
      &lt;span class=&quot;n&quot;&gt;from&lt;/span&gt; &lt;span class=&quot;s2&quot;&gt;&amp;quot;your name &amp;lt;your_login@your_domain.com&amp;gt;&amp;quot;&lt;/span&gt;
      &lt;span class=&quot;n&quot;&gt;recipients&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;s2&quot;&gt;&amp;quot;your_login@your_domain.com&amp;quot;&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;]&lt;/span&gt;
      &lt;span class=&quot;n&quot;&gt;subject&lt;/span&gt; &lt;span class=&quot;s2&quot;&gt;&amp;quot;working?&amp;quot;&lt;/span&gt;
      &lt;span class=&quot;n&quot;&gt;body&lt;/span&gt; &lt;span class=&quot;s2&quot;&gt;&amp;quot;sending from rails&amp;quot;&lt;/span&gt;
    &lt;span class=&quot;k&quot;&gt;end&lt;/span&gt;
  &lt;span class=&quot;k&quot;&gt;end&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;
&lt;/div&gt;&lt;p&gt;Finally, from script/console:&lt;/p&gt;
&lt;div class=&quot;highlight&quot;&gt;&lt;pre&gt;&lt;code class=&quot;ruby&quot;&gt;  &lt;span class=&quot;no&quot;&gt;Mailer&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;deliver_test&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;
&lt;/div&gt;</content>
 </entry>
 
 <entry>
   <title>Preventing default event behavior with Javascript</title>
   <link href="http://codelikezell.com/preventing-default-event-behavior-with-javascript"/>
   <updated>2009-02-23T00:00:00-08:00</updated>
   <id>http://codelikezell.com/preventing-default-event-behavior-with-javascript</id>
   <content type="html">&lt;p&gt;Let’s say we want to disable all the links on a page, using jQuery we just have to return false from the click handler:&lt;/p&gt;
&lt;div class=&quot;highlight&quot;&gt;&lt;pre&gt;&lt;code class=&quot;js&quot;&gt;  &lt;span class=&quot;nx&quot;&gt;jQuery&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;kd&quot;&gt;function&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(){&lt;/span&gt;
    &lt;span class=&quot;nx&quot;&gt;jQuery&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;s1&quot;&gt;&amp;#39;body a&amp;#39;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;).&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;click&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;kd&quot;&gt;function&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(){&lt;/span&gt;
      &lt;span class=&quot;k&quot;&gt;return&lt;/span&gt; &lt;span class=&quot;kc&quot;&gt;false&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;;&lt;/span&gt;
    &lt;span class=&quot;p&quot;&gt;});&lt;/span&gt;
  &lt;span class=&quot;p&quot;&gt;});&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;
&lt;/div&gt;&lt;p&gt;Using Prototype, we pass the event instance to Event.stop():&lt;/p&gt;
&lt;div class=&quot;highlight&quot;&gt;&lt;pre&gt;&lt;code class=&quot;js&quot;&gt;  &lt;span class=&quot;nb&quot;&gt;document&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;observe&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;s2&quot;&gt;&amp;quot;dom:loaded&amp;quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;kd&quot;&gt;function&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(){&lt;/span&gt;
    &lt;span class=&quot;nx&quot;&gt;$$&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;s1&quot;&gt;&amp;#39;body a&amp;#39;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;).&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;each&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;kd&quot;&gt;function&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;a&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;nx&quot;&gt;num&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;){&lt;/span&gt;
      &lt;span class=&quot;nx&quot;&gt;$&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;a&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;).&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;observe&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;s1&quot;&gt;&amp;#39;click&amp;#39;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;kd&quot;&gt;function&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;e&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;){&lt;/span&gt;
        &lt;span class=&quot;nx&quot;&gt;Event&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;stop&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;e&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;);&lt;/span&gt;
      &lt;span class=&quot;p&quot;&gt;});&lt;/span&gt;
    &lt;span class=&quot;p&quot;&gt;});&lt;/span&gt;
  &lt;span class=&quot;p&quot;&gt;});&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;
&lt;/div&gt;&lt;p&gt;With everyday Javascript, we again return false from the click handler:&lt;/p&gt;
&lt;div class=&quot;highlight&quot;&gt;&lt;pre&gt;&lt;code class=&quot;js&quot;&gt;  &lt;span class=&quot;nb&quot;&gt;window&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;onload&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;kd&quot;&gt;function&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(){&lt;/span&gt;
    &lt;span class=&quot;nx&quot;&gt;elements&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;nb&quot;&gt;document&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;getElementsByTagName&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;s1&quot;&gt;&amp;#39;a&amp;#39;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;);&lt;/span&gt;
    &lt;span class=&quot;k&quot;&gt;for&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;kd&quot;&gt;var&lt;/span&gt; &lt;span class=&quot;nx&quot;&gt;i&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;0&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;;&lt;/span&gt; &lt;span class=&quot;nx&quot;&gt;i&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;&amp;lt;&lt;/span&gt; &lt;span class=&quot;nx&quot;&gt;elements&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;length&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;;&lt;/span&gt; &lt;span class=&quot;nx&quot;&gt;i&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;++&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;){&lt;/span&gt;
      &lt;span class=&quot;nx&quot;&gt;elements&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;i&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;].&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;onclick&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;kd&quot;&gt;function&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(){&lt;/span&gt;
        &lt;span class=&quot;k&quot;&gt;return&lt;/span&gt; &lt;span class=&quot;kc&quot;&gt;false&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;;&lt;/span&gt;
      &lt;span class=&quot;p&quot;&gt;}&lt;/span&gt;
    &lt;span class=&quot;p&quot;&gt;}&lt;/span&gt;
  &lt;span class=&quot;p&quot;&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;
&lt;/div&gt;</content>
 </entry>
 
 <entry>
   <title>Ruby Bitwise Notes</title>
   <link href="http://codelikezell.com/ruby-bitwise-notes"/>
   <updated>2009-02-10T00:00:00-08:00</updated>
   <id>http://codelikezell.com/ruby-bitwise-notes</id>
   <content type="html">&lt;p&gt;Start with an integer:&lt;/p&gt;
&lt;div class=&quot;highlight&quot;&gt;&lt;pre&gt;&lt;code class=&quot;ruby&quot;&gt;  &lt;span class=&quot;n&quot;&gt;x&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;1&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;
&lt;/div&gt;&lt;p&gt;Shift by two bit positions:&lt;/p&gt;
&lt;div class=&quot;highlight&quot;&gt;&lt;pre&gt;&lt;code class=&quot;ruby&quot;&gt;  &lt;span class=&quot;n&quot;&gt;x&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;&amp;lt;&amp;lt;=&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;2&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;
&lt;/div&gt;&lt;p&gt;OR with 1:&lt;/p&gt;
&lt;div class=&quot;highlight&quot;&gt;&lt;pre&gt;&lt;code class=&quot;ruby&quot;&gt;  &lt;span class=&quot;n&quot;&gt;x&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;|=&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;1&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;
&lt;/div&gt;&lt;p&gt;&lt;span class=&quot;caps&quot;&gt;AND&lt;/span&gt; with 14 (hex E):&lt;/p&gt;
&lt;div class=&quot;highlight&quot;&gt;&lt;pre&gt;&lt;code class=&quot;ruby&quot;&gt;  &lt;span class=&quot;n&quot;&gt;x&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;&amp;amp;=&lt;/span&gt; &lt;span class=&quot;mh&quot;&gt;0xE&lt;/span&gt;
  &lt;span class=&quot;c1&quot;&gt;# is the same as:&lt;/span&gt;
  &lt;span class=&quot;n&quot;&gt;x&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;&amp;amp;=&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;14&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;
&lt;/div&gt;&lt;p&gt;Get binary representation:&lt;/p&gt;
&lt;div class=&quot;highlight&quot;&gt;&lt;pre&gt;&lt;code class=&quot;ruby&quot;&gt;  &lt;span class=&quot;n&quot;&gt;x&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;to_s&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;2&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;
&lt;/div&gt;&lt;p&gt;Get hex representation:&lt;/p&gt;
&lt;div class=&quot;highlight&quot;&gt;&lt;pre&gt;&lt;code class=&quot;ruby&quot;&gt;  &lt;span class=&quot;n&quot;&gt;x&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;to_s&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;16&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;
&lt;/div&gt;&lt;p&gt;&lt;span class=&quot;caps&quot;&gt;XOR&lt;/span&gt; (exclusive OR) with 1&lt;/p&gt;
&lt;div class=&quot;highlight&quot;&gt;&lt;pre&gt;&lt;code class=&quot;ruby&quot;&gt;  &lt;span class=&quot;n&quot;&gt;x&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;^=&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;1&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;
&lt;/div&gt;</content>
 </entry>
 
 <entry>
   <title>Vim single line move when :set wrap is on</title>
   <link href="http://codelikezell.com/vim-single-line-move-when-set-wrap-is-on"/>
   <updated>2009-01-25T00:00:00-08:00</updated>
   <id>http://codelikezell.com/vim-single-line-move-when-set-wrap-is-on</id>
   <content type="html">&lt;p&gt;If you are editing a long paragraph with word wrap on, you may find that ‘j’ and ‘k’ jump farther than you would expect. This is because ‘j’ is moving to the next real line instead of the next wrapped line. To make vim behave more intuitively&amp;#8212;for me, at least&amp;#8212;put this in your vim config file (~/.vimrc in my case):&lt;/p&gt;
&lt;div class=&quot;highlight&quot;&gt;&lt;pre&gt;&lt;code class=&quot;vim&quot;&gt;  &lt;span class=&quot;k&quot;&gt;function&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;!&lt;/span&gt; ScreenMovement&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;movement&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;
     &lt;span class=&quot;k&quot;&gt;if&lt;/span&gt; &amp;amp;&lt;span class=&quot;nb&quot;&gt;wrap&lt;/span&gt;
        &lt;span class=&quot;k&quot;&gt;return&lt;/span&gt; &lt;span class=&quot;c&quot;&gt;&amp;quot;g&amp;quot; . a:movement&lt;/span&gt;
     &lt;span class=&quot;k&quot;&gt;else&lt;/span&gt;
        &lt;span class=&quot;k&quot;&gt;return&lt;/span&gt; a:movement
     &lt;span class=&quot;k&quot;&gt;endif&lt;/span&gt;
  &lt;span class=&quot;k&quot;&gt;endfunction&lt;/span&gt;
  onoremap   &lt;span class=&quot;k&quot;&gt;j&lt;/span&gt; ScreenMovement&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;s2&quot;&gt;&amp;quot;j&amp;quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;
  onoremap   &lt;span class=&quot;k&quot;&gt;k&lt;/span&gt; ScreenMovement&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;s2&quot;&gt;&amp;quot;k&amp;quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;
  onoremap   &lt;span class=&quot;m&quot;&gt;0&lt;/span&gt; ScreenMovement&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;s2&quot;&gt;&amp;quot;0&amp;quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;
  onoremap   ^ ScreenMovement&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;s2&quot;&gt;&amp;quot;^&amp;quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;
  onoremap   $ ScreenMovement&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;s2&quot;&gt;&amp;quot;$&amp;quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;
  nnoremap   &lt;span class=&quot;k&quot;&gt;j&lt;/span&gt; ScreenMovement&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;s2&quot;&gt;&amp;quot;j&amp;quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;
  nnoremap   &lt;span class=&quot;k&quot;&gt;k&lt;/span&gt; ScreenMovement&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;s2&quot;&gt;&amp;quot;k&amp;quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;
  nnoremap   &lt;span class=&quot;m&quot;&gt;0&lt;/span&gt; ScreenMovement&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;s2&quot;&gt;&amp;quot;0&amp;quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;
  nnoremap   ^ ScreenMovement&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;s2&quot;&gt;&amp;quot;^&amp;quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;
  nnoremap   $ ScreenMovement&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;s2&quot;&gt;&amp;quot;$&amp;quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;
&lt;/div&gt;&lt;p&gt;Thanks to rick_h in #vim&lt;/p&gt;</content>
 </entry>
 
 <entry>
   <title>Rails 2 migrations without the timestamp</title>
   <link href="http://codelikezell.com/rails-2-migrations-without-the-timestamp"/>
   <updated>2009-01-25T00:00:00-08:00</updated>
   <id>http://codelikezell.com/rails-2-migrations-without-the-timestamp</id>
   <content type="html">&lt;p&gt;For Rails 1 style migrations, set this in environment.rb:&lt;/p&gt;
&lt;div class=&quot;highlight&quot;&gt;&lt;pre&gt;&lt;code class=&quot;ruby&quot;&gt;  &lt;span class=&quot;n&quot;&gt;config&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;active_record&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;timestamped_migrations&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;kp&quot;&gt;false&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;
&lt;/div&gt;&lt;p&gt;Note this will not work before Rails 2.2. Thanks to mikeg1a in #rubyonrails.&lt;/p&gt;</content>
 </entry>
 
 <entry>
   <title>Edit through FTP with TextMate and Cyberduck</title>
   <link href="http://codelikezell.com/edit-through-ftp-with-textmate-and-cyberduck"/>
   <updated>2008-06-29T00:00:00-07:00</updated>
   <id>http://codelikezell.com/edit-through-ftp-with-textmate-and-cyberduck</id>
   <content type="html">&lt;p&gt;I do a bit of freelance php work where I need to edit files through &lt;span class=&quot;caps&quot;&gt;FTP&lt;/span&gt;. Textmate does not support this very well out of the box, and at first it seemed like I would have to open and edit each file in its own window. But by combining &lt;a href=&quot;http://lists.macromates.com/textmate/2006-February/008636.html&quot;&gt;this tip&lt;/a&gt; by &lt;a href=&quot;http://subtlegradient.com/&quot;&gt;subtlegradient&lt;/a&gt; with &lt;a href=&quot;http://ciaranwal.sh/2007/11/27/textmate-tip-where-am-i&quot;&gt;this tip&lt;/a&gt; by &lt;a href=&quot;http://ciaranwal.sh/&quot;&gt;ciaranwal.sh&lt;/a&gt; we can use tabbed editing, project drawer, and cmd+t to switch files. The steps:&lt;/p&gt;
&lt;p&gt;1. In Cyberduck’s preferences make sure external editor is set to TextMate. Also, it helps if “Double click opens file in external editor” is set to true.&lt;/p&gt;
&lt;p&gt;2. Open up a file from your &lt;span class=&quot;caps&quot;&gt;FTP&lt;/span&gt; project that is close to the top level directory of your project, you’ll see why in a minute.&lt;/p&gt;
&lt;p&gt;3. In the TextMate window that popped up, hit ctrl+shift+o (Bundles &amp;gt; Shell Script &amp;gt; Open Terminal). The terminal will open at the temporary location where the file you are editing is.&lt;/p&gt;
&lt;p&gt;4. cd .. back to the top level directory of your project and enter: mate .&lt;/p&gt;
&lt;p&gt;Now any subsequent files you open using Cyberduck will be added as tabs in the current TextMate project.&lt;/p&gt;</content>
 </entry>
 
 <entry>
   <title>GoLark Mobile</title>
   <link href="http://codelikezell.com/golark-mobile"/>
   <updated>2008-02-12T00:00:00-08:00</updated>
   <id>http://codelikezell.com/golark-mobile</id>
   <content type="html">&lt;p&gt;**2009 Update: GoLark has been shutdown.&lt;/p&gt;
&lt;p&gt;The &lt;a href=&quot;http://www.apple.com/webapps/entertainment/golarkmobile.html&quot;&gt;GoLark iPhone Application&lt;/a&gt; was released this week, making GoLark one step closer to providing us with local events, anywhere, at any time.&lt;/p&gt;
&lt;p&gt;Currently, two of GoLark’s lists are supported on the iPhone: Top Larks and Top Recurring Larks. Date and time filtering–although slightly stripped down–is also provided. The app is purposely minimal in design, providing a clear and simple interface to the best local events.&lt;/p&gt;
&lt;p&gt;Check it out at &lt;a href=&quot;http://iphone.golark.com&quot;&gt;iphone.golark.com&lt;/a&gt;&lt;/p&gt;
&lt;div&gt;&lt;img src=&quot;/images/iphone_app1.png&quot;&gt;&lt;/div&gt;</content>
 </entry>
 
 <entry>
   <title>Create a sick game with Processing</title>
   <link href="http://codelikezell.com/create-a-sick-game-with-processing"/>
   <updated>2007-11-04T00:00:00-07:00</updated>
   <id>http://codelikezell.com/create-a-sick-game-with-processing</id>
   <content type="html">&lt;p&gt;I did a little experimenting with &lt;a href=&quot;http://www.processing.org/&quot;&gt;Processing&lt;/a&gt;, a language written for artists, graphics designers, and anyone interested in learning something new. I was very impressed with how easy it was to get started. The download comes with tons of simple example projects, and the &lt;a href=&quot;http://www.processing.org/reference/index.html&quot;&gt;&lt;span class=&quot;caps&quot;&gt;API&lt;/span&gt; reference&lt;/a&gt; is easy to understand. I had hopes of Processing opening a whole, previously undiscovered, artistic side of my brain — it didn’t. But I did make a killer “blow up the falling spheres with my triangle’s laser” game. Check it out:&lt;/p&gt;
&lt;div&gt;&lt;img src=&quot;/images/game_screenshot.png&quot; style=&quot;width: 70%&quot;&gt;&lt;/div&gt;
&lt;p&gt;Wow, that screen shot makes it look even more lame than it really is (hard to do).&lt;/p&gt;
&lt;p&gt;I know, I know, you want the code so you can try this game out for yourself. Here it is, paste into Processing and hit play:&lt;/p&gt;
&lt;div class=&quot;highlight&quot;&gt;&lt;pre&gt;&lt;code class=&quot;java&quot;&gt;  &lt;span class=&quot;n&quot;&gt;PFont&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;fontA&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;;&lt;/span&gt;
  &lt;span class=&quot;kt&quot;&gt;int&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;sphereDiameter&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;10&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;;&lt;/span&gt;
  &lt;span class=&quot;kt&quot;&gt;boolean&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;shoot&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;kc&quot;&gt;false&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;;&lt;/span&gt;
  
  &lt;span class=&quot;kt&quot;&gt;int&lt;/span&gt; &lt;span class=&quot;nf&quot;&gt;randx&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;()&lt;/span&gt;
  &lt;span class=&quot;o&quot;&gt;{&lt;/span&gt;
    &lt;span class=&quot;k&quot;&gt;return&lt;/span&gt; &lt;span class=&quot;nf&quot;&gt;int&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;random&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;600&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;));&lt;/span&gt;
  &lt;span class=&quot;o&quot;&gt;}&lt;/span&gt;
  
  &lt;span class=&quot;kt&quot;&gt;int&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;[]&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;sphereXCoords&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;{&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;randx&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;(),&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;randx&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;(),&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;randx&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;(),&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;randx&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;(),&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;randx&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;()&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;};&lt;/span&gt;
  &lt;span class=&quot;kt&quot;&gt;int&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;[]&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;sphereYCoords&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;{&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;0&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;0&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;0&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;0&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;0&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;};&lt;/span&gt;
  
  &lt;span class=&quot;kt&quot;&gt;void&lt;/span&gt; &lt;span class=&quot;nf&quot;&gt;setup&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;()&lt;/span&gt;
  &lt;span class=&quot;o&quot;&gt;{&lt;/span&gt;
    &lt;span class=&quot;n&quot;&gt;size&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;600&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;,&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;620&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;);&lt;/span&gt;
  &lt;span class=&quot;o&quot;&gt;}&lt;/span&gt;
  
  &lt;span class=&quot;kt&quot;&gt;void&lt;/span&gt; &lt;span class=&quot;nf&quot;&gt;draw&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;()&lt;/span&gt;
  &lt;span class=&quot;o&quot;&gt;{&lt;/span&gt;
    &lt;span class=&quot;n&quot;&gt;background&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;0&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;);&lt;/span&gt;
    &lt;span class=&quot;n&quot;&gt;fill&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;color&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;0&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;,&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;255&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;,&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;0&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;));&lt;/span&gt;
    &lt;span class=&quot;n&quot;&gt;stroke&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;color&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;0&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;,&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;255&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;,&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;0&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;));&lt;/span&gt;
    &lt;span class=&quot;n&quot;&gt;triangle&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;mouseX&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;-&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;8&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;580&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;mouseX&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;+&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;8&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;580&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;mouseX&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;565&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;);&lt;/span&gt;
    &lt;span class=&quot;n&quot;&gt;fill&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;color&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;255&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;,&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;0&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;,&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;0&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;));&lt;/span&gt;
    &lt;span class=&quot;n&quot;&gt;stroke&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;color&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;255&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;,&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;0&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;,&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;0&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;));&lt;/span&gt;
  
    &lt;span class=&quot;k&quot;&gt;if&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;shoot&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;==&lt;/span&gt;&lt;span class=&quot;kc&quot;&gt;true&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;)&lt;/span&gt;
    &lt;span class=&quot;o&quot;&gt;{&lt;/span&gt;
      &lt;span class=&quot;n&quot;&gt;sphereKiller&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;mouseX&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;);&lt;/span&gt;
      &lt;span class=&quot;n&quot;&gt;shoot&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;kc&quot;&gt;false&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;;&lt;/span&gt;
    &lt;span class=&quot;o&quot;&gt;}&lt;/span&gt;
  
    &lt;span class=&quot;n&quot;&gt;sphereDropper&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;();&lt;/span&gt;
    &lt;span class=&quot;n&quot;&gt;gameEnder&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;();&lt;/span&gt;  
  &lt;span class=&quot;o&quot;&gt;}&lt;/span&gt;
  
  &lt;span class=&quot;kt&quot;&gt;void&lt;/span&gt; &lt;span class=&quot;nf&quot;&gt;mousePressed&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;()&lt;/span&gt;
  &lt;span class=&quot;o&quot;&gt;{&lt;/span&gt;
    &lt;span class=&quot;n&quot;&gt;shoot&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;kc&quot;&gt;true&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;;&lt;/span&gt;
  &lt;span class=&quot;o&quot;&gt;}&lt;/span&gt;
  
  &lt;span class=&quot;kt&quot;&gt;void&lt;/span&gt; &lt;span class=&quot;nf&quot;&gt;sphereDropper&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;()&lt;/span&gt;
  &lt;span class=&quot;o&quot;&gt;{&lt;/span&gt;  
    &lt;span class=&quot;n&quot;&gt;stroke&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;255&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;);&lt;/span&gt;
    &lt;span class=&quot;n&quot;&gt;fill&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;255&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;);&lt;/span&gt;
    &lt;span class=&quot;k&quot;&gt;for&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;kt&quot;&gt;int&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;i&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;0&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;;&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;i&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;&amp;lt;&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;5&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;;&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;i&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;++)&lt;/span&gt;
    &lt;span class=&quot;o&quot;&gt;{&lt;/span&gt;
      &lt;span class=&quot;n&quot;&gt;ellipse&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;sphereXCoords&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;i&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;],&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;sphereYCoords&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;i&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;]++,&lt;/span&gt;
              &lt;span class=&quot;n&quot;&gt;sphereDiameter&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;sphereDiameter&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;);&lt;/span&gt;
    &lt;span class=&quot;o&quot;&gt;}&lt;/span&gt;
  &lt;span class=&quot;o&quot;&gt;}&lt;/span&gt;
  
  &lt;span class=&quot;kt&quot;&gt;void&lt;/span&gt; &lt;span class=&quot;nf&quot;&gt;sphereKiller&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;kt&quot;&gt;int&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;shotX&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;)&lt;/span&gt;
  &lt;span class=&quot;o&quot;&gt;{&lt;/span&gt;
    &lt;span class=&quot;kt&quot;&gt;boolean&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;hit&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;kc&quot;&gt;false&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;;&lt;/span&gt;
    &lt;span class=&quot;k&quot;&gt;for&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;kt&quot;&gt;int&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;i&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;0&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;;&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;i&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;&amp;lt;&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;5&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;;&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;i&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;++)&lt;/span&gt;
    &lt;span class=&quot;o&quot;&gt;{&lt;/span&gt;
      &lt;span class=&quot;k&quot;&gt;if&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;((&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;shotX&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;&amp;gt;=&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;sphereXCoords&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;i&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;]-&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;sphereDiameter&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;/&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;2&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;))&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;&amp;amp;&amp;amp;&lt;/span&gt; 
         &lt;span class=&quot;o&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;shotX&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;&amp;lt;=&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;sphereXCoords&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;i&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;]+&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;sphereDiameter&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;/&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;2&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;)))&lt;/span&gt;
      &lt;span class=&quot;o&quot;&gt;{&lt;/span&gt;
        &lt;span class=&quot;n&quot;&gt;hit&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;kc&quot;&gt;true&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;;&lt;/span&gt;
        &lt;span class=&quot;n&quot;&gt;line&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;mouseX&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;565&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;mouseX&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;sphereYCoords&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;i&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;]);&lt;/span&gt;
        &lt;span class=&quot;n&quot;&gt;ellipse&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;sphereXCoords&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;i&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;],&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;sphereYCoords&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;i&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;],&lt;/span&gt;
                &lt;span class=&quot;n&quot;&gt;sphereDiameter&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;+&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;25&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;sphereDiameter&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;+&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;25&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;);&lt;/span&gt;
        &lt;span class=&quot;n&quot;&gt;sphereXCoords&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;i&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;]&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;randx&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;();&lt;/span&gt;
        &lt;span class=&quot;n&quot;&gt;sphereYCoords&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;i&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;]&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;0&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;;&lt;/span&gt;
      &lt;span class=&quot;o&quot;&gt;}&lt;/span&gt;    
    &lt;span class=&quot;o&quot;&gt;}&lt;/span&gt;
  
    &lt;span class=&quot;k&quot;&gt;if&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;hit&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;==&lt;/span&gt; &lt;span class=&quot;kc&quot;&gt;false&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;)&lt;/span&gt;
    &lt;span class=&quot;o&quot;&gt;{&lt;/span&gt;
      &lt;span class=&quot;n&quot;&gt;line&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;mouseX&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;565&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;mouseX&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;0&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;);&lt;/span&gt;
    &lt;span class=&quot;o&quot;&gt;}&lt;/span&gt;  
  
  &lt;span class=&quot;o&quot;&gt;}&lt;/span&gt;
  
  &lt;span class=&quot;kt&quot;&gt;void&lt;/span&gt; &lt;span class=&quot;nf&quot;&gt;gameEnder&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;()&lt;/span&gt;
  &lt;span class=&quot;o&quot;&gt;{&lt;/span&gt;
    &lt;span class=&quot;k&quot;&gt;for&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;kt&quot;&gt;int&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;i&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;0&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;;&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;i&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;&amp;lt;&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;5&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;;&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;i&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;++)&lt;/span&gt;
    &lt;span class=&quot;o&quot;&gt;{&lt;/span&gt;
      &lt;span class=&quot;k&quot;&gt;if&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;sphereYCoords&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;i&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;]==&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;600&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;)&lt;/span&gt;
      &lt;span class=&quot;o&quot;&gt;{&lt;/span&gt;
        &lt;span class=&quot;n&quot;&gt;fill&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;color&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;255&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;,&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;0&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;,&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;0&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;));&lt;/span&gt;
        &lt;span class=&quot;n&quot;&gt;noLoop&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;();&lt;/span&gt;
      &lt;span class=&quot;o&quot;&gt;}&lt;/span&gt;
    &lt;span class=&quot;o&quot;&gt;}&lt;/span&gt;
  &lt;span class=&quot;o&quot;&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;
&lt;/div&gt;</content>
 </entry>
 
 <entry>
   <title>How to modify the GNU linker's default search path</title>
   <link href="http://codelikezell.com/how-to-modify-the-gnu-linkers-default-search-path"/>
   <updated>2007-10-30T00:00:00-07:00</updated>
   <id>http://codelikezell.com/how-to-modify-the-gnu-linkers-default-search-path</id>
   <content type="html">&lt;p&gt;I installed &lt;a href=&quot;http://www.gnu.org/software/gsl/&quot;&gt;GNU’s Scientific Library&lt;/a&gt; and &lt;a href=&quot;http://rb-gsl.rubyforge.org/&quot;&gt;Ruby’s wrapper for &lt;span class=&quot;caps&quot;&gt;GSL&lt;/span&gt;&lt;/a&gt; on Ubuntu and OS X without any problems. Next up: CentOS. The install appeared to complete successfully, but a require ‘gsl’ from irb showed otherwise:&lt;/p&gt;
&lt;pre class=&quot;boxed&quot;&gt;
  LoadError: libgsl.so.0: cannot open shared object file: 
  No such file or directory
&lt;/pre&gt;
&lt;p&gt;I located libgsl.so.0 in /usr/local/lib; so the problem is with the linker finding a shared library. The way I fixed this during the &lt;a href=&quot;/how-to-install-memcached-on-centos&quot;&gt;memcached install&lt;/a&gt; was to add the &lt;code&gt;--rpath&lt;/code&gt; linker flag during the build. But I don’t wan’t to keep running into this in the future, so I decided to add /usr/local/lib to ld’s default search path, here’s how:&lt;/p&gt;
&lt;p&gt;Open /etc/ld.so.conf in your editor and make sure there is a single line that reads:&lt;/p&gt;
&lt;pre class=&quot;boxed&quot;&gt;
  include ld.so.conf.d/*.conf
&lt;/pre&gt;
&lt;p&gt;Then, from your shell prompt:&lt;/p&gt;
&lt;pre class=&quot;boxed&quot;&gt;
  echo &quot;/usr/local/lib&quot; &amp;gt;&amp;gt; /etc/ld.so.conf.d/loc_lib.conf
  /sbin/ldconfig
&lt;/pre&gt;
&lt;p&gt;That should do it.&lt;/p&gt;
&lt;p&gt;If you would like to learn more on the subject, this is the best documentation I have found on &lt;a href=&quot;http://www.eyrie.org/~eagle/notes/rpath.html&quot;&gt;Shared Library Search Paths&lt;/a&gt;.&lt;/p&gt;</content>
 </entry>
 
 <entry>
   <title>Benchmarking Ruby Time and Date instantiation</title>
   <link href="http://codelikezell.com/benchmarking-ruby-time-and-date-instantiation"/>
   <updated>2007-10-19T00:00:00-07:00</updated>
   <id>http://codelikezell.com/benchmarking-ruby-time-and-date-instantiation</id>
   <content type="html">&lt;p&gt;A comparison of various ways to represent dates and times in ruby.  I am creating October 10, 2007 in every case, here are the tests:&lt;/p&gt;
&lt;div class=&quot;highlight&quot;&gt;&lt;pre&gt;&lt;code class=&quot;ruby&quot;&gt;  &lt;span class=&quot;n&quot;&gt;n&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;10000&lt;/span&gt;
  &lt;span class=&quot;no&quot;&gt;Benchmark&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;bm&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;10&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;k&quot;&gt;do&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;|&lt;/span&gt;&lt;span class=&quot;nb&quot;&gt;test&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;|&lt;/span&gt;
    &lt;span class=&quot;nb&quot;&gt;test&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;report&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;s2&quot;&gt;&amp;quot;Date.strptime: &amp;quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;k&quot;&gt;do&lt;/span&gt;
      &lt;span class=&quot;n&quot;&gt;n&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;times&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;{&lt;/span&gt;&lt;span class=&quot;no&quot;&gt;Date&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;strptime&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;s2&quot;&gt;&amp;quot;20071001&amp;quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt;&lt;span class=&quot;s2&quot;&gt;&amp;quot;%Y%m%d&amp;quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)}&lt;/span&gt;
    &lt;span class=&quot;k&quot;&gt;end&lt;/span&gt; 
    &lt;span class=&quot;nb&quot;&gt;test&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;report&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;s2&quot;&gt;&amp;quot;Date.parse: &amp;quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;k&quot;&gt;do&lt;/span&gt;
      &lt;span class=&quot;n&quot;&gt;n&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;times&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;{&lt;/span&gt;&lt;span class=&quot;no&quot;&gt;Date&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;parse&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;s2&quot;&gt;&amp;quot;20071001&amp;quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)}&lt;/span&gt;
    &lt;span class=&quot;k&quot;&gt;end&lt;/span&gt; 
    &lt;span class=&quot;nb&quot;&gt;test&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;report&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;s2&quot;&gt;&amp;quot;Time.now: &amp;quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;k&quot;&gt;do&lt;/span&gt;
      &lt;span class=&quot;n&quot;&gt;n&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;times&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;{&lt;/span&gt;&lt;span class=&quot;no&quot;&gt;Time&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;now&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;}&lt;/span&gt;
    &lt;span class=&quot;k&quot;&gt;end&lt;/span&gt; 
    &lt;span class=&quot;nb&quot;&gt;test&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;report&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;s2&quot;&gt;&amp;quot;Date.new: &amp;quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;k&quot;&gt;do&lt;/span&gt;
      &lt;span class=&quot;n&quot;&gt;n&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;times&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;{&lt;/span&gt;&lt;span class=&quot;no&quot;&gt;Date&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;new&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;2007&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;10&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;1&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)}&lt;/span&gt;
    &lt;span class=&quot;k&quot;&gt;end&lt;/span&gt; 
    &lt;span class=&quot;nb&quot;&gt;test&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;report&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;s2&quot;&gt;&amp;quot;DateTime.civil: &amp;quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;k&quot;&gt;do&lt;/span&gt;
      &lt;span class=&quot;n&quot;&gt;n&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;times&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;{&lt;/span&gt;&lt;span class=&quot;no&quot;&gt;DateTime&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;civil&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;2007&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;10&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;1&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)}&lt;/span&gt;
    &lt;span class=&quot;k&quot;&gt;end&lt;/span&gt; 
    &lt;span class=&quot;nb&quot;&gt;test&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;report&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;s2&quot;&gt;&amp;quot;DateTime.parse: &amp;quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;k&quot;&gt;do&lt;/span&gt;
      &lt;span class=&quot;n&quot;&gt;n&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;times&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;{&lt;/span&gt;&lt;span class=&quot;no&quot;&gt;DateTime&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;parse&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;s2&quot;&gt;&amp;quot;20071001&amp;quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)}&lt;/span&gt;
    &lt;span class=&quot;k&quot;&gt;end&lt;/span&gt; 
    &lt;span class=&quot;nb&quot;&gt;test&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;report&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;s2&quot;&gt;&amp;quot;DateTime.strptime: &amp;quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;k&quot;&gt;do&lt;/span&gt;
      &lt;span class=&quot;n&quot;&gt;n&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;times&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;{&lt;/span&gt;&lt;span class=&quot;no&quot;&gt;DateTime&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;strptime&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;s2&quot;&gt;&amp;quot;20071001&amp;quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt;&lt;span class=&quot;s2&quot;&gt;&amp;quot;%Y%m%d&amp;quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)}&lt;/span&gt;
    &lt;span class=&quot;k&quot;&gt;end&lt;/span&gt; 
    &lt;span class=&quot;nb&quot;&gt;test&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;report&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;s2&quot;&gt;&amp;quot;Time.local: &amp;quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;k&quot;&gt;do&lt;/span&gt;
      &lt;span class=&quot;n&quot;&gt;n&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;times&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;{&lt;/span&gt;&lt;span class=&quot;no&quot;&gt;Time&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;local&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;2007&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;s2&quot;&gt;&amp;quot;oct&amp;quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;1&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)}&lt;/span&gt;
    &lt;span class=&quot;k&quot;&gt;end&lt;/span&gt; 
    &lt;span class=&quot;nb&quot;&gt;test&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;report&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;s2&quot;&gt;&amp;quot;Time.parse: &amp;quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;k&quot;&gt;do&lt;/span&gt;
      &lt;span class=&quot;n&quot;&gt;n&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;times&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;{&lt;/span&gt;&lt;span class=&quot;no&quot;&gt;Time&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;parse&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;s2&quot;&gt;&amp;quot;20071001&amp;quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)}&lt;/span&gt;
    &lt;span class=&quot;k&quot;&gt;end&lt;/span&gt; 
    &lt;span class=&quot;nb&quot;&gt;test&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;report&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;s2&quot;&gt;&amp;quot;Time.quick_parse: &amp;quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;k&quot;&gt;do&lt;/span&gt;
      &lt;span class=&quot;n&quot;&gt;n&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;times&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;{&lt;/span&gt;&lt;span class=&quot;no&quot;&gt;Time&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;quick_parse&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;s2&quot;&gt;&amp;quot;20071001&amp;quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)}&lt;/span&gt;
    &lt;span class=&quot;k&quot;&gt;end&lt;/span&gt; 
  &lt;span class=&quot;k&quot;&gt;end&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;
&lt;/div&gt;&lt;p&gt;Time.quick_parse is a method that I defined, it&amp;#8217;s going to be the fastest way to parse a string in the form &amp;#8220;&lt;span class=&quot;caps&quot;&gt;YYYYMMDD&lt;/span&gt;&amp;#8221;:&lt;/p&gt;
&lt;div class=&quot;highlight&quot;&gt;&lt;pre&gt;&lt;code class=&quot;ruby&quot;&gt;  &lt;span class=&quot;k&quot;&gt;class&lt;/span&gt; &lt;span class=&quot;nc&quot;&gt;Time&lt;/span&gt;
    &lt;span class=&quot;k&quot;&gt;class&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;&amp;lt;&amp;lt;&lt;/span&gt; &lt;span class=&quot;nb&quot;&gt;self&lt;/span&gt;
      &lt;span class=&quot;c1&quot;&gt;# Usage:  Time.quick_parse(&amp;quot;YYYYMMDD&amp;quot;)&lt;/span&gt;
      &lt;span class=&quot;k&quot;&gt;def&lt;/span&gt; &lt;span class=&quot;nf&quot;&gt;quick_parse&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;date_str&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;
        &lt;span class=&quot;n&quot;&gt;local&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;date_str&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;0&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;3&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;]&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; 
              &lt;span class=&quot;no&quot;&gt;RFC2822_MONTH_NAME&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;date_str&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;4&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;5&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;].&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;to_i&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;-&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;1&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;]&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt;
              &lt;span class=&quot;n&quot;&gt;date_str&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;6&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;7&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;]&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;
      &lt;span class=&quot;k&quot;&gt;end&lt;/span&gt;
    &lt;span class=&quot;k&quot;&gt;end&lt;/span&gt;
  &lt;span class=&quot;k&quot;&gt;end&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;
&lt;/div&gt;&lt;p&gt;The results:&lt;/p&gt;
&lt;pre class=&quot;boxed&quot;&gt;
                      user        system      total        real
  Date.strptime:      2.890000    0.040000    2.930000    (  2.982972)
  Date.parse:         3.630000    0.050000    3.680000    (  3.755735)
  Time.now:           0.010000    0.000000    0.010000    (  0.008608)
  Date.new:           0.590000    0.010000    0.600000    (  0.597446)
  DateTime.civil:     1.640000    0.010000    1.650000    (  1.675539)
  DateTime.parse:     4.970000    0.050000    5.020000    (  5.066107)
  DateTime.strptime:  4.250000    0.050000    4.300000    (  4.342663)
  Time.local:         0.120000    0.000000    0.120000    (  0.123242)
  Time.parse:         1.720000    0.010000    1.730000    (  1.750917)
  Time.quick_parse:   0.150000    0.000000    0.150000    (  0.157280)
&lt;/pre&gt;
&lt;p&gt;The version of Ruby that I&amp;#8217;m using:&lt;/p&gt;
&lt;pre class=&quot;boxed&quot;&gt;
  ruby -v 
  ruby 1.8.6 (2008-03-03 patchlevel 114) [universal-darwin9.0]
&lt;/pre&gt;</content>
 </entry>
 
 <entry>
   <title>How to install memcached on CentOS</title>
   <link href="http://codelikezell.com/how-to-install-memcached-on-centos"/>
   <updated>2007-10-11T00:00:00-07:00</updated>
   <id>http://codelikezell.com/how-to-install-memcached-on-centos</id>
   <content type="html">&lt;p&gt;&lt;!-- I want to use meta description:
Step-by-step instructions on installing memcached. Includes dependency libevent, and prevents problems with loading shared libraries.
  --&gt;&lt;/p&gt;
&lt;p&gt;This is a step by step guide to installing memcached from source on CentOS.  To install using yum instead, run &lt;code&gt;yum install memcached&lt;/code&gt;.  The version of CentOS that I am using is CentOS release 5.2 (Final); to find what version you are using:&lt;/p&gt;
&lt;pre class=&quot;boxed&quot;&gt;
  cat /etc/redhat-release
&lt;/pre&gt;
&lt;p&gt;First, install the dependency libevent:&lt;/p&gt;
&lt;pre class=&quot;boxed&quot;&gt;
  cd /usr/local/src
  curl -O http://monkey.org/~provos/libevent-1.4.14b-stable.tar.gz
  tar xzvf libevent-1.4.14b-stable.tar.gz 
  cd libevent-1.4.14b-stable
  ./configure --prefix=/usr/local
  make &amp;amp;&amp;amp; make install
&lt;/pre&gt;
&lt;p&gt;Next, install memcached:&lt;/p&gt;
&lt;pre class=&quot;boxed&quot;&gt;
  cd /usr/local/src
  curl -O http://memcached.googlecode.com/files/memcached-1.4.5.tar.gz
  tar xzvf memcached-1.4.5.tar.gz
  cd memcached-1.4.5
  LDFLAGS='-Wl,--rpath /usr/local/lib' ./configure --prefix=/usr/local
  make &amp;amp;&amp;amp; make install
&lt;/pre&gt;
&lt;p&gt;Verify that memcached starts:&lt;/p&gt;
&lt;pre class=&quot;boxed&quot;&gt;
  memcached -u root -d 
&lt;/pre&gt;
&lt;p&gt;If there were no errors, make sure it is running:&lt;/p&gt;
&lt;pre class=&quot;boxed&quot;&gt;
  ps aux | grep memcached
&lt;/pre&gt;
&lt;p&gt;And finally, to stop memcached:&lt;/p&gt;
&lt;pre class=&quot;boxed&quot;&gt;
  pkill memcached
&lt;/pre&gt;
&lt;p&gt;These instructions prevent the following errors:&lt;/p&gt;
&lt;pre class=&quot;boxed&quot;&gt;
  memcached: error while loading shared libraries: libevent-1.4.so.2: 
  cannot open shared object file: No such file or directory
  configure: error: libevent is required
  If it's already installed, specify its path using --with-libevent=/dir/
&lt;/pre&gt;</content>
 </entry>
 
 <entry>
   <title>Detecting the enter key with javascript</title>
   <link href="http://codelikezell.com/detecting-the-enter-key-with-javascript"/>
   <updated>2007-10-05T00:00:00-07:00</updated>
   <id>http://codelikezell.com/detecting-the-enter-key-with-javascript</id>
   <content type="html">&lt;p&gt;Let&amp;#8217;s inspect a key-press event to determine if the enter key was pressed.  The event instance has a property called keyCode, which indicates the enter key when set to 13.  Let&amp;#8217;s start with a text input:&lt;/p&gt;
&lt;div class=&quot;highlight&quot;&gt;&lt;pre&gt;&lt;code class=&quot;html&quot;&gt;  &lt;span class=&quot;nt&quot;&gt;&amp;lt;input&lt;/span&gt; &lt;span class=&quot;na&quot;&gt;type=&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&amp;quot;text&amp;quot;&lt;/span&gt; &lt;span class=&quot;na&quot;&gt;id=&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&amp;quot;foo&amp;quot;&lt;/span&gt;&lt;span class=&quot;nt&quot;&gt;&amp;gt;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;
&lt;/div&gt;&lt;p&gt;We can write an event handler to alert the contents of this field when enter is pressed:&lt;/p&gt;
&lt;div class=&quot;highlight&quot;&gt;&lt;pre&gt;&lt;code class=&quot;js&quot;&gt;  &lt;span class=&quot;nb&quot;&gt;document&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;getElementById&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;s1&quot;&gt;&amp;#39;foo&amp;#39;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;).&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;onkeypress&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;kd&quot;&gt;function&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;e&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;){&lt;/span&gt;
    &lt;span class=&quot;k&quot;&gt;if&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;!&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;e&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;nx&quot;&gt;e&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;nb&quot;&gt;window&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;event&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;;&lt;/span&gt;   &lt;span class=&quot;c1&quot;&gt;// resolve event instance&lt;/span&gt;
    &lt;span class=&quot;k&quot;&gt;if&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;e&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;keyCode&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;==&lt;/span&gt; &lt;span class=&quot;s1&quot;&gt;&amp;#39;13&amp;#39;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;){&lt;/span&gt;
      &lt;span class=&quot;nx&quot;&gt;alert&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;k&quot;&gt;this&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;value&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;);&lt;/span&gt;
      &lt;span class=&quot;k&quot;&gt;return&lt;/span&gt; &lt;span class=&quot;kc&quot;&gt;false&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;;&lt;/span&gt;
    &lt;span class=&quot;p&quot;&gt;}&lt;/span&gt;
  &lt;span class=&quot;p&quot;&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;
&lt;/div&gt;&lt;p&gt;IE will append the event instance to the window instead of passing it as a parameter to the handler, so the first line of our handler ensures that &lt;strong&gt;e&lt;/strong&gt; is set to the event instance, regardless of browser.  Next we see if keyCode is equal to &amp;#8216;13&amp;#8217;, which indicates the enter key.  If enter was pressed we alert the contents of the text box and return false.  We return false in case our input is within a form and we want to &lt;a href=&quot;/preventing-default-event-behavior-with-javascript&quot;&gt;prevent the event&amp;#8217;s default behavior&lt;/a&gt; (i.e. submitting the form).&lt;/p&gt;
&lt;p&gt;Let&amp;#8217;s try it out, type something in the field below and hit enter:&lt;/p&gt;
&lt;form&gt;
&lt;input type=&quot;text&quot; id=&quot;foo&quot;&gt;
&lt;input type=&quot;submit&quot; value=&quot;Won't submit on enter&quot;&gt;
&lt;/form&gt;
&lt;p&gt;&lt;span&gt;&lt;/span&gt;&lt;/p&gt;
&lt;script type=&quot;text/javascript&quot;&gt;
document.getElementById('foo').onkeypress = function(e){
  if (!e) e = window.event;   // IE appends event instance to window
  if (e.keyCode == '13'){
    alert(this.value);
    return false;
  }
}
&lt;/script&gt;&lt;p&gt;I would also like to mention that there is no need to resolve the event instance if we use jquery or prototype.  Here is how we would accomplish the same thing with jquery:&lt;/p&gt;
&lt;div class=&quot;highlight&quot;&gt;&lt;pre&gt;&lt;code class=&quot;js&quot;&gt;  &lt;span class=&quot;nx&quot;&gt;$&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;s1&quot;&gt;&amp;#39;#foo&amp;#39;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;).&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;keypress&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;kd&quot;&gt;function&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;e&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;){&lt;/span&gt;
    &lt;span class=&quot;k&quot;&gt;if&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;e&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;keyCode&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;==&lt;/span&gt; &lt;span class=&quot;s1&quot;&gt;&amp;#39;13&amp;#39;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;){&lt;/span&gt;
      &lt;span class=&quot;nx&quot;&gt;alert&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;k&quot;&gt;this&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;value&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;);&lt;/span&gt;
      &lt;span class=&quot;k&quot;&gt;return&lt;/span&gt; &lt;span class=&quot;kc&quot;&gt;false&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;;&lt;/span&gt;
    &lt;span class=&quot;p&quot;&gt;}&lt;/span&gt;
  &lt;span class=&quot;p&quot;&gt;});&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;
&lt;/div&gt;&lt;p&gt;And finally, with prototype:&lt;/p&gt;
&lt;div class=&quot;highlight&quot;&gt;&lt;pre&gt;&lt;code class=&quot;js&quot;&gt;  &lt;span class=&quot;nx&quot;&gt;$&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;s1&quot;&gt;&amp;#39;foo&amp;#39;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;).&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;observe&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;s1&quot;&gt;&amp;#39;keypress&amp;#39;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;kd&quot;&gt;function&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;e&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;){&lt;/span&gt;
    &lt;span class=&quot;k&quot;&gt;if&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;e&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;keyCode&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;==&lt;/span&gt; &lt;span class=&quot;s1&quot;&gt;&amp;#39;13&amp;#39;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;){&lt;/span&gt;
      &lt;span class=&quot;nx&quot;&gt;alert&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;k&quot;&gt;this&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;value&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;);&lt;/span&gt;
      &lt;span class=&quot;nx&quot;&gt;Event&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;stop&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;e&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;);&lt;/span&gt;
    &lt;span class=&quot;p&quot;&gt;}&lt;/span&gt;
  &lt;span class=&quot;p&quot;&gt;});&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;
&lt;/div&gt;</content>
 </entry>
 
 <entry>
   <title>How to use Ruby variables in regular expressions</title>
   <link href="http://codelikezell.com/how-to-use-ruby-variables-in-regular-expressions"/>
   <updated>2007-09-27T00:00:00-07:00</updated>
   <id>http://codelikezell.com/how-to-use-ruby-variables-in-regular-expressions</id>
   <content type="html">&lt;p&gt;If you do not know the pattern that you are trying to match ahead of time (e.g. it is some form of user input), you can construct a regex from a string:&lt;/p&gt;
&lt;div class=&quot;highlight&quot;&gt;&lt;pre&gt;&lt;code class=&quot;ruby&quot;&gt;  &lt;span class=&quot;n&quot;&gt;str&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;s2&quot;&gt;&amp;quot;this string has ruby in it&amp;quot;&lt;/span&gt;
  &lt;span class=&quot;n&quot;&gt;re&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;s2&quot;&gt;&amp;quot;ruby&amp;quot;&lt;/span&gt;
  &lt;span class=&quot;n&quot;&gt;str&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=~&lt;/span&gt; &lt;span class=&quot;sr&quot;&gt;/&lt;/span&gt;&lt;span class=&quot;si&quot;&gt;#{&lt;/span&gt;&lt;span class=&quot;no&quot;&gt;Regexp&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;escape&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;re&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;si&quot;&gt;}&lt;/span&gt;&lt;span class=&quot;sr&quot;&gt;/&lt;/span&gt;    &lt;span class=&quot;c1&quot;&gt;# =&amp;gt; 16&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;
&lt;/div&gt;&lt;p&gt;You can also combine components to create a new pattern:&lt;/p&gt;
&lt;div class=&quot;highlight&quot;&gt;&lt;pre&gt;&lt;code class=&quot;ruby&quot;&gt;  &lt;span class=&quot;n&quot;&gt;a&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;s1&quot;&gt;&amp;#39;ruby&amp;#39;&lt;/span&gt;
  &lt;span class=&quot;n&quot;&gt;b&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;s1&quot;&gt;&amp;#39;on rails&amp;#39;&lt;/span&gt;
  &lt;span class=&quot;n&quot;&gt;str&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;s2&quot;&gt;&amp;quot;this string has ruby on rails in it&amp;quot;&lt;/span&gt;
  &lt;span class=&quot;n&quot;&gt;str&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;match&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;sr&quot;&gt;/&lt;/span&gt;&lt;span class=&quot;si&quot;&gt;#{&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;a&lt;/span&gt;&lt;span class=&quot;si&quot;&gt;}&lt;/span&gt;&lt;span class=&quot;sr&quot;&gt; &lt;/span&gt;&lt;span class=&quot;si&quot;&gt;#{&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;b&lt;/span&gt;&lt;span class=&quot;si&quot;&gt;}&lt;/span&gt;&lt;span class=&quot;sr&quot;&gt;/&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;    &lt;span class=&quot;c1&quot;&gt;# =&amp;gt; true&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;
&lt;/div&gt;&lt;p&gt;If you are looking for a way to create patterns from combinations of common elements, and the elements are not derived from input, it is just as easy to combine Regexp objects:&lt;/p&gt;
&lt;div class=&quot;highlight&quot;&gt;&lt;pre&gt;&lt;code class=&quot;ruby&quot;&gt;  &lt;span class=&quot;n&quot;&gt;a&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;sr&quot;&gt;/ruby/&lt;/span&gt;
  &lt;span class=&quot;n&quot;&gt;b&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;sr&quot;&gt;/on rails/&lt;/span&gt;
  &lt;span class=&quot;n&quot;&gt;str&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;s2&quot;&gt;&amp;quot;this string has ruby on rails in it&amp;quot;&lt;/span&gt;
  &lt;span class=&quot;n&quot;&gt;str&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;match&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;sr&quot;&gt;/&lt;/span&gt;&lt;span class=&quot;si&quot;&gt;#{&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;a&lt;/span&gt;&lt;span class=&quot;si&quot;&gt;}&lt;/span&gt;&lt;span class=&quot;sr&quot;&gt; &lt;/span&gt;&lt;span class=&quot;si&quot;&gt;#{&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;b&lt;/span&gt;&lt;span class=&quot;si&quot;&gt;}&lt;/span&gt;&lt;span class=&quot;sr&quot;&gt;/&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;  &lt;span class=&quot;c1&quot;&gt;# =&amp;gt; true&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;
&lt;/div&gt;</content>
 </entry>
 
 
</feed>

