Skip to content

Instantly share code, notes, and snippets.

View ssoroka's full-sized avatar
👾

Steven Soroka ssoroka

👾
View GitHub Profile
40+ newbie rails mistakes
themes:
Build for failure
expect services to be slow
expect services to be unavailable
Build so components can be easily replaced
Build so code can be easily reused
mistakes:
@ssoroka
ssoroka / prevent_doubleclick.js
Created January 13, 2011 17:03
Prevent a link with .prevent_doubleclick class from being clicked more than once every 10 seconds; avoids multiple link submits
function do_nothing() {
return false;
}
// prevent a second click for 10 seconds. :)
$('.prevent_doubleclick').live('click', function(e) {
$(e.target).click(do_nothing);
setTimeout(function(){
$(e.target).unbind('click', do_nothing);
}, 10000);
@ssoroka
ssoroka / speller.rb
Created February 13, 2011 03:38
spelling game in 18 lines of ruby
dictionary = File.read('/usr/share/dict/words').split("\n")
dictionary = dictionary.select { |word|
word.length > 3 && word.length < 7
}
word_picked = dictionary[rand(dictionary.size)]
system %(say "#{word_picked}")
@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'
@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
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 / 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
@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 / 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)
require 'objectdb'
db = ObjectDB.new
user = {:name => 'steve', :domain => 'go_fish.com', :customer_since => Time.now.to_s}
db.set('[email protected]', user)
db.get('[email protected]')
=> {"name"=>"steve", "domain"=>"go_fish.com", "customer_since"=>"Sun Jul 31 02:19:51 -0500 2011"}