Skip to content

Instantly share code, notes, and snippets.

View atnan's full-sized avatar

Nathan de Vries atnan

View GitHub Profile
@atnan
atnan / gist:1100998
Created July 23, 2011 04:03
Creating arbitrarily-colored icons from a black-with-alpha master image (iOS)
// Usage example:
// input image: http://f.cl.ly/items/3v0S3w2B3N0p3e0I082d/Image%202011.07.22%2011:29:25%20PM.png
//
// UIImage *buttonImage = [UIImage ipMaskedImageNamed:@"UIButtonBarAction.png" color:[UIColor redColor]];
// .h
@interface UIImage (IPImageUtils)
+ (UIImage *)ipMaskedImageNamed:(NSString *)name color:(UIColor *)color;
@end
static NSString * const AQPerThreadManagedObjectContext = @"AQPerThreadManagedObjectContext";
void StoreManagedObjectContextForCurrentThread( NSManagedObjectContext * context )
{
[[[NSThread currentThread] threadDictionary] setObject: context forKey: AQPerThreadManagedObjectContext];
}
NSManagedObjectContext * PerThreadManagedObjectContext( void )
{
NSManagedObjectContext * result = [[[NSThread currentThread] threadDictionary] objectForKey: AQPerThreadManagedObjectContext];
@atnan
atnan / compare.js
Created December 3, 2009 03:53 — forked from wycats/compare.js
// prototype
new Ajax.Request("/your/mom", onSuccess: function(response) { $("lightbox_content").innerHTML = response.responseJSON.contents })
// jquery
$.getJSON("/your/mom", function(json) { $("#lightbox_content").html(json.contents) })
// $.getJSON provides no ability to handle connection/parse errors
$.ajax({ url: "/your/mom", success: function(json) { $("#lightbox_content").html(json.contents) }, dataType: "json" })
@atnan
atnan / gist:218497
Created October 26, 2009 08:05 — forked from neror/gist:216705
#import <UIKit/UIKit.h>
#import "GTMStackTrace.h"
#ifdef DEBUG
extern BOOL NSDebugEnabled;
extern BOOL NSZombieEnabled;
extern BOOL NSDeallocateZombies;
extern BOOL NSHangOnUncaughtException;
static void exceptionHandler(NSException *exception) {
FTLOG(@"%@", GTMStackTraceFromException(exception));
def measure_time task_description
beginning = Time.now
yield
puts "Time to #{task_description}: #{Time.now - beginning} seconds"
end
def add a, i
a << i
end
# Would help dramatically if the function and arguments were appropriately named
def f(ra,n)
ra.inject(0) do |accum, value|
value.include?(n) ? accum + 1 : accum
end
end