Skip to content

Instantly share code, notes, and snippets.

View bensie's full-sized avatar

James Miller bensie

View GitHub Profile
package main
import (
"bytes"
"exec"
"log"
"os"
)
// Pipeline strings together the given exec.Cmd commands in a similar fashion
@bensie
bensie / no_www.rb
Created March 27, 2012 19:17 — forked from trevorturk/no_www.rb
no-www rack middleware
class NoWww
def initialize(app)
@app = app
end
def call(env)
request = Rack::Request.new(env)
if request.host.starts_with?("www.")
[301, {"Location" => request.url.sub(/www./, "")}, self]
heroku config --long | ruby -pe "\$_ = \$_.gsub(/(\w+)\s+=> (.+)/, 'export \1=\2')" > /tmp/$$ && source /tmp/$$; rm /tmp/$$
function convertDateTimeSelectTo12Hour() {
var translate = {"00":"Midnight","01":"1am","02":"2am","03":"3am","04":"4am","05":"5am","06":"6am","07":"7am","08":"8am","09":"9am","10":"10am","11":"11am","12":"Noon","13":"1pm","14":"2pm","15":"3pm","16":"4pm","17":"5pm","18":"6pm","19":"7pm","20":"8pm","21":"9pm","22":"10pm","23":"11pm"};
$("select[name$='(4i)]'] option").each(function() {
$(this).text(translate[$(this).text()]);
});
}
@bensie
bensie / license
Created January 27, 2010 15:32 — forked from defunkt/license
#!/bin/sh -e
# Usage: license
# Prints an MIT license appropriate for totin' around.
#
# $ license > COPYING
#!/bin/sh
echo "Copyright (c) `date +%Y` Chris Wanstrath
Permission is hereby granted, free of charge, to any person obtaining
a copy of this software and associated documentation files (the
ZIP_FILE = "#{PROJECT}.zip"
desc "Zip of the folder for release"
task :zip => [:clean] do
require 'zip/zip'
require 'zip/zipfilesystem'
# check to see if the file exists already, and if it does, delete it.
if File.file?(ZIP_FILE)
/**
* Format any UTC timestamp on the page to the users local timezone.
*/
var DateFormat = {
autoParse: function(){
$$('span.timestamp').each(function(span) {
var utc = Date.parseUTC(span.getAttribute('utc'));
var rel = span.getAttribute('format');
span.set('html', rel == 'words' ? utc.timeAgoInWords() : utc.strftime(rel))
});
@bensie
bensie / fsm.rb
Created December 4, 2009 16:49 — forked from dmcinnes/fsm.rb
class FSM
def initialize
@states = {}
end
def state(name, &block)
s = State.new
s.instance_eval(&block)
@states[name] = s
module AttrLogger
def self.included(base)
base.extend(ClassLevelMethods)
end
module ClassLevelMethods
def attr_logger(*args)
args.each do |attribute|
define_method(attribute) do
value = instance_variable_get("@#{attribute}")
#!/usr/bin/env ruby
require 'rubygems'
require 'logger'
require 'net/ssh'
require 'net/smtp'
require 'patron'
require 'timeout'
require 'parseconfig'
require 'yaml'