Javascript/CSS page print preview
So I took what I could find and came up with the following method of doing this.
I took the basic method and javascript code from Paul Sowden's article at A List Apart and mixed in my own specifics. Consult this article if you don't understand what I am doing. You should also look at Eric Meyers article at A list Apart on print style sheets if you don't understand creating a print stylesheet.
So here is what I did:
Rails Date Parser 1
So this is a simple to install simple to use extension to the ruby Date class. To use it simply copy the following code to a file named dateparse.rb and place it in the lib directory in your rails app. Then open up the application controller and and put require 'dateparse' at the top of the file. (Note: put it before the class declaration).
Then in your controller or view code use Date.parse_date() in place of Date.parse(). It recognizes the following formats
YYYY-mm-dd ISO Standard
mm-dd-YYYY American
mm-dd Assume current year
mm/dd/YYYY American standard
mm/dd
mm.dd.yyyy European
dd.mm.yyyy
dd mmmmm yyyy example: 22 may 1945 or 22nd may 1945
dd mmmmm example: 22 may (current year)
mmmm dd yyyy example: may 22 1945 or may 22nd 1945
mmmm dd, yyyy example: may 22, 1945
mmmm dd example may 22 or may 22nd
dd example 4 or 4th
today (tod) or now common names for days and abbreviations
tomorrow (tom)
yesterday (yes)
Next Week, Last Week, Next Month, Last Month, Next Year, Last Year
+n[units] or -n[units]: Date from today: examples: '+22', '+22 days',
'+22d', '-4 weeks', '-4w', '-4week', '+6 months', '+6m', '+6month',
'-2 years', '-2y'
Debian Etch Apache 2.2 and mod_fastcgi
I recently got around to upgrading a server I had running Debian Sarge. The upgrade went fairly well except for Apache 2.2 and mod_fcgi. Apache would not load with the version of mod_fcgi I had been using (2.4.2). So I went looking for the fix.
Bird Feeder Mystery
About a month ago I set out some bird feeders. After a few days the suet all disappeared one day after not much activity. After looking at things I decided it was probably squirrels.
A few days ago, we looked out of the house and say a female red fox eating stuff on the ground under the bird feeder. I wondered at the time if that was what had gotten the suet.
Well I was wrong it was a small coon and I have the pictures to prove it.
 
link_to_sort
I have created a little view helper that I use in my ROR applications. I call it link_to_sort. What it does is create a clickable header on a list page that sorts the list by that header.
I add it to the application helper and make minimal changes to the controller list action and add one routine to the application controller to make it work.
Log4r and Rails 7
In a rails application I am working on I needed to set up logging for the events happening in the system. After a little perusing on the net I figured that log4r was the way to go. Then as with a lot of ruby apps, I found the documentation wanting. Yes I know the api and source is on line but a little more help to get started would be helpful. So I thought I would share what I had gleaned from the various sources and how I got it working.
Data Normalization in Rails 2
For a project I am working on (in Rails of course) I wanted to display currency like currency in a data field. This was easy just use the number_to_currency helper in the view. Ok maybe not so easy when you use the text_field helper. Some code will illus trate how to do it.
<%= text_field "invoice", 'total', :value => number_to_currency(@invoice['total']) %>
That only took a few minutes to figure out.
Now the problem comes trying to save the value back into the database. ActiveRecord typecasts $9.00 to 0.00 because $9.00 is con sidered a string. I knew it should be easy to do and after far too long looking for the answer I found it. In the model, use the b efore_save callback to make changes to the before_type_cast attribute. Some code will illustrate it:
class Invoice < ActiveRecord::Base
before_save :fix_currency
def fix_currency
total_before_type_cast.tr!('$,','')
end
end
You could, of course, add any other normalization routines here.
Hope this will save someone some time.
Form Field Values and Ajax 2
In a project, I am working on, I found it necessary to read the value from one text field and update the value in another text field with Ajax without submitting the form.
Since I am using Ruby on Rails, I figured it could be done, I just had to figure out how. Here was the problem: take a value entered in to field one, perform a permutation on it and return the calculated value back into field 2. Of all the methods ROR offers to make the Ajax call, I chose the link_to_remote method, since I could link it to a little graphic. Getting the basic Ajax working was simply a matter of creating the method in the controller and returning the value. My initial code looked like this:
Exim4 Mailq Manager
I have a couple of backup mail servers that get a lot of spam and their mailqs fill up quickly. I looked around for a simple package to manage the queue through a webserver and found none. So I created one and offer it up for all to use. (GPL)
All t he real work is done in a php script run by cron. This script first checks for messages to be deleted and does so if necessary; the n it creates the html files needed for the files currently in the queue.
The html interface displays a list of the messages in the queue. With each message, you can view the header or body and mark it for deletion. Since the messages are only deleted by th e cron job, you can also unmark them.
 
Click > Mailq Manager 1.0 < to download the package. 
Note: I have only used this on some Debian boxen -- If you use it on something else and run int o trouble, please let me know. 
Enjoy



