Skip to content

Instantly share code, notes, and snippets.

Avatar

Jack Danger JackDanger

View GitHub Profile
View rails_test_modernizer.rb
#!/usr/bin/env ruby
# ActiveSupport has a more modern syntax now. Pipe any old-style
# ActiveSupport::TestCase suites into this file and have the syntax
# updated. For when you can't use Shoulda or RSpec but you still
# want to look sexy.
#
# Before:
#
# def test_guy_can_do_stuff
@JackDanger
JackDanger / gist:71799
Created Feb 28, 2009
Play yourself some Archx
View gist:71799
alias djgoatboy="curl -L `curl -s http://twitter.com/statuses/user_timeline/djgoatboy.rss | grep "title>djgoatboy:" | head -n 1 | cut -c 23-47` > djgoatboy.mp3; afplay djgoatboy.mp3"
View gist:73425
#!/usr/bin/env ruby1.9
#
# In Javascript you can add a function to an object like so:
#
# obj.perform = function(){ ... stuff to do ...}
#
# But in Ruby 1.8 there's always been a problem where a method
# defined with `define_method` won't be able to take a block.
# So you'd never be able to do something like this:
View gist:78377
(sent to Jack in the Box contact address)
Ahoy!
My name is Jack. It's a pretty good name. I love to eat at
Jack in the Box and I'd extra-double love to wear the oversized
Jack™ head around town here in Seattle.
Could you send me a huge Jack™ head that I can wear as I go
from cafe to cafe (I work for a startup and it's all telecommuting)?
I'd be happy to abide by any rules of conduct you might have for
wearing the Jack™ head. I'd be willing to sign something to that effect.
@JackDanger
JackDanger / gist:92951
Created Apr 10, 2009
simple framework-agnostic javascript image preloader
View gist:92951
// USAGE:
// preloadImage('/images/something_over.png')
// preloadImage('/images/other_over.gif')
// preloadImage.load()
preloadImage = (function(){
var images = []
var placeholder = new Image()
var instantiate = function(idx){
@JackDanger
JackDanger / hoptoad.rake
Created Apr 23, 2009
Make all Rake (production) errors go to Hoptoadapp.com
View hoptoad.rake
namespace :hoptoad do
desc "Makes all Rake (production) errors go to Hoptoadapp.com"
task :catch do
class Rake::Task
def execute_with_hoptoad(*args)
execute_without_hoptoad(*args)
rescue => e
require File.expand_path(File.dirname(__FILE__)+'/../../config/environment')
HoptoadNotifier.notify e
end
View gist:116987
# from: http://pivotallabs.com/users/alex/blog/articles/865-monkey-patch-du-jour
module ActiveRecord
module ConnectionAdapters
class AbstractAdapter
def log_info(sql, name, ms)
if @logger && @logger.debug?
@logger.debug("#{sql}, #{name}, #{ms}")
c = caller.detect{|line| line !~ /(activerecord|active_support|__DELEGATION__|\/lib\/|\/vendor\/plugins|\/vendor\/gems)/i}
c.gsub!("#{File.expand_path(File.dirname(RAILS_ROOT))}/", '') if defined?(RAILS_ROOT)
name = '%s (%.1fms) %s' % [name || 'SQL', ms, c]
View gist:118235
# put this in your ~/.irbrc
class Object
def console_reminder
puts "You're not in Terminal. CMD-} until you're out of the console."
end
# replace these with your common terminal commands
%w{gs gp gl cd l rake}.each do |cmd|
eval "alias #{cmd} console_reminder"
end
end
View CaseHawk Test Data
gem 'faker'
require 'faker'
account_id = 4
randomize = 'PostgreSQL' == ActiveRecord::Base.connection.adapter_name ? 'RANDOM()' : 'RAND()'
# Makes a bunch of different types of events per day at a random time during work hours
(30.days.ago.to_date..90.days.from_now.to_date).each do |date|
rand(3).times do
View gist:119076
for source in `find app test lib config -name *.rb`; do
if [ 2 = `egrep -c -v "(^#)|(^\s*$)" $source` ]; then
echo $source is an empty class or module definition;
fi;
done;