Skip to content

Instantly share code, notes, and snippets.

View pathsny's full-sized avatar

Vishnu Iyengar pathsny

View GitHub Profile
# A sample Gemfile
source "http://rubygems.org"
source 'http://gems.rubyforge.org/'
gem "dm-core"
gem "dm-validations"
gem "dm-migrations"
gem "dm-transactions"
gem "dm-sqlite-adapter"
gem "dm-aggregates"
fs.open(path, "a", 0666, function (error, file) {
fs.write(file, "worker 10 starting at" + time, null, "utf-8", function () {
forEachoftheFirstOneMillionHitsOnGoogleFor(word, function(url) {
getHtmlSource(url, function(html) {
foo(bar(html))
})
})
})
})
a = lambda { puts "hello #{name}"}
class Foo
def name
"manson"
end
end
Foo.new.instance_eval(&a) #hello manson
source 'http://gems.github.com'
source 'http://gems.rubyforge.org/'
gem "bunny"
gem "activesupport"
gem "actionmailer"
gem "DanaDanger-syslog_logger", :require => "syslog_logger"
gem "dm-core"
gem "dm-validations"
var fs = require('fs');
var sys = require("sys");
var files = ['data1', 'data2', 'data3'];
var data = {}
var AllDone = function() { return files.every(function(file) {return data[file] })}
var Biggest = function() { return files.reduce(function(big, file) {
return big.length > data[file].length ? big : data[file]
}, "")
require 'rubygems'
require 'dm-core'
require 'dm-migrations'
require 'dm-validations'
class Human
include DataMapper::Resource
property :id, Serial
validates_with_block :foo do
class Pet
include DataMapper::Resource
belongs_to :owner, Human
property :id Serial
property :status, String, :set => ['asleep', 'awake']
validators.contexts[:without_assocs] = validators.contexts[:default].reject{|v| v.field_name == :owner_id}
end
def step(name, *lambdas)
s = lambdas.reverse.inject(lambda{|p| p.call}) do |acc, l|
func = lambda { |*args| acc.call(*args) }
create_parallel_method(func)
a = Struct.new(name).new(func)
lambda { |*args| a.instance_exec(*args, &l)}
end
s.call
end
class Foo
include DataMapper::Resource
has 1, :bar
property :id, Serial
property :name, String
end
class Bar
require 'rubygems'
require 'dm-core'
require 'dm-migrations'
require 'dm-validations'
class Pet
include DataMapper::Resource
belongs_to :human