Skip to content

Instantly share code, notes, and snippets.

// Construct and run the javascript. SBJsonParser only works with objects or
// arrays, so we wrap the result in an array in case the result is not either
// an object or an array.
NSString* wrappedJavascript =
[NSString stringWithFormat:@"JSON.stringify([%@])", javascript];
NSString* resultJSON = [componentPlugin writeJavascript:wrappedJavascript];
// Parse and return the result, making sure to unwrap the result first.
SBJsonParser* jsonParser = [[[SBJsonParser alloc] init] autorelease];
NSArray* wrappedResult = [jsonParser objectWithString:resultJSON];
static char clickTargetScaleKey;
static char clickTargetWidthKey;
static char clickTargetHeightKey;
BOOL pointInsideWithEvent(
UIView* self, SEL _cmd, CGPoint point, UIEvent* event) {
NSNumber* clickTargetScaleNumber =
objc_getAssociatedObject(self, &clickTargetScaleKey);
assert(clickTargetScaleNumber);
float clickTargetScale = [clickTargetScaleNumber floatValue];
@mschulkind
mschulkind / gist:1258368
Created October 3, 2011 03:20
UIColor from string
+ (UIColor*)colorFromString:(NSString*)colorString
{
UIColor* color;
if ([colorString characterAtIndex:0] == '#') {
unsigned int hexValue;
[[NSScanner scannerWithString:[colorString substringFromIndex:1]]
scanHexInt:&hexValue];
NSInteger red, green, blue;
switch([colorString length]) {
** Invoke test:full (first_time)
** Invoke test (first_time)
** Execute test
/home/matt/.rvm/rubies/ruby-1.9.2-p180/bin/ruby -w -I"lib:lib:test" -rubygems -I"/home/matt/.rvm/gems/ruby-1.9.2-p180@rabl/gems/rake-0.9.2/lib" "/home/matt/.rvm/gems/ruby-1.9.2-p180@rabl/gems/rake-0.9.2/lib/rake/rake_test_loader.rb" "test/*_test.rb"
/home/matt/.rvm/gems/ruby-1.9.2-p180@rabl/gems/bundler-1.0.15/lib/bundler/rubygems_ext.rb:43: warning: method redefined; discarding old gem_dir
/home/matt/.rvm/rubies/ruby-1.9.2-p180/lib/ruby/site_ruby/1.9.1/rubygems/specification.rb:1262: warning: previous definition of gem_dir was here
/home/matt/.rvm/gems/ruby-1.9.2-p180@rabl/gems/bundler-1.0.15/lib/bundler/rubygems_ext.rb:154: warning: method redefined; discarding old hash
/home/matt/.rvm/rubies/ruby-1.9.2-p180/lib/ruby/site_ruby/1.9.1/rubygems/platform.rb:125: warning: previous definition of hash was here
/home/matt/.rvm/gems/ruby-1.9.2-p180@rabl/gems/bundler-1.0.15/lib/bundler/rubygems_integration.rb:183: warning: method redefined;
@mschulkind
mschulkind / gist:1217885
Created September 14, 2011 21:43
ObjC Swizzlin'
// Every class using this inherits from the class defining these methods,
// and provides a +uiKitSubclass method which returns the class object of
// the class which should be swizzled.
+ (void)subclassMethod:(SEL)selector
withImplementation:(IMP)subclassedImplementation
{
Method uiKitMethod = class_getInstanceMethod([self uiKitSubclass], selector);
assert(uiKitMethod);
Class superclass = class_getSuperclass([self class]);
Method superDealloc = class_getInstanceMethod(superclass, _cmd);
IMP superDeallocImp = method_getImplementation(superDealloc);
superDeallocImp(self, _cmd);
#import <UIKit/UIKit.h>
@interface DebugUIWebView : UIWebView {
@private
NSMutableDictionary* sourceIDMap_;
}
@property (nonatomic, retain) NSMutableDictionary* sourceIDMap;
@end
// Start building the command object.
var command = {
className: service,
methodName: action,
arguments: []
};
// Register the callbacks and add the callbackId to the positional
// arguments if given.
var callbackId = null;
[DEBUG] 2011-08-16 19:13:51.691 foo-app[65967:207] Exception - sourceID: 98712768
Source:
shouldRotateToOrientation(0);
Offending line:
1: shouldRotateToOrientation(0);
Call stack:
(null)
(null)
@mschulkind
mschulkind / gist:1143324
Created August 13, 2011 00:27
async image loading
// imageView is a UIImageView
NSURL* imageNSURL = [NSURL URLWithString:value];
dispatch_async(
dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0),
^{
NSData* imageData = [[NSData alloc] initWithContentsOfURL:imageNSURL];
dispatch_async(
dispatch_get_main_queue(),
^{