This file contains 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 MongoMapper | |
module FindRandom | |
def self.included(document) | |
document.extend ClassMethods | |
end | |
module ClassMethods | |
# Fetch random document from MongoDb | |
def find_random(conditions = {}) |
This file contains 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 'net/http' | |
require 'json' | |
module GetResponse | |
class Connection | |
API_URI = "http://api2.getresponse.com" | |
attr_reader :api_key |
This file contains 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
load 'deploy' if respond_to?(:namespace) # cap2 differentiator | |
Dir['vendor/plugins/*/recipes/*.rb'].each { |plugin| load(plugin) } | |
load 'config/deploy' # remove this line to skip loading any of the default tasks | |
namespace :bundler do | |
task :create_symlink, :roles => :app do | |
shared_dir = File.join(shared_path, 'bundle') | |
release_dir = File.join(release_path, '.bundle') | |
run("mkdir -p #{shared_dir} && ln -s #{shared_dir} #{release_dir}") |
This file contains 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 "oauth" | |
require "oauth/consumer" | |
enable :sessions | |
set :root, File.dirname(__FILE__) | |
TOKEN = 'Tmy-token' |
This file contains 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
# Ruby | |
def exception_return_puzzle? | |
begin | |
return true | |
ensure | |
return false | |
end | |
end | |
# Java |
This file contains 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
# My .zlogin file | |
git_prompt_info() { | |
ref=$(git symbolic-ref HEAD 2> /dev/null) | |
if [[ -n $ref ]]; then | |
echo "[%{$fg_bold[green]%}${ref#refs/heads/}%{$reset_color%}]" | |
fi | |
} | |
rvm_prompt_info() { |
This file contains 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
source "http://rubygems.org" | |
gem "sinatra" | |
gem "thin" |
This file contains 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
; What is the proper answer for this koan? | |
(defn multiply-by-ten [n] | |
(* 10 n)) | |
(defn square [n] (* n n)) | |
(meditations | |
"Higher-order functions take function arguments" | |
(= 25 (___ | |
(fn [n] (* n n)))) |
This file contains 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 'benchmark' | |
Benchmark.bm(7) do |x| | |
x.report("length") { 10.times { Array.new(10_000, 1).length > 0 } } | |
x.report("any?") { 10.times { Array.new(10_000, 1).any? } } | |
end | |
array = Array.new(10_000, 1) | |
Benchmark.bm(7) do |x| |
This file contains 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 'active_support' | |
require 'active_support/core_ext/hash/indifferent_access' | |
require 'benchmark' | |
ALPHA = ('a'..'z').to_a | |
simple_hash = ALPHA.inject({}) { |hash, element| hash[element] = element ; hash } | |
indifferent_hash = ALPHA.inject(HashWithIndifferentAccess.new) { |hash, element| hash[element] = element ; hash } | |
Benchmark.bm do |x| |