Skip to content

Instantly share code, notes, and snippets.

View iagooar's full-sized avatar

Mateusz Sójka iagooar

View GitHub Profile
@iagooar
iagooar / Gemfile
Last active August 29, 2015 14:04
Proxy for separate backend + frontend apps that work together
source 'https://rubygems.org'
gem 'rack-reverse-proxy', require: 'rack/reverse_proxy'
group :development do
gem 'foreman'
end
@iagooar
iagooar / comparison.rb
Created November 27, 2013 08:40
First string character comparison benchmark
require 'benchmark'
name = 'my_cool_string'
Benchmark.bmbm(10) do |x|
x.report('name[0] hit') do
1_000_000.times { name[0] == 'm' }
end
x.report('name[0] miss') do
1_000_000.times { name[0] == 'y' }
@iagooar
iagooar / 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
@iagooar
iagooar / 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
@iagooar
iagooar / 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
@iagooar
iagooar / gist:2236364
Created March 29, 2012 11:44
Change the character encoding of an existing database
alter database DATABASE_NAME charset=utf8
@iagooar
iagooar / 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