Skip to content

Instantly share code, notes, and snippets.

module MongoMapper
module FindRandom
def self.included(document)
document.extend ClassMethods
end
module ClassMethods
# Fetch random document from MongoDb
def find_random(conditions = {})
require 'rubygems'
require 'net/http'
require 'json'
module GetResponse
class Connection
API_URI = "http://api2.getresponse.com"
attr_reader :api_key
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}")
require "rubygems"
require "sinatra"
require "oauth"
require "oauth/consumer"
enable :sessions
set :root, File.dirname(__FILE__)
TOKEN = 'Tmy-token'
@seban
seban / gist:800061
Created January 28, 2011 10:04
Mala zagadka programistyczna #1
# Ruby
def exception_return_puzzle?
begin
return true
ensure
return false
end
end
# Java
# 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() {
source "http://rubygems.org"
gem "sinatra"
gem "thin"
; 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))))
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|
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|