Skip to content

Instantly share code, notes, and snippets.

this is SO weird

#! /usr/bin/env ruby
puts "closing firefox ..."
`killall firefox`
require 'rubygems'
require 'activerecord'
ActiveRecord::Base.establish_connection :adapter => 'sqlite3',
:database => '/home/remi/.mozilla/firefox/efs72yik.default/places.sqlite'
# different possible syntaxes for generating models
Factory(:user, :foo => 'bar', :chunky => 'bacon')
Factory.build(:user, :foo => 'bar', :chunky => 'bacon')
User.generate :foo => 'bar', :chunky => 'bacon'
User.build :foo => 'bar', :chunky => 'bacon'
User.gen :foo => 'bar', :chunky => 'bacon'
User.make :foo => 'bar', :chunky => 'bacon'
#! /usr/bin/env ruby
require 'rubygems'
require 'activerecord'
ActiveRecord::Base.establish_connection :adapter => 'sqlite3', :database => ':memory:'
class CreateStuff < ActiveRecord::Migration
def self.up
create_table( :breeds ){|t| t.string :name }
create_table( :dogs ){|t| t.string :name; t.integer :breed_id }
# randomly generate 0 or 1 ... you should get 1 about 10% of the time, 0 about 90% of the time
$ irb
>> rand
=> 0.534835738078545
>> rand
=> 0.334280092272696
>> rand * 10
=> 2.22911939494193
>> ( rand * 10 ).to_i
=> 0
# $ irb
>> require 'rack'
=> true
# to create and run a basic Rack application
>> Rack::Handler::Thin.run lambda {|e| [200, {}, ["Hello World!"]] }
Thin web server (v1.2.1 codename Asynctilicious Ultra Supreme)

Rack::OpenID example

This config.ru Rackup file is an example of a simple Rack application using Rack::OpenID

#! /usr/bin/env ruby
class Foo
DEFAULT_VAR = 'I am the default'
class << self
attr_accessor :var
end
def self.var
@beccasaurus
beccasaurus / README.markdown
Created September 19, 2009 22:24
How to easily do transactional specs using DataMapper

How to easily do transactional specs using DataMapper