Skip to content

Instantly share code, notes, and snippets.

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|
; 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))))
source "http://rubygems.org"
gem "sinatra"
gem "thin"
# 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() {
@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
require "rubygems"
require "sinatra"
require "oauth"
require "oauth/consumer"
enable :sessions
set :root, File.dirname(__FILE__)
TOKEN = 'Tmy-token'
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 'net/http'
require 'json'
module GetResponse
class Connection
API_URI = "http://api2.getresponse.com"
attr_reader :api_key
module MongoMapper
module FindRandom
def self.included(document)
document.extend ClassMethods
end
module ClassMethods
# Fetch random document from MongoDb
def find_random(conditions = {})
# WTF?!
email_regexp_1 = /^[\w\.-_]+@[a-zA-Z0-9\.]+\.([a-zA-Z]{2}|com|org|net|gov|mil|biz|info|mobi|name|aero|jobs|museum)$/x
email_regexp = /^ # początek dopasowania
[\w\.-_]+ # nazwa użytkownika: znaki alfanumeryczne, kropa, myślnik, podkreślenie
@ # 'at' - małpa
[a-zA-Z0-9\.]+ # domena np. gmail poczta.wp: znaki alfanumeryczne, kropka
\. # ostatnia kropa
([a-zA-Z]{2} # dwuliterowa top-level domain dla kraju np pl, us, de, be, ru
|com|org|net|gov|mil|biz|info|mobi|name|aero|jobs|museum) # dopuszczone top-level domain