Skip to content

Instantly share code, notes, and snippets.

View matisojka's full-sized avatar

Mateusz Sójka matisojka

View GitHub Profile
@matisojka
matisojka / measure_gem_loading_time.rb
Created July 4, 2012 07:05
Measure Gem loading time in your Rails APP
# Disclaimer: this solution has been taken from the post: http://stackoverflow.com/a/5071198/784270
# navigate to the bundler gem and in lib/bundler/runtime.rb,
# find the line that does Kernel.require and wrap it like this
puts Benchmark.measure("require #{file}") {
Kernel.require file
}.format("%n: %t %r")
# Add
@matisojka
matisojka / chef_solo_bootstrap.sh
Created May 13, 2012 19:08 — forked from ryanb/chef_solo_bootstrap.sh
Bootstrap Chef Solo
#!/usr/bin/env bash
apt-get -y update
apt-get -y install build-essential zlib1g-dev libssl-dev libreadline5-dev libyaml-dev
cd /tmp
wget ftp://ftp.ruby-lang.org/pub/ruby/1.9/ruby-1.9.3-p125.tar.gz
tar -xvzf ruby-1.9.3-p125.tar.gz
cd ruby-1.9.3-p125/
./configure --prefix=/usr/local
make
make install
@matisojka
matisojka / singleton_spec.rb
Created March 30, 2012 09:34
Test Ruby Singleton Classes
class MySingletonClass
include Singleton
def initialize
## Do some initializing
end
## Your business logic
end
@matisojka
matisojka / gist:2236364
Created March 29, 2012 11:44
Change the character encoding of an existing database
alter database DATABASE_NAME charset=utf8
@matisojka
matisojka / valid_json.rb
Created March 29, 2012 11:36 — forked from carlcrott/gist:2218175
JSON validation method (without monkey patching and with proper error handling)
def valid_json?(value)
JSON.parse value
true
rescue JSON::ParserError, TypeError
false
end