Skip to content

Instantly share code, notes, and snippets.

View thuss's full-sized avatar

Todd Huss thuss

View GitHub Profile
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)
end
it "should handle a single time" do
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 = times.map do | time |
raise ArgumentError, "Unexpected format " + time unless time.strip =~ /^[01]?\d:\d\d(am|pm)$/
@thuss
thuss / github-backups.sh
Created December 8, 2010 17:49
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
#
CHECKOUT_DIR=$HOME/backups/checkouts
BACKUP_DIR=$HOME/backups/tarballs
LOG=/tmp/github-daily-backups.log
REPOS="vm-main vm-cdn vm-operations-chef vm-iphone vm-contrib"
function clone_or_fetch {
package org.vm.web;
import java.util.*;
/**
* @author thuss
*/
public class CollectionStuff {
private Map<String, String> redirects = new HashMap<String, String>() {{
@thuss
thuss / _map.html.haml
Created June 27, 2011 16:45
Google maps haml partial
/ Partial used on http://www.fanclasstic.com 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)
#google-map
%script{:src => "http://maps.google.com/maps/api/js?sensor=false"}
%script{:type => "text/javascript"}
//<![CDATA[
function initialize() {
var myOptions = {
@thuss
thuss / LeadArticleViewControllerTest.m
Created July 17, 2011 22:27
Testing a UIViewController with OCHamcrest and OCMock
//
// LeadArticleViewControllerTest.m
//
#import <SenTestingKit/SenTestingKit.h>
#define HC_SHORTHAND
#import <OCHamcrestIOS/OCHamcrestIOS.h>
#import <OCMock/OCMock.h>
#import <CoreData/CoreData.h>
#import "AppController.h"
+(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
cachePolicy:NSURLRequestReloadIgnoringLocalCacheData
@thuss
thuss / tags.new.plist
Created August 17, 2011 17:15
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" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<array>
<dict>
<key>uniqueName</key>
<string>nfl</string>
<key>displayName</key>
<string>NFL</string>
<key>shortName</key>
@thuss
thuss / version.json
Created September 28, 2011 22:36
1.2.5 Android App Release Notes
{
"1.2.5": [
"Added top stories to the home screen",
"Improved navigation between your team stream and articles",
"Added ability to install or move the app to the SD card",
"Added haptic feedback to buttons"
]
}