Skip to content

Instantly share code, notes, and snippets.

asf asfd
afs
d a
sf
asdf
asdf
@nevir
nevir / memoization.py
Created February 3, 2011 00:37
Memoizers for functions and methods!
import functools
def memoized(func):
"""
Decorator that caches the result of this INSTANCE METHOD call. Does not work for unbound methods.
Caches data in the attribute __memoized_cache__
>>> class Foo(object):
... @memoized
@nevir
nevir / gist:952528
Created May 2, 2011 22:53
DataMapper join tables
require 'rubygems'
require 'dm-core'
require 'dm-migrations'
require 'dm-mysql-adapter'
require 'ffaker'
require 'benchmark'
logger = DataMapper::Logger.new(STDOUT, :debug)
DataMapper.setup(:default, 'mysql://dm:dm@localhost/dm_join_tables')
@nevir
nevir / validated_json.rb
Created May 19, 2011 19:19
DataMapper::Property::ValidatedJson
require 'dm-types'
require 'dm-validations'
module DataMapper
module Validations
class DeferredJsonValidator < GenericValidator
def initialize(field_name, pending_error_ivar_name, options={})
super(field_name, options)
@nevir
nevir / gist:1055219
Created June 29, 2011 22:58
rubinius compile error
Building openssl
/Users/ian/Coding/OpenSource/rubinius/bin/rbx-build extconf.rb
An exception occurred running extconf.rb
Error trying to compile /Users/ian/Coding/OpenSource/rubinius/lib/mkmf.rb (Rubinius::CompileError)
Backtrace:
Rubinius::Compiler.compiler_error at /Users/ian/Coding/OpenSource/rubinius
/runtime/19/compiler/compiler.rbc:11
Rubinius::Compiler.compile at /Users/ian/Coding/OpenSource/rubinius
/runtime/19/compiler/compiler.rbc:63
ruby-1.9.2-p180 :001 > Array(1)
=> [1]
ruby-1.9.2-p180 :002 > Array([1,2,3])
=> [1, 2, 3]
ruby-1.9.2-p180 :003 > Array.new
=> []
Ian: 2 beef tacos, 2 pork tacos, 1 POG
Erik: 2 beef tacos, 1 pork taco, 1 pork slider, 2 spam slider, 1 hawaiian punch
Total:
4 beef tacos
3 pork tacos
1 pork slider
2 spam slider
1 POG
1 hawaiian punch
ruby-1.9.2-p180 :001 > class Foo
ruby-1.9.2-p180 :002?> def  (*args)
ruby-1.9.2-p180 :003?> args
ruby-1.9.2-p180 :004?> end
ruby-1.9.2-p180 :005?> end
=> nil
ruby-1.9.2-p180 :006 > Foo.new. 
=> []
ruby-1.9.2-p180 :007 > Foo.new.  'stuff', other: 'stuff'
=> ["stuff", {:other=>"stuff"}]
NevBook:rubinius ian$ cat deep.rb
def deep
deep
end
deep
NevBook:rubinius ian$ bin/rbx deep.rb
An exception occurred running deep.rb
activesupport (3.1.0.rc4) lib/active_support/whiny_nil.rb:48:in method_missing'
cancan (1.6.5) lib/cancan/controller_resource.rb:116:inmember_action?'
cancan (1.6.5) lib/cancan/controller_resource.rb:73:in load_instance?'
cancan (1.6.5) lib/cancan/controller_resource.rb:31:inload_resource'
cancan (1.6.5) lib/cancan/controller_resource.rb:10:in block in add_before_filter'
activesupport (3.1.0.rc4) lib/active_support/callbacks.rb:448:in_run2228024897145879193process_action166216410147247412callbacks'
activesupport (3.1.0.rc4) lib/active_support/callbacks.rb:386:in _run_process_action_callbacks'
activesupport (3.1.0.rc4) lib/active_support/callbacks.rb:81:inrun_callbacks'
actionpack (3.1.0.rc4) lib/abstract_controller/callbacks.rb:17:in process_action'
actionpack (3.1.0.rc4) lib/action_controller/metal/instrumentation.rb:30:inblock in process_action'