Acts_as_versioned Rails Plugin
Versioning models with the acts_as_versioned plugin
cd rails/app ./script/plugin install git://github.com/technoweenie/acts_as_versioned.git ./script/generate model post title:string body:text
In your model
class Post < ActiveRecord::Base acts_as_versioned end
In db/migrate/****_create_posts.rb
def self.up
create_table :posts do |t|
t.string :title
t.text :body
t.timestamps
end
Post.create_versioned_table
end
def self.down
drop_table :posts
Post.drop_versioned_table
end
Migrate your db
rake db:migrate
Usage
p = Post.create :body => "hello world" p.body = "HELLO WORLD" p.save p.versions.size p.versions.last p.revert_to(p.versions.first) p.body # => hello world
*Quick Note If you want to revert to an older version in a controller or something, don't do
@post = @post.revert_to(2)
Revert_to method will return a TrueClass, Boolean type. Instead use
@post.revert_to(2)
This method will update the attributes for you and when you call them you'll get that version.
More information is available here http://ar-versioned.rubyforge.org/ and http://www.urbanhonking.com/ideasfordozens/archives/2006/02/learns_to_use_a_1.html
Install MySQLdb for Python on Mac OS X
I don’t do much python development. I really like the language and there are a lot of great software projects out there for it. Tornado, for example, is a fast non-blocking web server in python, just open sourced by Facebook that is the engine behind FriendFeed.com.
I downloaded the source, available at, http://tornadoweb.org, and started playing around. It comes with a database wrapper for mysql. Using “easy_install”, I suppose the python equivalent to gems, it goes something like this…
sudo easy_install MySQLdb-python
Nope
at least not on OS X. Time to do it the hard way. Luckily not too hard. It just can’t find the right path to mysql_config. Sound familiar? http://seanbehan.com/databases/install-do_mysql-ruby-gem-on-mac-os-x/
Anyway, here are the commands that worked for me…
wget http://dl.sourceforge.net/sourceforge/mysql-python/MySQL-python-1.2.3c1.tar.gz tar xzvf MySQL-python-1.2.3c1.tar.gz cd MySQL-python-1.2.3c1
In the setup_posix.py file change
mysql_config.path = "mysql_config"
to
mysql_config.path = "/opt/local/lib/mysql5/bin/mysql_config"
Next install it with these commands
python setup.py clean python setup.py build sudo python setup.py install
That should do it.
Regular Expression for finding absolute URLs
Regular Expression for finding absolute URLs in a bunch of text… like a log file.
/(http:(.*?)\s)/
Non Standard Port Number with SSH and Git
Here is an example using the port 4567 to connect with over ssh and git
ssh remote add origin ssh://sean@seanbehan.com:4567/path/to/git git push origin master