Friday, December 14, 2007

Rails Multi-Model Forms

Here is an excellent plugin to do all the magic.

URLs With file_column

This patch modifies the Rails file_column plugin so that it may download a remote file via HTTP in addition to using uploaded data. Now you can specify a string with a full valid URL.

Run it against lib/file_column.rb

Enjoy! file_column patch.

Thursday, December 13, 2007

Rails 2.0 Screencast

He goes a bit fast:

Direct links to the text versions:

Getting Rails 2.0 Running

So, Rails 2.0 has finally been released. It was a bit of a pain getting all my Ruby Gems updated for some reason. Please keep in mind that the MySQL path is specific to OSX 10.5.

$ sudo gem update sources
$ sudo gem update --system

$ sudo gem uninstall mysql
$ sudo gem install mysql -- --with-mysql-dir=/usr/local/mysql
$ sudo gem update -- --with-mysql-dir=/usr/local/mysql
$ sudo gem install rails --include-dependencies

I know there is a bit of duplicated effort there, but I had issues with that MySQL gem.

Finally Rails 2.0 joy. Now to fiddle around with it before starting a new project...

Installing the MySQL Ruby Gem for Rails MySQL Support on OSX Leopard

Some special command line magic is required to install the MySQL Gem on OSX Leopard (10.5).

$ export ARCHFLAGS="-arch i386"
$ sudo gem install mysql -- --with-mysql-dir=/usr/local/mysql

I got this information from

Wednesday, December 05, 2007

Netbeans 6 Final

Finally released! There's not many pieces of software I will actually use in beta, but. Wow. Amazing IDE here. I wish there had been nice open source IDE's like this back in the day.

Wednesday, November 21, 2007

Rails SQL Optimization

In order to automate the optimization of SQL queries in Ruby on Rails, I wrote this script to parse the output of the logs. It finds all the unique SQL queries made by different controllers, and runs an SQL EXPLAIN for each. This is really good for finding missing indexes and large table scans.

I have only tested this on Mac/MySQL, so your mileage may vary (it uses *NIX file paths). This script has saved me MUCH time. Of course, when optimizing queries, don't go overboard on eager loading. ActiveRecord eager loading can be slow if you use multiple nested includes.

Just run this script within your Rails application root directory, and it will create a file named explained.html. You may set the RAILS_ENV environment variable to specify production mode. The script automatically loads your database configuration from log/database.yml

Oh, and there needs to be at least 2 pageloads in your log. I haven't bothered fixing this bug.

So here is the script.

UPDATE: I came across some good tips for additional optimization here.

Friday, May 04, 2007

Dynamic DNS Setup In Ubuntu Using DynDNS

I use for dynamic domain services. There is easy setup and you can update your IP via a web browser, or schedule an application to run on a regular basis. Updating your IP address is important because you will lose your domain if you don’t update your record every 30-35 days. Here is a basic guide.

In Debian/Ubuntu you can install the updater via apt:

sudo apt-get install ipcheck

Create bin directory, dyndns directory and updater script:

mkdir ~/bin
mkdir ~/.dyndns
touch ~/bin/
chmod 700 ~/bin/
vi ~/bin/



cd ~/.dyndns
if [ -f ~/.dyndns/ipcheck.dat ]; then
/usr/sbin/ipcheck -r \
/usr/sbin/ipcheck --makedat -r \

Edit your crontab:

crontab -e

Add the following line to your crontab to run the script daily.

* 6 * * * /home/username/bin/

Tuesday, May 01, 2007

User Driven Sites

Today was completely spammed by user submitted articles about the HD-DVD media access key. Digg admins rightly decided to censor and ban users posting the number to avoid legal consequences. I only hope that the community driven site I am making doesn’t suffer from similar problems.

Thursday, March 22, 2007

A Server Monitor

I can't believe that I haven't been doing proper server monitoring. Well, that had to come to an end. I didn't like any of the monitoring apps out there and I did as a good code primate should and wrote my own. Here is my own server monitor and module written in and for Ruby. It outputs in XML format.

You write a simple XML configuration file, and call the app via the commandline specifying where the config, output, and XSL template are (cross-domain issues with XSL are fun!).

What are you waiting for?

Tabbed Pages with CSS and Javascript

It's been done before many times, but here's my stab at it. This took me far too long, as my javascript and CSS skills are severely lacking (I like backend stuff better, what can I say?).

What we have here is a horizontally styled list acting as a navigation bar, and a set of hidden divs shown when appropriate.

Source here.

Monday, March 05, 2007

Must-Have DVD Apps

DeVeDe: DVD Authoring Tool
k9copy: DVD9 to DVD5 copier
Thoggen: Rip DVD to OGG video

Friday, March 02, 2007

Hard Drive Performance and hdparm

Ok, I don't invest that much cash into my computer. Heck, I haven't purchased new (or used) computer hardware for myself in almost 2 years. My computer is at least 6 years out of date. Its slow.

Well, a RAM stick went out and I am down to 512MB, can we say SWAP???. So I checked out the ouput from hdparm and I had a nasty surprise. 8.59 MB/sec!!!

hdparm to the rescue.

$ hdparm -c3 -m16 -d1 -u1 -X70 -k /dev/hdb

37.99 MB/sec!!!

That should improve performance significantly!

Note: These settings are for a Seagate Barracuda 80GB

$ sudo hdparm -I /dev/hdb
ATA device, with non-removable media
Model Number: ST380021A
Serial Number: 3HV291LP
Firmware Revision: 3.19

Friday, February 16, 2007

Gnome Startup Programs Bug

If you specify additional startup programs through the Gnome Sessions application, and your changes won't save, it is likely that "~/.config/autostart" has the wrong file ownership. Sometimes installation of Beagle will screw things up.

To correct:
sudo chown -R username:username /home/username/.config

Friday, February 09, 2007

Ruby HTTPS with HTTP Basic Auth

Fetching HTTPS data with Ruby using HTTP Basic Authorization

require 'net/http'
require 'net/https'

def get_feed(server,path,username,password)
http =,443)
req =
http.use_ssl = true
req.basic_auth username, password
response = http.request(req)
return response.body

Wednesday, January 31, 2007

Complicity in Murder

This would have been more topical awhile back, but considering 
Saddam Hussein's execution is still in very recent memory it is 
worth remembering that the United States government has long been aware of the crimes that Saddam committed, and to a certain
extent complicit.  A key quote from Barry Lando:
The US gave satellite information, more to the Iraqis, enabling them to target Iranian troop concentrations, even though the US knew that the Iraqis were using chemical weapons.

Follow the link for an enlightening interview with a former 60 Minutes producer.

Monday, January 22, 2007

SSH Public Key Authentication

SSH Public Key Authentication
(password-less SSH authentication on *nix systems)

Its a pain to enter in passwords all day. If you are like me and have a dozen or more machines and accounts to maintain, password management gets ridiculous. A great solution is public key authentication. You create a public key and a private key on a client machine, and distribute the public key to the various accounts and servers you need to access. The public key identifies you, and your private key verifies your identity. You only create your key pair once, and place your public key on all the servers you want to configure for password-less login. If you do create another new key pair on the local machine, you will again have to follow the steps for configuring the remote machines.

Keep in mind, the idea is to have a key pair for a specific local account on a specific machine. If you want to be able to use password-less login from another machine, you should create a new key pair on that machine. DON'T simply copy your key pair to another machine.

Public key authentication also makes scripted remote management possible, but thats beyond the scope of this mini-article. So let's begin:

On Local/Client Machine
# Create .ssh directory unless it already exists
mkdir ~/.ssh
cd ~/.ssh

# Create your keypair. Specifying a password will protect your private key even if the private key file is compromised. Remember, the private key file identifies you, and if that file is compromised, the server is compromised as well. Regardless of password security, set secure permissions for this file.
ssh-keygen -t dsa
chmod 600 id_dsa

# Copy your public key to the server, specifically your remote user's home directory.

# Now login to the remote machine via ssh

On Remote/Server Machine
# Create the .ssh directory unless it exists
mkdir ~/.ssh
cd ~/.ssh

# Create the authorized key file unless it already exists
touch authorized_keys2
chmod 600 authorized_keys2

# Append your public key to the authorized key file. Directly editing the key file is generally a bad idea. Then delete the public key file you copied to this machine.
cat ~/ >> authorized_keys2
rm ~/

You may now logout, and log back in. This time you should be automatically logged in without a password prompt.

If you mess up, or your private key is compromised, there is a small amount of cleanup involved. On each of the configured servers, delete the line in the authorized_keys2 file that corresponds to your public key, and delete your local key pair as well. You can then start over.

Strip HTML Tags

It's trivial really...but regexp's are a bitch.

#!/usr/bin/ruby -n
puts $_.gsub(/<\/?[^>]*>/, "")

Sunday, January 21, 2007

Edit A Webpage in Place

This works for Firefox. Enter the following into the address bar.

javascript:document.body.contentEditable='true'; document.designMode='on'; void 0

This is an interesting hack. It is nothing of immediate utility, but combined with some other functionailty...

Thursday, January 18, 2007


A quote from today's Senate Judiciary Committee hearings.

Specter: Now wait a minute, wait a minute. The Constitution says you can't take it away except in the case of invasion or rebellion. Doesn't that mean you have the right of habeas corpus?

Gonzales: I meant by that comment that the Constitution doesn't say that every individual in the United States or every citizen has or is assured the right of habeas corpus. It doesn't say that. It simply says that the right of habeas corpus shall not be suspended.

Apparently our ATTORNEY GENERAL doesn't understand the fundamental premise of the Constitution, that ALL rights not EXPLICITLY given to the government are retained by the people.

Ruby Cheat Sheets

I found a handy ruby gem that makes reference very easy. gem install cheat to install the gem, then run cheat sheets to get a list of available cheat sheets. Run cheat cheat_name to display useful info.

Sunday, January 14, 2007

United States Activities Inside Iran?

This morning, national security advisor Stephen Hadley spoke about US engagement of Iranians aiding insurgents in Iraq.

When asked whether U.S. forces would cross into Iran to pursue those aiding Iraqi insurgents, he said: He said the priority "is what's going on inside Iraq. ... That's where we're going to deal with his problem." and, "Anytime you have questions about crossing international borders there are legal issues. ... We intend to deal with it by interdicting and disrupting activities in Iraq sponsored by Iran."

This response raises several questions as to whether the U.S. IS currently operating inside Iran. This administration has had a pattern of operating outside of established legal precedent (NSA wiretapping case, abuse of prisoners, suspension of habeas corpus, extraordinary rendition, etc, etc.), then dealing with the consequences (or lack of), later. In my mind, these aren't questions, but rather indications, but there is the cynicism and pragmatism.

Don't get me wrong, if people are assisting insurgents in killing our troops, they should be taken care of. Yet military incursions into a sovereign country against citizens of that country is an act of war, and war must be declared by Congress. Hence the "legal issues" mentioned by Mr. Hadley. Regardless, it has been apparent for some time that the administration's mind and direction are already set.

Just last Thursday, U.S. forces captured and detained 5 Iranian officials of relatively high rank. It has become obvious, that Iran is supporting at least the Shia side of the insurgency, and is establishing a political and military toehold in the power vacuum of Iraq.

War with Iran has already started. With politics, and on a small scale (on our side), soldiers. The battleground just happens to be Iraq.

Friday, January 12, 2007

Disable Low Disk Space Notification in Windows XP

1.Click Start, click Run, type regedit, and then click OK.
2.Locate and then click the following key in the registry:
3.On the Edit menu, point to New, and then click DWORD Value.
4.Type NoLowDiskSpaceChecks, and then press ENTER.
5.On the Edit menu, click Modify.
6.Type 1, and then click OK.
7. Logout.


Wednesday, January 03, 2007

Rails Development Using Vim

Rails developers fortunate enough to run OSX have raved to no end about TextMate, but what do the rest of us, being *Nix and Windows users, have available? RadRails is an EXCELLENT IDE, and I have used it almost exclusively for nearly a year now, but as an editor, like all software, it has severe limitations. It's a bit slow and too much of a memory hog for my taste, and not nearly as easy to extend as I would like.

In my experience as a Linux administrator and desktop user, I have learned to appreciate, and now love the Vi editor. Well, more accurately Vim. If you are using a GUI, Cream is an excellent set of customizations for GVim that make Vim more accessible to the new user.

To improve the state of affairs even further, there are various Ruby and Rails specific extensions and customizations that bring Vim to the point of being nearly as good, and better in some ways, than TextMate or RadRails. We're talking autocompletion, autoindention, syntax highlighting, abbreviations, and much much more. See this post (so useful to me that I mirrored it here) for how to tweak Vim for Rails development.