Skip to content

Instantly share code, notes, and snippets.

View lukeredpath's full-sized avatar
🏠
Working from home

Luke Redpath lukeredpath

🏠
Working from home
View GitHub Profile
# could we track github forks as "sources"?
$ brew track [github user]
$ brew track lukeredpath
# refresh sources if we're caching?
$ brew refresh [github user] (default: --all)
# listing formulae
def file_upload_from_string(string, content_type = 'text/plain')
test_upload_file = nil
Tempfile.open('file_upload_from_string') do |tempfile|
tempfile.write(string)
tempfile.rewind
test_upload_file = ActionController::TestUploadedFile.new(tempfile.path, content_type)
end
return test_upload_file
end
#define kApproxRadiusOfEarthInMiles 3963.1676
#define kApproxSizeOfOneDegreeLatitudeInMiles 68.71
#define kApproxSizeOfOneDegreeLongitudeAtLatitude(lat) ((M_PI/180.0)* kApproxRadiusOfEarthInMiles *cos(lat))
static function MKCoordinateSpan MKCoordinateSpanMakeWithDistanceInMiles(float miles, CLLocationDegrees latitude) {
MKCoordinateSpan viewSpan;
viewSpan.latitudeDelta = miles / kApproxSizeOfOneDegreeLatitudeInMiles;
viewSpan.longitudeDelta = miles / kApproxSizeOfOneDegreeLongitudeAtLatitude(latitude);
return viewSpan;
}
## remove unnecessary files and folders
%w{README doc public/favicon.ico}.each { |file| run("rm -rf #{file}") }
## configure git repository
git :init
file ".gitignore", %Q{
log/*
# prints to STDOUT by default, optional -o switch to specify output file
$ ruby tweetstream.rb -t 'myhashtag' -f 'lukeredpath' -e 'path/to/template.erb'
Options:
--tag, -t <s>: Hashtag to use as a filter
--from, -f <s>: Restrict to tweets from a specific user
--template, -e <s>: ERB template used to render the stream
--output, -o <s>: Output to this file
--help, -h: Show this message
#import "EGOCache.h"
@interface EGOCache (Plist)
- (NSData*)plistForKey:(NSString*)key;
- (void)setPlist:(id)plistObject forKey:(NSString*)key;
- (void)setPlist:(id)plistObject forKey:(NSString*)key withTimeoutInterval:(NSTimeInterval)timeoutInterval;
@end
require 'money'
require 'xe_exchange'
Money.default_bank = XE::Exchange.instance
ten_dollars = Money.new(1000, 'USD')
ten_dollars_in_pounds = ten_dollars.exchange_to('GBP')
@lukeredpath
lukeredpath / .freeagent
Created January 8, 2010 18:46
Generate a HTML expense report using the FreeAgent API
# this goes in ~/.freeagent
ENV['FA_COMPANY'] = 'mycompany'
ENV['FA_USERNAME'] = 'myloginemail'
ENV['FA_PASSWORD'] = 'mypassword'
#!/usr/bin/env ruby
# if you have lib/scripts/do_something.rb
# you might run:
# script/runner lib/scripts/do_something.rb
# but now you can do:
# script/daemon lib/scripts/do_something.rb (run|start|stop|restart)
require File.join(File.dirname(__FILE__), *%w[.. config environment])
require 'daemons'
require 'active_support'
require 'curb'
require 'yajl'
class TweetStreamer
def initialize(username, password, host = 'stream.twitter.com')
@username, @password = username, password
@host = host
@api_version = 1
end