Skip to content

Instantly share code, notes, and snippets.

@joel
joel / resque
Created September 27, 2011 09:30
Monit Resque by app
Check process resque_<app_name> with pidfile /var/www/<app_name>_production/shared/pids/resque.pid
start program = "/bin/sh /usr/local/bin/resque_<app_name>-start" as uid capistrano and gid users
stop program = "/bin/sh /usr/local/bin/resque_<app_name>-stop" as uid capistrano and gid users
group resque
if 5 restarts within 5 cycles then timeout
alert contact@world_company.com
@joel
joel / textmate_update_finder.rb
Created May 29, 2012 13:51
get last version of TextMate 2 Alpha
#!/usr/bin/env ruby
require "open-uri"
def print_status(status, n)
# The text of the status code is in [1]
case status.to_i
when 200
puts "match #{n} http://dl.textmate.org/Application/TextMate_r#{n}.tbz"
system "wget http://dl.textmate.org/Application/TextMate_r#{n}.tbz"
@joel
joel / gist:2909289
Created June 11, 2012 09:25
Make You Own Gem
http://guides.rubygems.org/make-your-own-gem/
rvm use ruby-1.9.3-p0@lorem --create
echo "rvm use ruby-1.9.3-p0@lorem --create" >> lorem/.rvmrc
bundle gem lorem
gem build lorem.gemspec
git tag -a v0.0.1 -m 'version 0.0.1'
git push --tags
gem push lorem-0.0.1.gem
@joel
joel / gist:2928524
Created June 14, 2012 06:59
Time comparison ActiveSupport vs Gem Twitter Static Time Constants w Ruby Benchmark
require 'rubygems'
# Set up gems listed in the Gemfile.
ENV['BUNDLE_GEMFILE'] ||= File.expand_path('Gemfile', __FILE__)
require 'bundler/setup' if File.exists?(ENV['BUNDLE_GEMFILE'])
require 'rails/all'
require 'time_constants'
@joel
joel / gist:2928905
Created June 14, 2012 08:03
Time comparison ActiveSupport vs Gem Twitter Static Time Constants w Ruby Prof
require 'rubygems'
# Set up gems listed in the Gemfile.
ENV['BUNDLE_GEMFILE'] ||= File.expand_path('Gemfile', __FILE__)
require 'bundler/setup' if File.exists?(ENV['BUNDLE_GEMFILE'])
require 'rails/all'
require 'time_constants'
require 'ruby-prof'
@joel
joel / gist:2964568
Created June 21, 2012 08:23
Use Object Tap instead return
#!/usr/bin/env ruby
# http://blog.rubybestpractices.com/posts/gregory/011-tap-that-hash.html
# http://www.ruby-doc.org/core-1.9.3/Object.html#method-i-tap
class TestingObjectTap
def legacy
results = {}
[:x, :y, :z].each do |letter|
results[letter] = rand(100)
@joel
joel / require_presence_of.rb
Created July 3, 2012 06:58
Rspec Custom Matcher require_presence_of
# Matcher place into spec/support/require_presence_of.rb
RSpec::Matchers.define :require_presence_of do |attr|
match do |model|
model.send("#{attr}=", nil)
!model.valid? && model.errors.has_key?(attr)
end
end
# Sample of use
@joel
joel / fix_homebrew.rb
Created July 6, 2012 10:10
Fix HomeBrew Binary unlinked after update Gcc
#!/usr/bin/env ruby
class CleaningHomeBrew
# Your binaries unlinked
BINARIES = ['cmake', 'imagemagick', 'jasper', 'jpeg', 'libevent', 'libtiff', 'little-cms','memcached','mysql','ossp-uuid','pidof','postgresql','redis','sphinx','wget']
class << self
def clean
@joel
joel / gist:3059347
Created July 6, 2012 10:07
Git Alias
alias gs='git status && git branch'
alias gsa='git status && git branch -a'
alias gp='git push && git branch'
alias gc='git commit -v -a'
alias gcb='git checkout'
alias gnb='git checkout -b'
alias ga='git add .'
alias gl='git log && git branch'
alias gln='git log -n 1 && git branch'
alias gd='git log --diff-filter=D --summary'
@joel
joel / gist:3076423
Created July 9, 2012 12:59
Comparaison blank? present? Nil ?
require 'rubygems'
# Set up gems listed in the Gemfile.
ENV['BUNDLE_GEMFILE'] ||= File.expand_path('Gemfile', __FILE__)
require 'bundler/setup' if File.exists?(ENV['BUNDLE_GEMFILE'])
require 'rails/all'
N = 10000000
EMPTY_STRING = ''