This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env ruby | |
require 'sinatra' | |
# simple script to serve static files from an arbitrary directory via Sinatra | |
# usage: rserve [/path/to/dir] [port] | |
# path will default to '.' | |
pub = File.expand_path(ARGV.shift || '.') | |
puts "Setting Public to #{pub}" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
describe "Something" do | |
before do | |
# __name__ defined in MiniTest::Unit::TestCase | |
VCR.insert_cassette(__name__) | |
end | |
after do | |
VCR.eject_cassette | |
end | |
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
require 'httparty' | |
require 'nokogiri' | |
require 'date' | |
require 'json' | |
abort 'usage: ruby nfl.rb [WEEK NUM]' if ARGV.size < 1 | |
resp = HTTParty.get("http://m.nfl.com/scores/reg/#{ARGV.shift}/") | |
parser = Nokogiri::HTML(resp.body) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// attempts to call a function; returns undef if function is not defined | |
Object.prototype.try = function(name, args){ | |
return this[name] ? this[name].apply(this, args) : undefined; | |
}; | |
// more robust version | |
Object.prototype.try = function(name){ | |
return this[name] ? this[name].apply(this, Array.prototype.slice.call(arguments, 1)) : undefined; | |
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class Settings | |
attr_reader :config | |
def initialize(fname) | |
@file_name = fname | |
config = YAML.load_file(fname) rescue false | |
@config = config || {} | |
end | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(function($){ | |
var prop = 'VisibilityState'; | |
var evt = 'visibilitychange'; | |
var vendors = ['webkit', 'ms']; | |
var vendor; | |
function set_state(state){ | |
$(window).trigger('visibilitychange', state); | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class ApplicationControllerTest < ActionController::TestCase | |
def setup | |
# create and initialize anonymous controller | |
@controller = Class.new(ApplicationController) do | |
def index | |
# what goes here all depends on the situation and the method your trying to test | |
end | |
end::new | |
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var LocationHash = (function(ev){ | |
var hash, changed = []; | |
function read_hash(){ | |
var list = location.hash.substr(1).split('&'); | |
hash = {}; | |
for (var i = 0, pair; pair = list[i]; i++){ | |
var split = pair.split('='); | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
require 'minitest/autorun' | |
class Minitest::Test | |
def self.test(name, &block) | |
define_method "test_#{name.gsub(/\s+/, '_')}", &block | |
end | |
def self.setup(&block) | |
define_method :setup, &block | |
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
!function(factories){ | |
factories.factory('$eventSource', ['$window', function($window){ | |
var EventSource = $window.EventSource; | |
function parse(obj){ | |
try { var json = JSON.parse(obj); } | |
catch(e) { json = {}; } | |
finally { return json; } | |
} |
OlderNewer