Date format
Format a date in ruby using the string from time method (strftime).
Format options:
%a - The abbreviated weekday name (``Sun'')
%A - The full weekday name (``Sunday'')
%b - The abbreviated month name (``Jan'')
%B - The full month name (``January'')
%c - The preferred local date and time representation
%d - Day of the month (01..31)
%H - Hour of the day, 24-hour clock (00..23)
%I - Hour of the day, 12-hour clock (01..12)
%j - Day of the year (001..366)
%m - Month of the year (01..12)
%M - Minute of the hour (00..59)
%p - Meridian indicator (``AM'' or ``PM'')
%S - Second of the minute (00..60)
%U - Week number of the current year,
starting with the first Sunday as the first
day of the first week (00..53)
%W - Week number of the current year,
starting with the first Monday as the first
day of the first week (00..53)
%w - Day of the week (Sunday is 0, 0..6)
%x - Preferred representation for the date alone, no time
%X - Preferred representation for the time alone, no date
%y - Year without a century (00..99)
%Y - Year with century
%Z - Time zone name
%% - Literal ``%'' character
t = Time.now
t.strftime("Today is %m/%d/%Y") #=> "Today is 04/29/2008"
t.strftime("at %I:%M %p") #=> "at 10:04 PM"
Ruby on Rails for RHEL 5
Here is the quick and dirty Ruby on Rails setup for Redhat Enterprise Linux v5 with MySQL.
Using yum install ruby and mysql. The command below does not list all the required packages, but due to dependencies, the additional packages will be installed (or should be - this is all from memory).
Read the rest of this entry »
Reduce database connections using :include
When displaying a list that requires information from several tables in the database, you can sometimes end up with three or more database queries per list row. Depending on the situation, this may not be a problem. However, it is possible to join the tables in one large SQL query using the :include option.
@requests = Request.find(:all, :include => [:department, :status])
Using the :include option may improve performance. However, it will likely use more server memory and could potentially return a lot of data through the joins that may not even be used.
Move an LVM-based virtual machine to another host
For those running Xen on servers with no back-end SAN, the following instructions detail the steps necessary to move an LVM-based virtual machine to a new physical host. There may be more elegant ways to achieve this, but this is what worked for me.
Environment
Ok, so let’s set the scene:
vmhostis a RHEL 5 server running several virtual machines using the Xen virtualization technology. Each virtual machine is allocated a 60 GB logical volume within an LVM volume group. One of these virtual machines, “win2k3vm”, needs to be moved to a new server.new-vmhostis almost identical to vmhost, but has updated hardware and more memory. This is the server that “win2k3vm” will be moved to.
Install phpMyAdmin
phpMyAdmin is web-based PHP application for managing MySQL databases. It is fairly easy to install and configure.
Download the latest stable version from the phpMyAdmin web site, and extract it to a location of your choice. I prefer to keep the installation outside of the web root and use an apache alias to reference it.
Read the rest of this entry »
