Skip to content

Instantly share code, notes, and snippets.

@teeparham
teeparham / bench_string_hash.rb
Created November 15, 2013 21:31
benchmark simple ruby string to int hashing
require 'benchmark'
strs = 1000.times.map{(0...32).map{(65 + rand(26)).chr}.join}
Benchmark.bm(6) do |x|
x.report('sum') { 100.times{strs.each &:sum} }
x.report('digest') { 100.times{strs.each{|s| Digest::MD5.hexdigest(s).to_i(16) }}}
end
# user system total real
@teeparham
teeparham / postgis_21_ext.sql
Last active December 25, 2015 07:28
Upgrade from Postgres 9.2 to 9.3 and PostGIS 2.0 to 2.1. OSX, homebrew
create extension postgis;
create extension postgis_topology;
alter extension postgis update to "2.1.0";
@teeparham
teeparham / hip_dizzle.sh
Last active December 18, 2015 04:39
command line aliases for dizzle & hipster
gem install ffaker
alias dizzle="ruby -e \"require 'ffaker'; puts Faker::DizzleIpsum.paragraph\" | tee >(pbcopy)"
alias hipster="ruby -e \"require 'ffaker'; puts Faker::HipsterIpsum.paragraph\" | tee >(pbcopy)"
###
$ dizzle
You talk too much like every single day Long Beach fo shizzle used to sell loot Coupe de Ville.
Real deal holyfield tha dizzle with my mind on my money fo shizzle. Real deal holyfield Mr. Buckwort
@teeparham
teeparham / email.text.haml
Last active December 17, 2015 23:09
haml plain text formatting with line breaks and unescaped text
:plain
#{title}
look - this preserves the whitespace above
also note that title is unescaped because of :plain
\
the "\" in the above line also adds a blank line
no blank line will be rendered above this one
@teeparham
teeparham / ffaker.rb
Created April 29, 2013 16:55
ffaker 1.16
require 'ffaker'
Faker::DizzleIpsum.sentence
=> "Every single one the diggy recognize it's 1993."
Faker::HipsterIpsum.sentence
=> "Irony sartorial fixie tofu."
Faker::LoremCN.sentence
=> "马到成功叮叮当当顷刻间数不胜数象牙白七窍生烟,"
@teeparham
teeparham / dev.log
Created March 6, 2013 08:05
rails 3.2.12 + ruby 2.0 + bare project + tracepoint
=> Booting WEBrick
=> Rails 3.2.12 application starting in development on http://0.0.0.0:3000
=> Call with -d to detach
=> Ctrl-C to shutdown server
[2013-03-06 01:02:27] INFO WEBrick 1.3.1
[2013-03-06 01:02:27] INFO ruby 2.0.0 (2013-02-24) [x86_64-darwin11.4.2]
--- 1
/monkeys/index
@teeparham
teeparham / rvm_install_ruby_2_osx.sh
Last active December 14, 2015 04:09
OSX ruby 2.0 install with rvm and homebrew
brew update
brew install libyaml
rvm get head
rvm pkg install openssl
rvm install 2.0.0 --with-openssl-dir=$HOME/.rvm/usr --verify-downloads 1
rvm use 2.0.0 --default
gem update rake
gem install bundler --pre
@teeparham
teeparham / in_groups_of_with_index.rb
Created February 8, 2013 04:24
ruby array extension that combines ActiveSupport in_groups_of + each_with_index
class Array
# [1,2,3,4,5,6,7,8].in_groups_of_with_index(3, false) do |group, index|
# puts group.to_s + " " + index.to_s
# end
# [1, 2, 3] 0
# [4, 5, 6] 1
# [7, 8] 2
# => [[1, 2, 3], [4, 5, 6], [7, 8]]
#
# [1,2,3,4,5,6,7,8].in_groups_of_with_index(3, "x") do |group, index|
@teeparham
teeparham / rvm_install_193_p374_patched.sh
Last active December 11, 2015 11:09
Install lastest MRI ruby 1.9.3 patch 374 with railsexpress patch set
rvm get head
rvm install 1.9.3-p374 --patch railsexpress
rvm use ruby-1.9.3-p374 --default
@teeparham
teeparham / bm_extend.rb
Created January 3, 2013 17:26
Ruby extend performance test
# gem install benchmark-ips
require 'rubygems'
require 'benchmark/ips'
module Mixin
def foo; 42; end
end
class SubclassArray < Array