Blog

Ruby or PHP strftime Without Leading Zeros

The docs for strftime() in both PHP and Ruby seem to assume that you prefer your dates and times to be formatted with leading zeros padding the output to 2 characters. For the minutes, this seems logical enough (4:05 instead of 4:5), but for the hours field it can be a little unattractive (04:05). Here are the format strings you can use for non-zero padded versions of the fields:

%l: The hour in 12-hour format, without a leading zero
%e: The day of the month, without a leading zero

How to Reset a Lost MySQL Password

  mysqld --skip-grant-tables &
  mysql -h 127.0.0.1 mysql

Overriding Default Getters in ActiveRecord

I find somewhat frequent occasions where dynamic Model getters are handy. The most common case is where you want to use the value of one attribute unless it's nil, in which case you want to use another attribute instead. You could do @object.field1 || @object.field2, but that's not very DRY if you do it often.

Instead, you can override the default attribute accessor that ActiveRecord builds for you with code like the following:

Multiple Selection Binding for Complex Objects in Spring

I ran into an issue where I needed to offer a multiple select interface to edit a many-to-many association of one domain object to another (assigning multiple roles to a user).

This JRoller Post helped me solve the issue.

What Version of Linux am I Running?

I sometimes work on client's servers where the installed distribution and version of Linux are unknown at first. How do you find out which version of Linux is installed? Well, each distribution is different, so it may be necessary to try all of the following.

Determine the Installed Version of Redhat-based Systems


cat /etc/redhat-release

Determine the Installed Version of Debian


cat /etc/debian_version

Determine the Installed Version of Ubuntu


cat /etc/issue

or


cat /etc/lsb-release

Accidentally Deleted My Show Desktop Icon

I accidentally deleted my "Show Desktop" shortcut icon today. I guess it's one of those features I took for granted, because I sure missed it once it was gone. After a little digging on another computer, I've figured out how to restore it.

Step One:

Create a text file with the following contents:

[Shell]
Command=2
IconFile=explorer.exe,3
[Taskbar]
Command=ToggleDesktop

Step Two:

Save that file as "Show Desktop.scf" and place it in your Quick Launch folder (%USERPROFILE%\Application Data\Microsoft\Internet Explorer\Quick Launch). %USERPROFILE%,

Two Column or "Double-Justified" Lists

Here's a CSS tutorial to create double-justified lists. This is the most readable way I've found to present a list of dated links in a compact format. I first used this as a method to display a blog archive in a sidebar. Here's the example:

  • 5/4New Yorker

How to Regain Root Password Using Grub Commands

From http://forums1.itrc.hp.com/service/forums/questionanswer.do?threadId=827712&admit=-682735245+1152513688084+28353475

interrupt the grub loader (hopefully you've got a pause there) by just hitting the arrow key around at the menu choice for the grub loader - this will make the timer countdown stop.

Then,
go to the line that holds your choice of the Linux load you want and hit "e" (for edit). This will bring you into an editor for the current load command. Choose the line you want ( I can't remember which one you need off the top of my head - there's probably two - try it on both), and hit "e" once again. Now, you should be editing a single line of the loader. Arrow key to the end of teh command and and the parameter "single" to the end of the line. Hit enter to "save" (only in the buffer - not on the disk) the command.

Ubuntu Dapper Install on Intel Centrino Laptop with on-board ATI Graphics

1. Install Ubuntu.
2. Run all updates from Synaptic.
3. Install Automatix

Edit /etc/apt/sources.list

deb http://www.beerorkid.com/automatix/apt dapper main

Import key

wget http://www.beerorkid.com/automatix/apt/key.gpg.asc
gpg --import key.gpg.asc
gpg --export --armor 521A9C7C | sudo apt-key add

Install

sudo apt-get update
sudo apt-get install automatix

4. Run Automatix

Choose the following:
- Thunderbird 1.5
- DVD Codecs
- Music players and codecs
- Flash
- Java 1.5 JDK and JRE
- nVidia Card Drivers
- Web editing and code tools

Ubuntu Dapper Install on Dual-Core AMD with nVidia Graphics

1. Install Ubuntu.
2. Fix Grub


title Windows XP
root (hd0,0)
savedefault
makeactive
chainloader +1

3. Install Automatix

Edit /etc/apt/sources.list

deb http://www.beerorkid.com/automatix/apt dapper main

Import key

wget http://www.beerorkid.com/automatix/apt/key.gpg.asc
gpg --import key.gpg.asc
gpg --export --armor 521A9C7C | sudo apt-key add

Install

sudo apt-get update
sudo apt-get install automatix

4. Run Automatix

Choose the following:
- Thunderbird 1.5
- DVD Codecs
- Music players and codecs