Skip to content

Instantly share code, notes, and snippets.

@shedd
shedd / schedule.rb
Created May 7, 2011 15:03
Lockrun support for Whenever cron jobs
# Support running Whenever cron jobs with Lockrun
# Lockrun: http://www.unixwiz.net/tools/lockrun.html
# lockrun typically installed at /usr/bin/lockrun
# On Mac, install with: brew install lockrun
# Lockrun prefix for cronjobs: /usr/bin/lockrun --lockfile=/path/to/tmp/JOBNAME.lockrun -- sh -c "COMMAND"
def wrap_with_lockrun command
"/usr/bin/env lockrun --lockfile=:path/tmp/:lockfile.lockrun -- sh -c \"#{ command }\""
end
#redefine the three default job types to use Lockrun (i.e. just add 'lockrun_' in front of the existing job names)
@shedd
shedd / assets.rake
Created June 20, 2011 18:05
Check asset encoding for valid UTF-8
namespace :assets do
task :check => :environment do
paths = ["app/assets", "lib/assets", "vendor/assets"]
paths.each do |path|
dir_path = Rails.root + path
if File.exists?(dir_path)
dir_files = File.join(dir_path, "**")
@shedd
shedd / gist:1040432
Created June 22, 2011 16:01
Hoptoad Errors on Ruby 1.9.2 w/ Rails 3.1.rc4
## VANILLA RAKE
username /data/appname/current $ ruby --version
ruby 1.9.2p180 (2011-02-18 revision 30909) [i686-linux]
username /data/appname/current $ rake hoptoad:test --trace
DEPRECATION WARNING: attr_accessor_with_default is deprecated. Use Ruby instead!. (called from block in <module:Configuration> at /data/appname/shared/bundled_gems/ruby/1.9.1/bundler/gems/active_admin-47cab4dd73d6/lib/active_admin/comments/configuration.rb:12)
** Invoke hoptoad:test (first_time)
** Invoke environment (first_time)
** Execute environment
** Invoke hoptoad:log_stdout (first_time)
@shedd
shedd / gist:1040446
Created June 22, 2011 16:08
lib/tasks/hoptoad_tasks.rake
# Don't load anything when running the gems:* tasks.
# Otherwise, hoptoad_notifier will be considered a framework gem.
# https://thoughtbot.lighthouseapp.com/projects/14221/tickets/629
unless ARGV.any? {|a| a =~ /^gems/}
Dir[File.join(Rails.root, 'vendor', 'gems', 'hoptoad_notifier-*')].each do |vendored_notifier|
$: << File.join(vendored_notifier, 'lib')
end
begin
@shedd
shedd / pause_pingdom.rb
Created June 24, 2011 21:57
Script to use the Pingdom API to pause and unpause check
require 'net/http'
require 'net/https'
require 'uri'
PINGDOM_API_HOSTNAME = "api.pingdom.com"
PINGDOM_API_KEY = "your_api_key_here"
PINGDOM_API_VERSION = "2.0"
PINGDOM_CHECK_ID = "######"
PINGDOM_USERNAME = "[email protected]"
PINGDOM_PASSWORD = "password"
@shedd
shedd / gist:1162412
Created August 22, 2011 13:51
Wrap Rake Tasks in Hoptoad Notifier
# Log any errors to Hoptoad as needed
# ** define this before the lib/tasks are included
def task_with_hoptoad_notification(options)
task(options) do
begin
yield
rescue Exception => msg
HoptoadNotifier.notify(msg)
end
end
@shedd
shedd / gist:1162432
Created August 22, 2011 13:56
Wrap New Relic Instrumentation around Hoptoad Rake wrapper
# Add New Relic instrumentation
# ** define this before the lib/tasks are included
def task_with_new_relic_and_hoptoad(options)
caller_method = options.keys.first
task(options) do
require 'newrelic_rpm'
include NewRelic::Agent::Instrumentation::ControllerInstrumentation
NewRelic::Agent.manual_start
@shedd
shedd / gist:1200269
Created September 7, 2011 10:50
terminitor config for BetDash
# BETDASH DEVELOPMENT ENVIRONMENT
# tab 1: terminal in betdash project
# tab 2: Rails console
# tab 3: tail -f on development log
# tab 4: dev script
before { run 'fgb' }
tab "BetDash", :selected => true do
run "clear"
@shedd
shedd / gist:1255865
Created October 1, 2011 10:44
Fun with Probability
# to run this file:
# gem install rspec
# rspec prob_spec.rb
class Integer
def factorial
self.downto(1).inject(:*)
end
end
@shedd
shedd / gist:1299851
Created October 19, 2011 22:16
Airbrake SSL certificate issues
Configuration:
notifier_name: "Airbrake Notifier"
http_open_timeout: 2
proxy_host: nil
api_key: "<REMOVED>"
notifier_url: "http://airbrakeapp.com"
http_read_timeout: 5
user_information: "Airbrake Error {{error_id}}"
proxy_user: nil
notifier_version: "3.0.4"