Skip to content

Instantly share code, notes, and snippets.

View splattael's full-sized avatar
🏠
Working from home

Peter Leitzen splattael

🏠
Working from home
View GitHub Profile
#!/bin/sh
# usage: $0 < hosts.txt
# line = ip name
while read line
do
ip=$(echo $line | cut -f 1 -d ' ')
hostname=$(echo $line | cut -f 2 -d ' ')
echo "host: $hostname ($ip)"
# http://stefankst.net/2007/06/05/capture-standard-output-in-ruby/
def capture_stdout
old_stdout = $stdout
out = StringIO.new
$stdout = out
begin
yield
ensure
$stdout = old_stdout
end
require 'rubygems'
require 'ftools'
require 'rbench'
TMP_DIR = "/tmp"
FACTORS = {
2 => 10 .. 20, # - 1048576 bytes
3 => 8 .. 13, # - 1594323 bytes
5 => 5 .. 9, # - 1953125 bytes
# http://gist.github.com/49013
#
# assert_errors_on record, :email
# assert_errors_on record, :email => 2
# assert_errors_on record, :email => "is blank"
# assert_errors_on record, :email => ["is blank", "is invalid"]
# assert_errors_on record, :email, :plz => 2
# assert_errors_on record, [:username, :email] => "is blank"
def assert_errors_on(object, *attributes_or_hash)
assert !object.valid?, "#{object.inspect} should be invalid."
# /usr/share/dict/ogerman
PI - AN 157 # pianist
PI - AN 0 # piano
PI - AN 0 # piano
PI - CA 550 # picasso
PI - CK 7 # pickt
PI - LL 3 # pille
PI - LO 7 # pilot
PI - L 5 # pils
PI - L 2 # pilz
Class.instance_methods(:include_super.false)
# => ["to_yaml", "allocate", "superclass", "new"]
Class.instance_methods(:include_super.true)
# => => ["inspect", "pretty_print_instance_variables", "private_class_method", "const_missing", ...
def with_rails_env(new_value)
old = Object.send(:remove_const, 'RAILS_ENV')
Object.const_set('RAILS_ENV', new_value)
yield
ensure
Object.send(:remove_const, 'RAILS_ENV')
Object.const_set('RAILS_ENV', old)
end
memcache-client-1.7$ ruby test/test_benchmark.rb
Loaded suite test/test_benchmark
Started
Testing 1.7.1
user system total real
set:plain:memcache-client 3.350000 0.310000 3.660000 ( 3.749737)
set:ruby:memcache-client 3.500000 0.280000 3.780000 ( 3.881471)
get:plain:memcache-client 5.120000 0.430000 5.550000 ( 5.811311)
get:ruby:memcache-client 5.200000 0.330000 5.530000 ( 5.721424)
multiget:ruby:memcache-client 2.510000 0.130000 2.640000 ( 2.732127)
navigation :hide => true do |nav|
nav.start
nav.home do |home|
home.connect :user
home.user # user_path
home.user "/user"
#!/usr/bin/env ruby
ALPHA_TO_MORSE = DATA.readlines.map do |line|
alpha, *morse = line.split(' ')
end.inject({}) do |hash, (key, *values)|
hash[key] = values.join
hash
end
ALPHA_TO_MORSE[" "] = "/"