Skip to content

Instantly share code, notes, and snippets.


Todd Huss thuss

View GitHub Profile
View arrival_calculator.rb
require 'time'
module ArrivalCalculator
TWELVE_HOURS = 12 * 60 * 60
TWENTY_FOUR_HOURS = 24 * 60 * 60
# Average time of day expects array such as ['11:00am', '1:00pm'] => '12:00pm'
def average_time_of_day(times)
times_in_seconds = do | time |
raise ArgumentError, "Unexpected format " + time unless time.strip =~ /^[01]?\d:\d\d(am|pm)$/
View arrival_calculator_spec.rb
require File.dirname(__FILE__) + '/spec_helper.rb'
describe ArrivalCalculator do
include ArrivalCalculator
it "should throw an exception on unexpected values" do
lambda { average_time_of_day(["26:41am", "6:51am"]) }.should raise_error(ArgumentError)
it "should handle a single time" do
View README.rdoc
thuss /
Created Dec 8, 2010
A simple script to backup github repositories
#!/bin/bash -e
# This script clones or fetches the latest updates from selected repo's and then tar's them up
REPOS="vm-main vm-cdn vm-operations-chef vm-iphone vm-contrib"
function clone_or_fetch {
View gist:870094
package org.vm.web;
import java.util.*;
* @author thuss
public class CollectionStuff {
private Map<String, String> redirects = new HashMap<String, String>() {{
thuss / login.feature
Created Apr 16, 2011
Cucumber login scenario
View login.feature
Scenario: login with valid credentials
Given I am on the login page
When I fill in "Email" with ""
And I fill in "Password" with "test123pass"
And I press "Login"
Then I should be on the users home page
And I should see "Login successful"
thuss / _map.html.haml
Created Jun 27, 2011
Google maps haml partial
View _map.html.haml
/ Partial used on for mapping organizations
- organizations = organizations.delete_if{|o| o.latitude.nil? || o.longitude.nil?}
- if organizations.size > 0
- center = Geocoder::Calculations.geographic_center(organizations.clone)
%script{:src => ""}
%script{:type => "text/javascript"}
function initialize() {
var myOptions = {
thuss / LeadArticleViewControllerTest.m
Created Jul 17, 2011
Testing a UIViewController with OCHamcrest and OCMock
View LeadArticleViewControllerTest.m
// LeadArticleViewControllerTest.m
#import <SenTestingKit/SenTestingKit.h>
#import <OCHamcrestIOS/OCHamcrestIOS.h>
#import <OCMock/OCMock.h>
#import <CoreData/CoreData.h>
#import "AppController.h"
View gist:1139006
+(NSDictionary *)dictionaryFromJsonWebService:(NSString *)urlString {
if (!urlString) return [NSDictionary dictionary];
NSDictionary *dict = nil;
NSError *err;
// Make the web service request
NSURL *url = [NSURL URLWithString:urlString];
NSHTTPURLResponse* urlResponse = nil;
NSMutableURLRequest *req = [NSMutableURLRequest requestWithURL:url
thuss /
Created Aug 17, 2011
New BR plist format and old format annotated with changes
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "">
<plist version="1.0">