Skip to content

Instantly share code, notes, and snippets.

View ntalbott's full-sized avatar
💻
Writing and Coding

Nathaniel Talbott ntalbott

💻
Writing and Coding
View GitHub Profile
$ irb
> require 'roadtrip'
=> true
> t = Roadtrip::Trip.new 'rdu', 'hilton downtown, nashville, tn', 2.75, 15
=> #<Roadtrip::Trip:0x00000100a23e28 @start="rdu", @destination="hilton downtown, nashville, tn", @cost_per_gallon=2.75, @mpg=15>
> t.distance
=> "528 mi"
> t.duration
=> "8 hours 23 mins"
> t.cost
@ntalbott
ntalbott / config.ru
Created December 20, 2010 23:02
Automatically and temporarily exposes a little Rack server on your firewall for testing purposes. Requires UPnP to be enabled on your firewall to work.
EXTERNAL_PORT = 42063
require 'UPnP'
upnp = UPnP::UPnP.new(true, 10)
upnp.addPortMapping(EXTERNAL_PORT, 9292, UPnP::Protocol::TCP, "Test Port")
at_exit{upnp.deletePortMapping(EXTERNAL_PORT, UPnP::Protocol::TCP)}
puts "Call externally: http://#{upnp.externalIP}:#{EXTERNAL_PORT}"
run proc{|env| p :env => env; [200, {"Content-Type" => "text/html"}, ["success\n"]]}
@ntalbott
ntalbott / hashed_sprintf.rb
Created February 15, 2011 01:06
For those still stuck on 1.8, edge cases left as an exercise to the reader...
require 'test/unit'
class TestHashedSprintf < Test::Unit::TestCase
def hashed_sprintf(string, hash)
array = []
cleaned_string = string.gsub(/%<(\w+)>/) do |match|
array << hash[$1.to_sym]
'%'
end
sprintf(cleaned_string, *array)
@ntalbott
ntalbott / entrepreneur.txt
Created February 18, 2011 17:03
Definition of "Entrepreneur"
"An entrepreneur is a person who takes responsibility for finding a sustainable way to deliver value in an uncertain environment."
-- adapted from Eric Ries' definition of a startup in http://www.startuplessonslearned.com/2010/06/what-is-startup.html, broadened to include Steve Blank's four types of entrepreneurs in http://steveblank.com/2010/06/10/you%E2%80%99re-not-a-real-entrepreneur/
@interface TT : NSObject {
}
-(BOOL)isEnabled;
@end
@ntalbott
ntalbott / gharch
Created April 11, 2011 21:46
Github Repo Archive Script
#!/usr/bin/env ruby
target = ARGV[0]
dest = ARGV[1]
unless target && dest
puts "Github Archive Usage: gharch <user/repo> <destdir>"
exit(1)
end
remote, repo = target.split("/")
@ntalbott
ntalbott / AppDelegate.rb
Created May 4, 2011 13:56
MacRuby "can't convert Class into String (TypeError)"
class AppDelegate
attr_accessor :window
def applicationDidFinishLaunching(a_notification)
NSRunLoop.currentRunLoop.performSelector :test, target: self, argument: nil, order: 1, modes: NSDefaultRunLoopMode
end
def test
puts "Hi!"
end
end
@ntalbott
ntalbott / gist:958220
Created May 6, 2011 00:01
git log --no-merges --pretty=short --since="2011-04-25" --until="2011-05-01" | git shortlog
Duff OMelia (8):
Don't use an rvm gemset.
Fixed unit test.
Upgrade colored gem
Don't need the version for map_by_method gem.
Don't need to specify a version for the will_paginate_gem.
Upgrade the database_cleaner gem.
Upgraded mocha gem.
Fix exception we just received.
@ntalbott
ntalbott / gist:964921
Created May 10, 2011 17:12
Output of `make rel` for riak 0.14.1
ntalbott@joshua:~/git/riak$ make rel
./rebar get-deps
==> cluster_info (get-deps)
==> skerl (get-deps)
==> protobuffs (get-deps)
==> basho_stats (get-deps)
==> riak_sysmon (get-deps)
==> mochiweb (get-deps)
==> webmachine (get-deps)
==> riak_core (get-deps)
@ntalbott
ntalbott / curl_put_spreedly.php
Created June 20, 2011 12:28 — forked from gjsoulman/curl_put_spreedly.php
PHP CURL PUT to Spreedly Core
<?php
$apiLogin = 'Ll6fAtoVSTyVMlJEmtpoJV8Shw5';
$apiSecret = 'RKOCG5D8D3fZxDSg504D0IxU2XD4Io5VXmyzdCtTivHFTTSylzM2ZzTWFwVH4ucG';
$paymentToken = 'N2V9GWfTgYv4jXAz2vcc4T3i8f6';
$url = 'https://spreedlycore.com/v1/payment_methods/' . $paymentToken . '/retain.xml';
$ch = curl_init($url);
curl_setopt($ch, CURLOPT_USERPWD, $apiLogin . ':' . $apiSecret);