Skip to content

Instantly share code, notes, and snippets.

View Whoops's full-sized avatar

Walton Hoops Whoops

View GitHub Profile
require 'sqlite3'
require 'active_record'
db = SQLite3::Database.new ('demo.db')
db.execute('DROP TABLE IF EXISTS demos')
db.execute('CREATE TABLE demos ( id TEXT PRIMARY KEY, data TEXT)')
ActiveRecord::Base.logger = Logger.new(File.open('database.log', 'a'))
ActiveRecord::Base.establish_connection( :adapter => 'sqlite3',
:database => 'demo.db')
db.close
"It's your own choosing," said the man with the withered arm once more.
I heard the faint sound of a stick and a shambling step on the flags in
the passage outside. The door creaked on its hinges as a second old man
entered, more bent, more wrinkled, more aged even than the first. He
supported himself by the help of a crutch, his eyes were covered by
a shade, and his lower lip, half averted, hung pale and pink from his
decaying yellow teeth. He made straight for an armchair on the opposite
side of the table, sat down clumsily, and began to cough. The man with
the withered hand gave the newcomer a short glance of positive dislike;
require 'pp'
a=[1,[2,[3]],4,5,[6,7,[8,9]]]
pp a.inject([]){|b,x| if Array===x then x.each {|y| b << y } else b << x end;b;}
require 'net/ssh'
print "Enter host: "
host=gets.chomp
print "Enter username: "
user=gets.chomp
print "Enter password: "
password=gets.chomp
Net::SSH.start(host, user, :password => password) do |ssh|
foo='foo'
bar='bar'
class A
def self.call_block
foo="I've got a lovely bunch of coconuts"
bar='detitly doo'
#note, yield calls the block assigned to a function
yield foo, bar
end
require 'rubygems'
require 'sinatra/base'
require 'omniauth'
require 'openid/store/filesystem'
require 'sinatra/mongomatic'
require 'models.rb'
class Teste < Sinatra::Base
register Sinatra::Mongomatic
module Drive
def go
start_engine
plan_route
follow_route
end
def start_engine
#code here
end
room ('coconut room') do
description 'This room has a massive amount of coconuts'
door do
to 'banjo room'
on_open do
# some stuff
end
locked true
end
end
create table authors ( id INTEGER primary key, name TEXT not null);
create table posts ( id INTEGER primary key, author_id INTEGER not null, title text not null,
content text not null );
insert into authors (name) values ('some guy');
insert into authors (name) values ('another guy');
--cheat here, I know the first id will be 1
insert into posts(author_id, title, content)
values (1, 'My first article', 'introductory text here');
insert into posts(author_id, title, content)
values (1, 'My second article', 'itermediate text here');
@Whoops
Whoops / output
Created January 24, 2011 21:23
demonstrate inheritance and polymorphism
C:\Users\walton.hoops\Desktop>ruby vehicle.rb
Cruisin in my Car
Cruisin in my Truck
get a long little doggie!
Tow that gosh durn Car
C:\Users\walton.hoops\Desktop>