Skip to content

Instantly share code, notes, and snippets.

//
// prototype-scriptaculous-hint-text.js | by Rick Branson -- Released into the public domain.
//
// Adds placeholder text above an input. Fades in and out. Is sexy. No kids. Not tested in IE (yet).
//
// $(element).hintText("string", {
// hiddenOpacity: the opacity of the placeholder text when it's hidden. (0.0 to 1.0)
// shownOpacity: the opacity of the placeholder text when it's shown. (0.0 to 1.0)
// effectDuration: the length (in seconds) of the fading effect, 0 turns it off.
// textPadding: the amount of text padding to use if none is explicitly set on
#
# To use this, drop it into your lib directory and add a require to an initializer
# in config/initializers.
#
# This little extension to Mongoid allows belongs_to_related associations to
# have an "in" option, which will traverse the object graph to find the
# collection that will contain the related model object.
#
# The goal is to allow relations to be created that reference objects embedded
# in documents, instead of only objects that are contained within collections.
@rbranson
rbranson / run-node.sh
Created October 21, 2010 16:16
start-stop-daemon friendly script to start node and log to a file
#!/bin/sh
#
# Runs node.js against script, logging to a logfile. We have to do
# this because there's no way to call node directly and have start-stop-daemon
# redirect stdout to a logfile.
#
LOGFILE=/var/log/node/node-application.log
NODE=/usr/local/bin/node
JAVASCRIPT=/var/apps/node-application/app.js
@rbranson
rbranson / delayed_job
Created October 29, 2010 02:43
A hack of a delayed_job monitoring script for Munin
#!/usr/bin/env ruby
if ARGV[0] == "autoconf"
puts "yes"
exit
end
if ARGV[0] == "config"
puts <<EOT
graph_title delayed_jobs
@rbranson
rbranson / slurp-election-xml.rb
Created November 3, 2010 17:23
Reads ABC's XML files for 2010 election totals and dumps them out.
#!/usr/bin/env ruby
#
# Read's ABC's XML files for 2010 election totals and dumps them out.
#
# http://a.abcnews.com/xml/elections/2010/dynamic/dynamicgeneral/prod/elections/national/HouseMap.xml
# http://a.abcnews.com/xml/elections/2010/dynamic/dynamicgeneral/prod/elections/national/SenateMap.xml
#
# Copyright (c) 2010 Rick Branson
#
# Permission is hereby granted, free of charge, to any person obtaining a copy
@rbranson
rbranson / minify_javascript_cache.rb
Created November 5, 2010 19:28
An initializer that will make Rails run JSMin on any cached JavaScript files
# Copyright (c) 2010 Richard Branson
#
# Permission is hereby granted, free of charge, to any person obtaining a copy
# of this software and associated documentation files (the "Software"), to deal
# in the Software without restriction, including without limitation the rights
# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
# copies of the Software, and to permit persons to whom the Software is
# furnished to do so, subject to the following conditions:
#
# The above copyright notice and this permission notice shall be included in
@rbranson
rbranson / gist:664855
Created November 5, 2010 20:57
Roughly Benchmark Page Speed as if it was from a 1.5mbit Connection
wget -nv --limit-rate=150k --delete-after -p http://www.site.com/path/to/page
@rbranson
rbranson / pidigits.rb
Created November 17, 2010 07:36
Implementation of pidigits using GMP
# The Computer Language Benchmarks Game
# http://shootout.alioth.debian.org/
# transliterated from Mario Pernici's Python program
# contributed by Rick Branson
require "rubygems"
require "gmp"
def gmpz(n)
#!/bin/sh -x
# git name-rev is fail
CURRENT=`git branch | grep '\*' | awk '{print $2}'`
git checkout master
git merge ${CURRENT}
git push origin master
git checkout ${CURRENT}
#!/bin/sh -x
# git name-rev is fail
CURRENT=`git branch | grep '\*' | awk '{print $2}'`
if [ "$CURRENT" == "master" ]; then
echo "Current branch is master!"
exit
fi
git checkout master