Skip to content

Instantly share code, notes, and snippets.

require "pg"
require "redis"
words = File.read("/usr/share/dict/words").split "\n"
pgconn = PGconn.open :dbname => "test_hstore", :port => 5433, :user => "test_user", :password => "changeme"
redis = Redis.new
reps = [1,10,100,1000,10000]
pg_inserts = []
pg_selects = []
redis_sets = []
require 'active_record'
require 'activerecord-import'
require 'benchmark'
require 'pg'
include ActiveRecord
Base.establish_connection adapter: 'postgresql',
encoding: 'unicode',
pool: 5,
$ ./benchmark.rb 1000
user system total real
# Inserting 1000 rows normally
insertion 0.290000 0.030000 0.320000 ( 0.396852)
# Updating 1000 rows normally
updating 0.280000 0.020000 0.300000 ( 0.381354)
# Updating 100 rows, adding 10 columns each
insertion/10 0.280000 0.020000 0.300000 ( 0.410743)
@Phazz
Phazz / gist:6131502
Created August 1, 2013 13:48
Typing history in shell
history | awk '{a[$2]++ } END{for(i in a){print a[i] " " i}}'|sort -rn |head -n 30

Launch Sublime Text 2 from the Mac OS X Terminal

Sublime Text 2 ships with a CLI called subl (why not "sublime", go figure). This utility is hidden in the following folder (assuming you installed Sublime in /Applications like normal folk. If this following line opens Sublime Text for you, then bingo, you're ready.

open /Applications/Sublime\ Text\ 2.app/Contents/SharedSupport/bin/subl

You can find more (official) details about subl here: http://www.sublimetext.com/docs/2/osx_command_line.html

Installation

Launch Sublime Text 2 from the Mac OS X Terminal

Sublime Text 2 ships with a CLI called subl (why not "sublime", go figure). This utility is hidden in the following folder (assuming you installed Sublime in /Applications like normal folk. If this following line opens Sublime Text for you, then bingo, you're ready.

open /Applications/Sublime\ Text\ 2.app/Contents/SharedSupport/bin/subl

You can find more (official) details about subl here: http://www.sublimetext.com/docs/2/osx_command_line.html

Installation

require 'factory_girl_rails'
require 'rspec'
require 'rspec-rails'
require 'rspec/mocks/standalone' # => if factories need stubs (for remote services for example)
include FactoryGirl::Syntax::Methods # make FG methods available at top level, so you can do `> create :user`
def reload_factories!
FactoryGirl.instance_variable_set(:@factories, nil) # => clear loaded factories/sequences
# FactoryGirl.instance_variable_set(:@sequences, nil)
require 'spec_helper'
describe 'block example' do
let(:thing) { FactoryGirl.create :thing }
context 'without versioning' do
before do
thing.update_attributes name: 'a different name'
@Phazz
Phazz / deploy.rb
Created October 9, 2013 12:08 — forked from ahawkins/deploy.rb
#!/usr/bin/env ruby
# This is a basic deploy script for Heroku apps.
# It provides a structure you can use to expand on
# and add your own prereqs and deploy tasks.
#
# It basically ensures that:
# 1. There are no uncommited files
# 2. You can ssh to github
# 3. You can connect to heroku
test:
override:
- bundle exec rspec spec
deployment:
acceptance:
branch: master
commands:
- ./script/heroku_deploy.sh <ACCEPTANCE_HEROKU_APP>:
timeout: 300