Skip to content

Instantly share code, notes, and snippets.

View jschoolcraft's full-sized avatar

Jeff Schoolcraft jschoolcraft

View GitHub Profile
@jschoolcraft
jschoolcraft / TechDecisions.md
Created December 1, 2011 18:51
Choices to make in a new Rails project. Would love to see this forked with other's opinions.

Team Support

Source Code Control

git (private server)
Alternative: github

Time Tracking

Cashboard

@jschoolcraft
jschoolcraft / plugins.watchr.rb
Created October 19, 2011 14:02
plugin development sucks less: restart passenger when a file under vendor/plugins changes
# Run me with:
#
# $ watchr plugins.watchr.rb
# --------------------------------------------------
# Convenience Methods
# --------------------------------------------------
def run(cmd)
puts(cmd)
system(cmd)
@jschoolcraft
jschoolcraft / delayed_job.monitrc
Created September 10, 2011 14:37 — forked from denmarkin/delayed_job.monitrc
real-world monit recipes
# See: http://stackoverflow.com/questions/1226302/how-to-monitor-delayedjob-with-monit/1285611
check process delayed_job with pidfile /full/path/to/app/shared/pids/delayed_job.pid
start program = "/bin/su - deploy_username -c 'cd /full/path/to/app/current/; RAILS_ENV=production script/delayed_job start'"
stop program = "/bin/su - deploy_username -c 'cd /full/path/to/app/current/; RAILS_ENV=production script/delayed_job stop'"
@jschoolcraft
jschoolcraft / mysql2_connection_pool.rb
Created August 25, 2011 18:13
a simple connection pool for eventmachine & mysql2
require 'mysql2'
require 'mysql2/em'
class MysqlConnectionPool
def initialize(conf)
@pool_size = conf[:size] || 10
@connections = []
@query_queue = EM::Queue.new
start_queue conf
@jschoolcraft
jschoolcraft / gist:1168190
Created August 24, 2011 14:29
Capistrano recipe for multi-stage deployment running Passenger standalone
$:.unshift(File.expand_path('./lib', ENV['rvm_path']))
require "rvm/capistrano"
# REPLACE this below with your ruby version/gemset version: YOUR_RUBY_VERSION@YOUR_GEM_SET
set :rvm_ruby_string, 'ruby-1.9.2-p136@example_gemset'
set :use_sudo, false
set :stages, %w(production staging)
set :default_stage, "staging"
require 'capistrano/ext/multistage'
>> dates
=> [#<Date: 2011-07-01 (4911487/2,0,2299161)>, #<Date: 2011-07-20 (4911525/2,0,2299161)>]
>> Date.today - dates.map { |d| Date.today - d }.map(&:to_f).inject { |sum, diff| sum + diff } / dates.length
=> #<Date: 2011-07-10 (2455753.0,0,2299161)>
>>
@jschoolcraft
jschoolcraft / gist:1094715
Created July 20, 2011 10:13 — forked from masaki/gist:329030
OO-ish ab (apache bench)
#!/usr/bin/ruby
require 'stringio'
module AB
class Response
class << self
def parse_string(string)
new.tap {|res| res.parse_string(string) }
end
@jschoolcraft
jschoolcraft / reminder.rb
Created June 24, 2011 20:28
rake task to send reminders
# redMine - project management software
# Copyright (C) 2008 Jean-Philippe Lang
#
# This program is free software; you can redistribute it and/or
# modify it under the terms of the GNU General Public License
# as published by the Free Software Foundation; either version 2
# of the License, or (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
@jschoolcraft
jschoolcraft / persistence.md
Created May 18, 2011 23:28 — forked from jraines/persistence.md
Notes on Adam Keys' presentation "Mixing a persistence cocktail"
  • Marshaling AR objects: dangerous if internal structure of AR object changes with Rails change

Relaxing consistency requirements

  • Is it ok for users to see slightly older data?

Configuring

  • Initializer that loads yaml file that loads different connections per Rails environtment
@jschoolcraft
jschoolcraft / confident-code.md
Created May 18, 2011 23:28 — forked from jraines/confident-code.md
Notes on Avdi Grimm's "Confident Code"

Confident Code

timid code

  • Randomly mixes input gathering, error handling, and business logic
  • imposes cognitive load on the reader

confident code

  • no digressions