Skip to content

Instantly share code, notes, and snippets.

View callumj's full-sized avatar
🙌
writing code

Callum Jones callumj

🙌
writing code
View GitHub Profile
@callumj
callumj / extracted.m
Created February 12, 2014 10:12
MPNowPlayingInfoCenter setting
- (void)reflectNowPlaying
{
if (_activeTrack == nil)
return;
NSMutableDictionary *activeInfo = [[NSMutableDictionary alloc] initWithDictionary:[[MPNowPlayingInfoCenter defaultCenter] nowPlayingInfo]];
if (artworkNeedsReflecting || metaNeedsReflecting)
{
[activeInfo setObject:[_activeTrack title] forKey:MPMediaItemPropertyTitle];
@callumj
callumj / Dockerfile
Created March 11, 2014 02:02
Example Dockerfile for Ruby app (with Bundler + Git clone)
FROM ubuntu
MAINTAINER Callum Jones <callum@callumj.com>
RUN echo "deb http://archive.ubuntu.com/ubuntu precise main universe" > /etc/apt/sources.list
RUN apt-get -y update
# prep for downloading and installing ruby
RUN mkdir -p /temp/ruby
RUN apt-get install -y build-essential libssl-dev zlib1g-dev
@callumj
callumj / README.md
Created March 11, 2014 09:31
TearUp/Down databases in NUnit tests

Database helper for NUnit tests

I've found the need to interact with an actual database context during my NUnit tests (as opposed to abstracting away), I couldn't find any ways to achieve this so I've written my own simple TestHelper.

Basically this give you access to TestHelper.testContext, which will create the context and migrate the test database for the first time.

@callumj
callumj / playlist_hinting.h
Created March 17, 2014 14:04
PlaylistHinting
@protocol PlaylistHinting<NSObject>
- (SCItem *)nextItemAfter:(SCItem *)item;
@end
@callumj
callumj / Helper.cs
Created March 19, 2014 07:15
Helper code for ASP.NET MVC alternating
public class OddEvenWrapper<T>
{
public T Object { get; set; }
public bool Even { get; set; }
}
public static IEnumerable<OddEvenWrapper<T>> AlternateOddEven<T>(IEnumerable<T> list)
{
bool even = false;
foreach(T obj in list)
@callumj
callumj / merge.go
Last active August 29, 2015 13:59
Merge
func mergeIntoBaseArchive(baseArchive ArchiveInfo, basedir string, contents []string, file string) {
var mapped map[string]bool
mapped = make(map[string]bool)
for _, item := range contents {
stripped := strings.Replace(item, basedir, "", 1)
mapped[stripped] = true
}
// tar pntr for copy
dupe, dupeErr := os.Create(file)
@callumj
callumj / ex.rb
Created December 12, 2014 22:28
Stripe final invoice example
Params: {"id"=>"evt_15918WAOjoYioo6eh6ubIhG3", "created"=>1418420384, "livemode"=>false, "type"=>"invoice.payment_failed", "data"=>{"object"=>{"date"=>1418416740, "id"=>"in_1590BkAOjoYioo6e7zU6p7za", "period_start"=>1418416740, "period_end"=>1418416740, "lines"=>{"object"=>"list", "total_count"=>2, "has_more"=>false, "url"=>"/v1/invoices/in_1590BkAOjoYioo6e7zU6p7za/lines", "data"=>[{"id"=>"ii_1590BkAOjoYioo6eFYIKO43B", "object"=>"line_item", "type"=>"invoiceitem", "livemode"=>false, "amount"=>121999, "currency"=>"usd", "proration"=>false, "period"=>{"start"=>1418416740, "end"=>1418416740}, "subscription"=>nil, "quantity"=>nil, "plan"=>nil, "description"=>"Host 'rails-4198' 122 hours at 1000.00c/hour", "metadata"=>{}}, {"id"=>"ii_1590BkAOjoYioo6em1eascIv", "object"=>"line_item", "type"=>"invoiceitem", "livemode"=>false, "amount"=>136999, "currency"=>"usd", "proration"=>false, "period"=>{"start"=>1418416740, "end"=>1418416740}, "subscription"=>nil, "quantity"=>nil, "plan"=>nil, "description"=>"Host 'test2-9598'
@callumj
callumj / README.md
Last active August 29, 2015 14:24
now_playing.rb
def doRummbleMethod(method, queryString)
consumer = OAuth::Consumer.new(API_KEY, API_SECRET, { :site => "http://api.rummble.com", :request_token_url => "http://www.rummble.com/oauth/request_token", :access_token_url => "http://www.rummble.com/oauth/access_token", :authorize_url => "http://www.rummble.com/oauth/authorize" })
paramsString = ""
if queryString.size > 0
queryString.to_a.collect {|key, value| paramsString << "#{key}=#{value}&"}
paramsString[paramsString.length - 1] = '' #remove last &
end
returnObj = consumer.request(:get, "/?method=#{method}&#{paramsString}", nil, {:scheme => :query_string})
returnObj.body
end
file='/Users/callumj/Desktop/test.txt'
f = File.open(file, "r")
f.each_line { |line|
if !line.downcase.include?("total")
randomval = rand(500)
print "#{line[0,line.rindex(',')]},#{randomval}\r\n"
end
}
f.close