Skip to content

Instantly share code, notes, and snippets.

View bspaulding's full-sized avatar

Bradley Spaulding bspaulding

View GitHub Profile
// Navigation Handler
// ---------------
// Author: Bradley Spaulding, USAi.net
//
// Navigation Handler is built for the USAi.net Wireless Portal.
// This script handles DOM manipulation for page navigation.
// Updated 2009-08-20: Fixed IE Latency issue which caused frequent "No Navigation Item is Active" errors.
function NavigationHandler(set_nav_div, set_content_div) {
#! /usr/bin/ruby
# USAGE:
# ./validate_md5.rb /path/to/file Exp3ct3dD1G35t
require 'digest/md5'
expected_digest = ARGV[1]
computed_digest = Digest::MD5.hexdigest(File.open(ARGV[0]).read)
Ajax.InPlaceEditorWithEmptyText = Class.create(Ajax.InPlaceEditor, {
initialize: function($super, element, url, options) {
if (!options.emptyText) options.emptyText = "Click to Edit";
if (!options.emptyClassName) options.emptyClassName = "inplaceeditor-empty";
$super(element, url, options);
this.checkEmpty();
@bspaulding
bspaulding / BSTimer.rb
Created October 19, 2010 20:10
A simple task timing class. It allows you to time the execution of any inline block or proc.
# BSTimer
# - A simple task timing class. It allows you to time the execution of any inline block or proc.
# Author: Bradley J. Spaulding
# Created On: 2010-10-11
# Last Updated: 2010-10-19
#
class BSTimer
def self.time(num_trials = 1, &block)
results = []
@bspaulding
bspaulding / application_controller.rb
Created October 11, 2011 14:51 — forked from ajvargo/gist:1277150
Create a presenter object on the fly in Rails
# Inspired by Ryan Bates pro RailsCast "Presenters from Scratch"
# This is a proof of concept for 'automagically' creating presenter objects
#
# This assumes you have presenter objects that follow the convention
# Object => ObjectPresenter
#
# It intercepts the 'render' method in the controller, and does some
# introspection to see if there is a presenter defined for the class
# of the instance variable being looked at. If so, it makes a presenter
# and adds it as an instance variable
@bspaulding
bspaulding / WordCount.java
Created November 15, 2011 23:08
WordCount.java
package org.myorg;
import java.io.IOException;
import java.util.*;
import org.apache.hadoop.fs.Path;
import org.apache.hadoop.conf.*;
import org.apache.hadoop.io.*;
import org.apache.hadoop.mapred.*;
import org.apache.hadoop.util.*;
@bspaulding
bspaulding / require.js
Created November 22, 2011 20:26
CommonJS Modules Implementation in Pure JS
var exports = {};
var module = {};
function require(id) {
if ( 'undefined' === typeof arguments.callee.require_stack ) { arguments.callee.require_stack = []; }
var require_stack = arguments.callee.require_stack;
if ( 'undefined' === typeof arguments.callee.modules ) { arguments.callee.modules = {}; }
var modules = arguments.callee.modules;
// if currently requiring module 'id', return partial exports
@bspaulding
bspaulding / rgba_to_rgb.rb
Created May 22, 2012 14:24
Convert and RGBA color on a specified background to an opaque RGB color.
#! /usr/bin/env ruby
# Pseudo Code
# - http://stackoverflow.com/questions/2049230/convert-rgba-color-to-rgb
#
# Source => Target = (BGColor + Source) =
# Target.R = ((1 - Source.A) * Source.R) + (Source.A * BGColor.R)
# Target.G = ((1 - Source.A) * Source.G) + (Source.A * BGColor.G)
# Target.B = ((1 - Source.A) * Source.B) + (Source.A * BGColor.B)
#! /usr/bin/env ruby
require 'webrick'
include WEBrick
HTTPUtils::DefaultMimeTypes["appcache"] = "text/cache-manifest"
HTTPUtils::DefaultMimeTypes["js"] = "text/javascript"
HTTPUtils::DefaultMimeTypes["mp3"] = "audio/mpeg3"
server = HTTPServer.new(:Port => 9090, :DocumentRoot => Dir::pwd)
@bspaulding
bspaulding / gist:3003731
Created June 27, 2012 12:25
jenkins-post-receive
#!/bin/bash
#
# jenkins-post-receive
#
# Configuraton
# ------------
# jenkins-post-receive.enabled
# [OPTIONAL] Defaults to off (false). Treated as a boolean with git config --bool.
#
# jenkins-post-receive.jenkins-cli-jar-path