Skip to content

Instantly share code, notes, and snippets.

View rubysolo's full-sized avatar

Solomon White rubysolo

View GitHub Profile
@rubysolo
rubysolo / etc_init.d_unicorn_example.co.uk
Created October 27, 2011 20:04 — forked from scottlowe/etc_init.d_unicorn_example.co.uk
Ruby on Rails server setup on Ubuntu 11.04 with Nginx, Unicorn, Rbenv
#! /bin/bash
### BEGIN INIT INFO
# Provides: unicorn
# Required-Start: $local_fs $remote_fs $network $syslog
# Required-Stop: $local_fs $remote_fs $network $syslog
# Default-Start: 2 3 4 5
# Default-Stop: 0 1 6
# Short-Description: starts the unicorn web server
# Description: starts unicorn
set nocompatible
let mapleader = ","
call pathogen#infect()
syntax on
filetype plugin indent on
color herald
Given I have the following users:
| company | user |
| ACME | bob |
| ACME | jim |
Given /I have the following users/ do |users|
users.hashes.each do |user_attributes|
company_name = user_attributes.delete('company')
company = Company.find_by_name(company_name) || Company.make(:name => company_name)
@rubysolo
rubysolo / luhn10.coffee
Created September 13, 2011 19:16
CoffeeScript Luhn10
flatten = (a) ->
if a.length is 0 then return []
a.reduce (lhs, rhs) -> lhs.concat rhs
divmod = (x, y) ->
[(q = Math.floor(x/y)), (r = if x < y then x else x % y)]
valid = (number) ->
num = ((Number) x for x in number).reverse()
num = (2 * x for x in num[1..num.length] by 2).concat(
task "resque:setup" => :environment do
# since our priorized job classes are generated dynamically,
# we need to explicitly load all jobs to trigger the generation.
Dir[Rails.root.join("app/models/jobs/*.rb")].each do |job_defn|
require File.expand_path(job_defn)
end
end
class SalesOrderMailerJob
@queue = :critical # you can make this up
def self.perform(sales_order_id)
SalesOrderMailer.deliver_something(SalesOrder.find(sales_order_id))
end
end
@rubysolo
rubysolo / descriptive_sql_load_log.rb
Created July 19, 2011 20:42 — forked from JackDanger/descriptive_sql_load_log.rb
Let Rails display file names and line numbers for log activity.
module ActiveRecord
module ConnectionAdapters
class AbstractAdapter
protected
# Turn:
# User Load (6.3ms) SELECT * FROM "users"
# Into:
# User Load /app/views/_partial.erb:27 (6.3ms) in `_app_views_partial_erb` SELECT * FROM "users"
@rubysolo
rubysolo / gist:1047951
Created June 26, 2011 20:38 — forked from clarkware/gist:1046693
View Source for Ruby
# Toss this in your ~/.irbrc file for a convenient way
# to peruse Ruby source code in TextMate. This
# only works in Ruby 1.9!
#
# Use it in irb like so:
#
# >> require 'active_record'
# >> ActiveRecord::Base.source_for_method(:create)
class Object
@rubysolo
rubysolo / app_resizer.rb
Created June 24, 2011 16:48
A Mac OS application resizer script for different desktop resolutions.
require "rubygems"
require "appscript"
class AppResizer
include Appscript
# Full screen bounds for all modes.
HOME_FULL_SCREEN = [0, 0, 2560, 1440]
LAPTOP_FULL_SCREEN = [0, 0, 1440, 900]
@rubysolo
rubysolo / empty
Created June 17, 2011 17:34 — forked from banister/empty
pry(main):4> blame_for(Pry.instance_method(:repl)).display
John Mair def repl(target=TOPLEVEL_BINDING)
John Mair target = Pry.binding_for(target)
John Mair target_self = target.eval('self')
John Mair
John Mair repl_prologue(target)
Mon ouïe
John Mair # cannot rely on nesting.level as
John Mair # nesting.level changes with new sessions
John Mair nesting_level = nesting.size