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 NameIdCache | |
def self.included(base) | |
m = Module.new | |
base.all.each do |record| | |
cache_key = NameIdCache.cache_key(base, record) | |
Rails.cache.write(cache_key, record.id) | |
m.__send__(:define_method, record.name) do | |
Rails.cache.fetch(cache_key) do |
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 NameIdCache | |
def self.included(base) | |
m = Module.new | |
base.all.each do |record| | |
m.__send__(:define_method, record.name) do | |
record.record_id # using #record_id because OpenStruct is iffy about #id | |
end | |
end | |
base.extend(m) | |
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
# Explanation at http://stackoverflow.com/questions/5212213/ruby-equivalent-of-php-openssl-seal/9428217#9428217 | |
# Implementation | |
class EnvelopeEncryption | |
require "openssl" | |
# This method takes in plaintext and produces ciphertext and an |
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
$ cat Gemfile | |
source 'http://rubygems.org' | |
gem "rails", ">=3.0.5" | |
# To use debugger | |
# gem 'ruby-debug' | |
gem "guid" | |
gem "mysql2" |
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
diff -ur marcbowes-UsingYAML-590c028/lib/using_yaml/array.rb UsingYAML-590c028/lib/using_yaml/array.rb | |
--- marcbowes-UsingYAML-590c028/lib/using_yaml/array.rb 2010-03-06 22:14:19.000000000 +0200 | |
+++ UsingYAML-590c028/lib/using_yaml/array.rb 2010-03-29 18:05:01.000000000 +0200 | |
@@ -25,5 +25,6 @@ | |
# Load in the extensions for this instance | |
array.extend(extensions) | |
+ array | |
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
# This is a cheap stab at demonstrating the behavior of | |
# Inotify::CREATE. That is, CREATE will trigger inotify events | |
# immediately upon file creation. | |
require 'inotify' | |
require 'fileutils' | |
# Method which fakes a slow write by sleeping for one second. | |
def slow_write(filename) | |
File.open(filename, "w") do |f| |
NewerOlder