Skip to content

Instantly share code, notes, and snippets.

View ssoroka's full-sized avatar
👾

Steven Soroka ssoroka

👾
View GitHub Profile
@ssoroka
ssoroka / ar_factory_test.rb
Created March 25, 2013 20:26
Make your data layer an implementation detail. :)
require 'test_helper'
class ARFactory
def self.new(table_name)
Class.new(ActiveRecord::Base) do
self.table_name = table_name
end
end
end
# insert at the top of boot.rb for FUN!
require 'benchmark'
$level ||= 0
$file ||= File.open('require_tree.log', 'w')
$pending_writes = []
Object.class_eval do
def __trace_requires(arg, &block)
val = nil
time = nil
$pending_writes << [$level, arg]
#!/usr/bin/env bash
export RUBY_HEAP_MIN_SLOTS=800000
export RUBY_HEAP_FREE_MIN=100000
export RUBY_HEAP_SLOTS_INCREMENT=300000
export RUBY_HEAP_SLOTS_GROWTH_FACTOR=1
export RUBY_GC_MALLOC_LIMIT=79000000
alias flow='ps vx | grep -iE "\b(adium|messages|mail|skype|twitter|propane|flint|sparrow)\b" | grep -v grep | cut -f1 -d" " | xargs kill; osascript -e "tell Application \"iTunes\" to play" 2&> /dev/null; echo "FLOW MODE ENABLED: Distractions closed; tunes playing"'
alias flowish='ps vx | grep -iE "\b(mail|skype|twitter|propane|flint|sparrow)\b" | grep -v grep | cut -f1 -d" " | xargs kill; osascript -e "tell Application \"iTunes\" to play" 2&> /dev/null; echo "FLOW MODE ENABLED: Distractions closed; tunes playing"'
export HISTFILESIZE=100000
require 'objectdb'
db = ObjectDB.new
user = {:name => 'steve', :domain => 'go_fish.com', :customer_since => Time.now.to_s}
db.set('steve@example.com', user)
db.get('steve@example.com')
=> {"name"=>"steve", "domain"=>"go_fish.com", "customer_since"=>"Sun Jul 31 02:19:51 -0500 2011"}
@ssoroka
ssoroka / git-compare
Created July 5, 2011 15:36
github git-compare; opens commits in github's compare feature.
#!/usr/bin/env ruby
# ONE-LINE INSTALL INSTRUCTIONS:
# wget --no-check-certificate https://raw.github.com/gist/1065081/git-compare; chmod u+x git-compare; mv git-compare `which git-status | ruby -e "puts STDIN.read.split(/\//)[0..-2].join('/')"`/
$remote = 'origin'
def usage
puts %(
opens commits in github's compare feature. Commits must be pushed (remote "origin" is default)
@ssoroka
ssoroka / active_record_sql_counter.rb
Created June 30, 2011 15:32
active_record_sql_counter.rb
module ActiveRecord
class SQLCounter
IGNORED_SQL = [/^PRAGMA (?!(table_info))/, /^SELECT currval/, /^SELECT CAST/, /^SELECT @@IDENTITY/, /^SELECT @@ROWCOUNT/, /^SAVEPOINT/, /^ROLLBACK TO SAVEPOINT/, /^RELEASE SAVEPOINT/, /^SHOW max_identifier_length/]
# FIXME: this needs to be refactored so specific database can add their own
# ignored SQL. This ignored SQL is for Oracle.
IGNORED_SQL.concat [/^select .*nextval/i, /^SAVEPOINT/, /^ROLLBACK TO/, /^\s*select .* from all_triggers/im]
def initialize
$queries_executed = []
@ssoroka
ssoroka / acceptance_helper.rb
Created May 30, 2011 05:45
Use feature, background, and scenario blocks to write acceptance tests in test/unit
# Use feature, background, and scenario blocks to write acceptance tests in test/unit
# which are really just integration tests. include capybara or webrat or something and voila.
# test/acceptance_helper.rb
require 'test_helper'
module ActionDispatch
class AcceptanceTest < ActionDispatch::IntegrationTest
class << self
alias :background :setup
Rubinius Crash Report #rbxcrashreport
Error: signal SIGSEGV
[[Backtrace]]
0 rbx 0x00000001000212e0 _ZN8rubiniusL12segv_handlerEi + 160
1 libSystem.B.dylib 0x00007fff8044866a _sigtramp + 26
2 ??? 0x00007fff5fbf3490 0x0 + 140734799754384
3 rbx 0x00000001001c8d93 _ZN8rubinius12ObjectWalker4nextEv + 51
4 rbx 0x00000001001276f6 _ZN8rubinius6System14vm_find_objectEPNS_2VMEPNS_5ArrayEPNS_6ObjectEPNS_9CallFrameE + 422
@ssoroka
ssoroka / evented_irb.rb
Created March 18, 2011 21:14
dead simple em-synchrony evented console. woop
$:<< '../lib' << 'lib'
require 'rubygems'
require 'eventmachine'
require 'em-synchrony'
EM.run {
EM.synchrony {
loop do
begin
@ssoroka
ssoroka / Gemfile
Created February 16, 2011 20:10
A default Gemfile with most of the stuff I use in every project.
# Use "bundle install --path vendor/bundler"
source :rubygems
gem 'mysql'
gem 'rails', '~> 3.0' # rails 3!
gem 'hoptoad_notifier'
gem 'app_settings', :git => 'git://github.com/ssoroka/app_settings.git'
gem 'ignore_nil' # eg: ignore_nil { user.account.config.name.strip }
gem 'less'