Skip to content

Instantly share code, notes, and snippets.

View erik-megarad's full-sized avatar

Erik Peterson erik-megarad

View GitHub Profile
module EnumThing
def categories
@categories ||= connection.execute("SELECT category FROM #{table_name} GROUP BY category").collect{|r|r[0]}
end
include InstanceMethods
module InstanceMethod
def categories
self.class.categories
end
# FUCK NO
class Person
include Mongoid::Document
field :athing, :type => String, :default => "Something"
validates_format_of :athing, :with => /[A-Za-z]/
end
# HELL YES
class Person
# HELL NO
defaults: &defaults
adapter: mongo
host: localhost
development:
<<: *defaults
database: fanboy_dev
production:
# Can I get a "HELL YEAH?"
Mongoid.environments do
environment :development do
adapter :mongo
host :localhost
database :fanboy_dev
end
environment :production do
adapter :mongo
# Can I get a "FUCK YEAH?"
Mongoid.environments do
@defaults = {:adapter => :mongo, :host => :localhost}
environment :development do
self.settings.merge!(@defaults)
database :fanboy_dev
end
environment :production do
@erik-megarad
erik-megarad / aes_crypt.rb
Created December 4, 2010 20:24
AES Encryption for Ruby 1.9
require 'openssl'
module AESCrypt
# Decrypts a block of data (encrypted_data) given an encryption key
# and an initialization vector (iv). Keys, iv's, and the data
# returned are all binary strings. Cipher_type should be
# "AES-256-CBC", "AES-256-ECB", or any of the cipher types
# supported by OpenSSL. Pass nil for the iv if the encryption type
# doesn't use iv's (like ECB).
#:return: => String
module DataMapper
module Adapters
class RedisAdapter < AbstractAdapter
def find_matches(query, operand)
@redis.smembers("#{query.model.to_s.downcase}:#{operand.subject.name}:#{encode(operand.value)}").collect{|k| k.gsub(/\[|\]/, "")}
end
end
end
end
ssssoooosmMMNmmhdhhys+/+oosyyyyyyyssssssssssssoooooooooooooooo+++++++++++++++++++++++++++++/////////
ssssooooomMNmddddhdhhyo+++oossssyyssssssssssssoooooooooooooooo+++++++++++++++++++++++++++++/////////
ssssooooomMNmmmmhysyhhhyso+oooooossssssssssssoooooooooooooo+o++++++++++++++++++++++++++++++/////////
ssssooooodMMNmddhdddhhyyysssoooo++ossssssssssoooooooooooooooo++++++++++++++++++++++++++++///////////
sssoooooohMMNNmmmdhysshyyhysyso+oo+oyssssssssssosssooooooooo+o+++++++++++++++++++++++++/////////////
sssooooosyMMMNddysssssyysyyhydhyosssyyyyyhhhyyhyyhyhsssosoooooo++++++++++++++++++++++++++++ooossssso
sssoooosssNMMMMNmdhhyyysyhdmNdmmhssyyyyyhhhhhdhhhhyyyssysssysssooooo++++++++oooooossssyhddmdhhyssooo
ssssosossyNMMMMMNdyyhhhdmNMMMMmNmhssddhyhhhdhhhhhhyyyoosyyysyyyyyyyssssssyhdmmmmNNNNmmdhyysooosssso+
yyyssssssyNMMMMNmmdmmNNNMMMMMMMmNmdhmmdhhhyhyyhhdhyhs++ssyyssyyyhddhmmddmmNNNMNNNdhhsssssyyyyyssooo+
yyyyyysyyhMMMMMMMNNNNNMMMMMMMMMNdmNNNmdhdhyhyhhdhdyhys+osysssssyhdmmmmdmNmmdddhhhhhhyhyyyhhyyysooso+
/Users/epeterson/.rvm/rubies/ruby-1.9.2-p290/bin/ruby vm/codegen/field_extract.rb vm/builtin/basicobject.hpp vm/builtin/object.hpp vm/builtin/integer.hpp vm/builtin/fixnum.hpp vm/builtin/array.hpp vm/builtin/bignum.hpp vm/builtin/executable.hpp vm/builtin/access_variable.hpp vm/builtin/alias.hpp vm/builtin/block_environment.hpp vm/builtin/block_as_method.hpp vm/builtin/bytearray.hpp vm/builtin/chararray.hpp vm/builtin/io.hpp vm/builtin/channel.hpp vm/builtin/module.hpp vm/builtin/class.hpp vm/builtin/compiledmethod.hpp vm/builtin/data.hpp vm/builtin/dir.hpp vm/builtin/exception.hpp vm/builtin/float.hpp vm/builtin/immediates.hpp vm/builtin/iseq.hpp vm/builtin/list.hpp vm/builtin/lookuptable.hpp vm/builtin/ffi_pointer.hpp vm/builtin/methodtable.hpp vm/builtin/nativefunction.hpp vm/builtin/packed_object.hpp vm/builtin/randomizer.hpp vm/builtin/regexp.hpp vm/builtin/staticscope.hpp vm/builtin/string.hpp vm/builtin/symbol.hpp vm/builtin/thread.hpp vm/builtin/tuple.hpp vm/builtin/compactlookuptable.hpp vm/builtin/t
epeterson@ep:~/Sites/rubinius locks ✔ ⇧ $ bin/mspec ci -T -X19 spec/ruby/core/array/rotate_spec.rb
rubinius 2.0.0dev (1.9.2 f145b1bb yyyy-mm-dd JI) [x86_64-apple-darwin10.8.0]
EEEEEEEEF
1)
Array#rotate returns a copy of the array whose first n elements is moved to the last ERROR
NoMethodError: undefined method `rotate' on an instance of Array.
Kernel(Array)#rotate (method_missing) at kernel/delta/kernel.rb:79
{ } in Object#__script__ at spec/ruby/core/array/rotate_spec.rb:8
BasicObject(Object)#instance_eval at kernel/common/eval19.rb:43