ListYourWish.com
I just thought I would share a project I’ve been working on with you. I’m not a designer at all so you can look past the design (or lack thereof). Design ideas welcome
!
ListYourWish.com is a place for you to keep an ongoing wish list for events in your life; ie Christmas, Birthday, Graduation, or any other event you would normally receive gifts for. It automatically sends out notifications to your friends and family with you up-to-date wish list so they know what to get for you.
I will be working on performance and features in the next few weeks to come. This will be the second RoR application I’ve put on dreamhost and they both seem to run very slow; even in production mode. Let me know if you have any tricks for speeding up RoR on Dreamhost.
Any comments, suggestions, or money
welcome.
Adding Rails cron jobs on Dreamhost
Okay, so I thought adding a cron job for my RoR application would be pretty easy. Having never done it before I started hitting the search engines to the how-to’s. I found this to be a lot harder than I thought due to some technical difficulties (on my part) so I want to detail how i FINALLY got it done.
First, http://wiki.dreamhost.com/index.php/Crontab is dreamhost’s writeup about crontab and it has mostly what you need for the syntax of each line in the crontab.
Here’s what I learned, a crontab holds a list of all the cron jobs you want to perform. At first i tried to create a local .txt file on my computer and ftp it up to the server. Due to the .txt file’s format and the fact that I’m using Dreamweaver for FTP (which I would not recommend), something did not work; something about ASCII format and the way it uploads the file (and also something about the last character in the file has to be cr\lf) <- dont worry about that.
So, this is how I got it done.
- I SSH’d to my dreamhost account (you can get there right?).
- Then type crontab -l to list the contents of your crontab file. If this is the first you’ve done of this kind of thing it will say that you dont have a crontab file.
- Next you need to change the default text editor to vim. Nano is the default editor for dreamhost and it will not work for creating a crontab. it has something to do with the way it writes an asterick (*). Type export EDITOR=vim to change the editor to vim. Note: I am horrbile with the commands for using vim as an editor and found this cheatsheet helpful: http://www.lagmonster.org/docs/vi.html
- Now you need to create the crontab file. Do so by typing crontab -e
- Ok, press ‘i’ to get into “insertion mode” in the text file. In my crontab the first line i specify my email address to send errors to. This is optional. If you want it, type MAILTO=”youremailaddress@somewhere.com” in the first line and press enter.
- We’re now going to add our first cron job to this file. Go to the link above to understand the components of the line you will be adding. In my crontab my first cron job looks like this
59 2 * * * ~/listyourwish.com/script/runner -e development 'ScheduledNotifications.send_out_notifications' > /cronlogs/notifications.log. This is telling crontab to run this job at 2:59am every day of every month of every year. A couple fo things to note here; the “~/” portion of the path referrs to your user’s home directory (/home/username). And the “> filename.log” tells crontab to write errors to that log file. Note about Ruby on Rails: in order to run a Ruby on Rails script from command line (cron) you must have the path of the script runner (command line ruby compiler ??) in the cron job line. It is located in your RoR app under script/runner - if you want more than one script to run at different times then add a line for each script just like we did in the previous example.
- when you are done adding them, press the escape [ESC] key to exit out of “insertion mode”, then type
:x[enter] to write and save your crontab. - make sure your crontab is active by typing crontab -l to list it’s contents and you should see the new file you just saved
Importing multiple pages into PDFLib
So, as I’ve stated before, I’m creating an application that imports a large PDF into PDFlib so that i can populate textfields on each page from a database table.
PDFlib essentially imports one page at a time to work with. So here’s code to import a multipage PDF and populate the fields for each page.
def populate_pdf
#setup some defaults
infile = "alaska_pdflib.pdf"
searchpath = "../state_doc_originals"
#this data should pull from a database, the keys of the hash must be the same as the block names on the pdf
data = {
"last_name" => "Constant",
"first_name" => "Nate",
"middle_name" => "Andrew",
"dob_m" => "09",
"dob_y"=>"1980",
"dob_d" => "18",
"city_of_birth" => "Omaha",
"state_of_birth" => "Nebraska",
"gender_male" => "8"
}
p = PDFlib.new
if (p.begin_document("", "compatibility = 1.6") == -1)
logger.info "Error: " + p.get_errmsg()
end
# Set the search path for fonts and PDF files
p.set_parameter("SearchPath", searchpath)
p.set_parameter("pdiwarning", "true")
p.set_info("Creator", "businesscard.rb")
p.set_info("Author", "QuickDocData")
p.set_info("Title", "Alaska State License Application")
#open the document
blockcontainer = p.open_pdi(infile, "", 0)
if (blockcontainer == -1)
logger.info "Error: " + p.get_errmsg()
end
regularfont = p.load_font("Arial", "winansi", "")
checkbox_font = p.load_font("ZapfDingbats","builtin","")
#loop through all pages and put data in the blocks
number_of_pages = p.get_pdi_value("/Root/Pages/Count",blockcontainer,-1,0)
1.upto(number_of_pages){|page_num|
#get current page
page = p.open_pdi_page(blockcontainer, page_num, "")
if (page == -1)
logger.info "Error: " + p.get_errmsg()
end
#get all blocks for the page and put them in an array to use later
num_of_blocks_on_page = p.get_pdi_value("vdp/blockcount",blockcontainer,page,0)
cur_blocks = Array.new
0.upto(num_of_blocks_on_page-1){ |i|
cur_blocks.push( p.get_pdi_parameter("vdp/Blocks[#{i}]/Name", blockcontainer, page, 0))
#logger.info p.get_pdi_parameter("vdp/Blocks[#{i}]/Name", blockcontainer, page, 0)
}
#set page size
p.begin_page_ext(595, 842, "topdown")
# This will adjust the page size to the block container's size.
p.fit_pdi_page(page, 0, 842, "")
# Fill all text blocks with dynamic data
cur_blocks.each { |key, value|
use_font = p.get_pdi_parameter("vdp/Blocks/#{key}/fontname", blockcontainer, page, 0)
if use_font == "ZapfDingbats"#is this block a checkbox?
font_string = "font #{checkbox_font.to_s} embedding encoding=builtin"
else
font_string ="font #{regularfont.to_s} embedding encoding=winansi"
end
if (p.fill_textblock(page, key, data[key].to_s,font_string) == -1)
logger.info "Warning: " + p.get_errmsg
end
}
p.end_page_ext("")
p.close_pdi_page(page)
}#end looping through all of the pages
p.close_pdi(blockcontainer)
p.end_document("")
p.get_buffer()
end
Recently
- 08.24 Setting up flash messages in Zend Framework
- 09.08 CakePHP default dateTime()
- 03.24 Extending CakePHP’s beforeFilter()
- 03.17 Rails-like Flash messages in CakePHP
- 03.08 CakePHP thumbnails with phpThumb
- 02.15 CakePHP model validation
- 02.10 CakePHP - saving dates in your model
- 09.19 Importing multiple pdf pages and documents into PDFlib - Part 2
- 09.18 Quick Link - Every CSS based layout you could want
- 09.04 Mongrel pid error fixed