Javascript/CSS page print preview

Posted by Tom Willett Wed, 09 Jul 2008 17:53:00 GMT

I looked around for a simple example of creating a print preview button/link on a webpage. I already had a print.css which handled the printing but my users could not seem to find the print and print preview links on their browsers. Sigh.

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

Posted by Tom Willett Fri, 27 Jun 2008 20:11:00 GMT

I became frustrated with date parsing in Rails and Ruby and so created a user friendly parser for dates. I wanted to avoid a big javascript library or using a date-picker widget. Quite frankly, when I am entering dates, I don't like to have to reach for the mouse and scroll through the dates.

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

Posted by Tom Willett Thu, 19 Apr 2007 15:09:00 GMT

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

Posted by Tom Willett Fri, 13 Apr 2007 18:08:00 GMT

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

Posted by Tom Willett Fri, 16 Feb 2007 16:46:00 GMT

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

Posted by Tom Willett Thu, 01 Feb 2007 15:33:00 GMT

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

Posted by Tom Willett Wed, 20 Dec 2006 21:44:00 GMT

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

Posted by Tom Willett Fri, 08 Dec 2006 02:26:00 GMT

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

Posted by Tom Willett Fri, 03 Nov 2006 22:43:00 GMT

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

Pileated Woodpecker

Posted by Tom Willett Mon, 23 Oct 2006 18:55:00 GMT

Today, while walking through the woods, I heard a faint peck, peck. After going up the hill a ways I spotted a Pileated Woodpecker on some fallen trees pecking away. He was buried in the brush and I could not get a good picture, but you can make him out through the brush. After he left I went and tried to find what he was eating but I only found the hole. Note, after posting this I found where the woodpeckers had pecked holes in the styrofoam covering our basement. This is stucco covering styrofoam over concrete block -- not very tasty.

Pileated Woodpecker

Pileated Woodpecker Hole




Woodpecker Damage

Older posts: 1 2 3 4 5