This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(define (make-interval a b) (cons a b)) | |
(define (lower-bound int) (car int)) | |
(define (upper-bound int) (cdr int)) | |
(define (add-interval x y) | |
(make-interval (+ (lower-bound x) (lower-bound y)) | |
(+ (upper-bound x) (upper-bound y)))) | |
(define (sub-interval x y) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
require 'rubygems' | |
require 'sinatra' | |
require 'builder' | |
get '/hi' do | |
builder do |html| | |
html.h1 "Frist Post" | |
html.form("action" => "boo", "method" => "post") do | |
html.input("type" => "submit", "id" => "submit") | |
end |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
require "rubygems" | |
require "webrat" | |
Webrat.configure do |config| | |
config.mode = :mechanize | |
end | |
class Webrat::Session | |
def_delegators :@adapter, :response_headers | |
def response_location |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class Payment | |
include DataMapper::Resource | |
belongs_to :payee, User | |
belongs_to :payer, User | |
property :id, Serial | |
# ... | |
end |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class Payment | |
include DataMapper::Resource | |
property :id, Serial | |
belongs_to :payee, 'User' | |
belongs_to :payer, 'User' | |
end | |
class User |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class Foo | |
include DataMapper::Resource | |
property :id, Serial | |
property :foo, Integer, :unique => true | |
property :desc, String | |
end | |
Foo.auto_migrate! |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
require 'rubygems' | |
require 'dm-core' | |
class Foo | |
include DataMapper::Resource | |
property :id, Serial | |
property :foo, Integer | |
property :bar, String |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
module DataMapper | |
module Resource | |
def transactional_save | |
transaction do |t| | |
returning save do |s| | |
t.rollback unless s | |
end | |
end | |
end | |
end |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function loadTemplates(fn){ | |
var templates - ['action', 'error', 'torrent', 'no_torrents', 'speed']; | |
templates.reduce(function(acc_fn, template){ | |
return function() { | |
$.get('templates/' + template + '.html.template', | |
function(data){ | |
$templates[template] = $.jqotec(data); | |
acc_fn(); | |
} | |
) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class Foo | |
include DataMapper::Resource | |
property :id, Serial | |
property :external_id, UUID | |
end | |
Foo.auto_migrate! | |
f = Foo.create | |
f.external_id = UUIDTools::UUID.random_create | |
f.save |