Jun 06
Now the RailsConf aftermath has calmed down, I wanted to let you know a little about a tool we announced at the conference that I’ve been working on for a while. We’ve bundled up an Engine Yard gentoo slice from our clusters and put it into a VMWare image.
All the information you’ll need is on that page and there’s more to come.
Jun 02
So the end of the conference has come, and I’m absolutely exhausted. In their wisdom O’Reilly only filmed the keynote this year, so I’ve uploaded my slides with some added notes (so you can get a better idea of what I said) if you missed the talk or were one of the 30+ that got kicked out due to the room being full. I’ll put more up later.
Here’s the presentation:
Oh, and if you liked my talk, feel free to recommend me on Working With Rails:
My Profile on Working With Rails
May 03
Let’s pretend that you’re busy making a kick ass template maker, and you’d like to keep backups of the file you generate. You certainly don’t want to write over it every time, in case there’s customer changes that have been made since the last time you did. What if you want to keep 5 copies of it, and only 5?
Rather than code it all yourself, save yourself some trouble and download the Backup gem off github, and you’re ready to go:
Install
$ sudo gem sources -a http://gems.github.com
$ sudo gem install engineyard-backup
You only need to install the source once and then you can install any gem hosted on github, which basically means any repository that has a .gemspec at the root of their repository.
Usage
backup = Backup.new("/the/file/to/backup")
backup.run
So what exactly have we done here? Well, we’ve made a copy of the file we wanted backed up, and we’ve added a timestamp to it. Every time we run this file, Backup will move the current file to a timestamped version, and also ensure that (by default) 5 versions of that file are kept.
Want a different number of ‘releases’?
# Set a different amount of backups on initialize
backup = Backup.new("/the/file/to/backup", 10)
# or set it manually
backup.backups = 15
# Run the backup
backup.run
Some more methods:
backup = Backup.new("/the/file/to/backup")
# which files would we keep in a backup
backup.keep_list
# => ["backup.20080430185243", "backup.20080430185246", "backup.20080430185243", "backup.20080430185250", "backup.20080430185254"]
# which files would we delete in a backup
backup.delete_list
# => ["backup.20080430185221", "backup.20080430185224", "backup.20080430185230"]
# how about skipping the cleanup?
backup.run( :no_delete )
# what if we just want to cleanup the old revisions
backup.cleanup
# and finally, how about we just get a list of the backup files present
backup.find_all_releases
Notes
This library doesn’t care where it’s being used, it could be a Rails application or a command line Ruby script of some sort. It merely handles backups of files in the form of a library. If you just want to backup some files and not programmatically from within your own application, then these are not the droids you are looking for.
Conclusion
Easy peasy, lemon squeezy backups. Enjoy.
Mar 19
So, it turns out both Eric Cartman and Arnold Schwarzenegger like Ruby! Who’d have known!
Eric Cartman
Arnold Schwarzenegger
There’s rumoured to be Borat, Ali G and possibly Bruce Forsyth coming too, in an extended version of the question!
Dec 28
Just in case any of you wonder why when you use REXML’s write method on ruby 1.8.6 (2007-09-24 patchlevel 111) [universal-darwin9.0] and possibly other versions, you get errors, it’s a bug in Apple’s REXML library. See this:
def write(writer=$stdout, indent=-1, transitive=false, ie_hack=false)
Kernel.warn("#{self.class.name}.write is deprecated. See REXML::Formatters")
formatter = if indent > -1
if transitive
REXML::Formatters::Transitive.new( indent, ie_hack )
else
REXML::Formatters::Pretty.new( indent, ie_hack )
end
else
REXML::Formatters::Default.new( ie_hack )
end
formatter.write( self, output )
end
As you can see, the method sets a local variable of ‘writer’ in the method arguments, however at the bottom it uses ‘output’. A simple change of the bottom line fixes it:
formatter.write( self, writer )
For those who requested it, here’s how to use the formatter:
# I want to create a REXML document to output
require "rexml/document"
# Make a pretty formatter
formatter = REXML::Formatters::Pretty.new( 2 )
# Create some silly xml example
xml = REXML::Document.new '<moo>RAR!</moo>'
# Write to STDOUT
formatter.write( xml, $stdout )
# Write to file
xml_file = File.open( "some_file.xml", "a+" )
formatter.write( xml, xml_file )
Recent Comments