Skip to content

Instantly share code, notes, and snippets.

View openfirmware's full-sized avatar

James Badger openfirmware

View GitHub Profile
@openfirmware
openfirmware / gs_dedupe_queue.js
Created June 11, 2011 22:37
Remove duplicate songs from Grooveshark queue. Keeps first instance of song. Compares using SongID, so will not catch different uploads for the same song. Tested with Google Chrome 12, Safari 5, and Firefox 4.
song_hash = {};
removal_list = [];
for(var i = 0; i < window.GS.player.queue.songs.length; i++) {
var song = window.GS.player.queue.songs[i];
if(song_hash[song["SongID"]] == undefined) {
song_hash[song["SongID"]] = 1;
} else {
removal_list.push(song["queueSongID"]);
}
}
@openfirmware
openfirmware / check_rsnapshot.rb
Created October 13, 2011 20:46
Nagios check rsnapshot
#!/usr/bin/env ruby
#
# Nagios check for rsnapshot activity and errors
# Author: James Badger <jamesbadger@gmail.com>
#
# == Documentation
#
# This script will check rsnapshot's log file to determine if it is actively
# running and that it is running without errors.
#
When /^I send a GET request for "([^"]*)"$/ do |path|
get path
end
Then /^the response code should be "([^"]*)"$/ do |code|
last_response.status.should == code.to_i
end
Before "@no-throttle" do
@app = Rack::Builder.new {
map "/api" do
run proc { |env|
[200, {}, ["OK"]]
}
end
}
end
When /^I send a GET request for "([^"]*)"$/ do |path|
get path
end
When /^I send more than one GET request in a second to "([^"]*)"$/ do |path|
# We'll assume this happens in < 1 second
get path
get path
end
@openfirmware
openfirmware / passenger_standalone.rb
Created March 9, 2012 18:30 — forked from reu/passenger_standalone.rb
Capistrano recipe for passenger standalone
set :rails_env, "production"
set :passenger_port, 9292
set :passenger_cmd, "#{bundle_cmd} exec passenger"
namespace :deploy do
task :start, :roles => :app, :except => { :no_release => true } do
run "cd #{current_path} && #{passenger_cmd} start -e #{rails_env} -p #{passenger_port} -d"
end
task :stop, :roles => :app, :except => { :no_release => true } do
@openfirmware
openfirmware / gist:3427808
Created August 22, 2012 17:36
capybara-webkit 0.12.1 install issue
$ ruby -v
ruby 1.9.3p194 (2012-04-20 revision 35410) [x86_64-darwin12.0.0]
$ uname -a
Darwin James-MacBook-Pro.local 12.0.0 Darwin Kernel Version 12.0.0: Sun Jun 24 23:00:16 PDT 2012; root:xnu-2050.7.9~1/RELEASE_X86_64 x86_64
$ rvm version
rvm 1.15.5 (master) by Wayne E. Seguin <wayneeseguin@gmail.com>, Michal Papis <mpapis@gmail.com> [https://rvm.io/]
$ brew doctor
Your system is raring to brew.
@openfirmware
openfirmware / engine_override.rb
Created January 17, 2013 23:28
This piece of code (from http://stackoverflow.com/a/5051185/237958) can be used to automatically extend controllers/helpers/models and replace views defined in a Rails engine with the same files defined in the host Rails application. Works on Rails 3.2.11.
# config/initializers/engine_override.rb
require 'active_support/dependencies'
module ActiveSupport::Dependencies
alias_method :require_or_load_without_multiple, :require_or_load
def require_or_load(file_name, const_path = nil)
if file_name.starts_with?(Rails.root.to_s + '/app')
relative_name = file_name.gsub(Rails.root.to_s, '')
@engine_paths ||= Rails.application.railties.engines.collect{|engine| engine.config.root.to_s }
@engine_paths.each do |path|
#!/usr/bin/env ruby
# -*- ruby -*-
require 'rubygems'
require 'daemon_spawn'
RAILS_ROOT = File.expand_path(File.join(File.dirname(__FILE__), '..'))
class DelayedJobWorker < DaemonSpawn::Base
def start(args)
ENV['RAILS_ENV'] ||= args.first || 'development'