This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
void (^myBlock)(int); | |
__block __weak __typeof__(myBlock) myRecursiveBlock = myBlock = ^(int x) { | |
if (x > 5) { | |
return; | |
} else { | |
myRecursiveBlock(x + 1); | |
} | |
}; | |
myBlock(1); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#import <Foundation/Foundation.h> | |
#import <libkern/OSAtomic.h> | |
@interface NSArray (ConcurrentMap) | |
- (NSArray*)semaphore_map:(id (^)(id))block; | |
- (NSArray*)serial_map:(id (^)(id))block; | |
- (NSArray*)spinlock_map:(id (^)(id))block; | |
@end | |
@implementation NSArray (ConcurrentMap) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
- (NSArray *)mapConcurrent; | |
{ | |
NSArray *originals = self.listOfObjects; | |
NSUInteger count = originals.count; | |
NSMutableArray *collected = [[NSMutableArray alloc] initWithCapacity:count]; | |
for (NSUInteger i = 0; i < count; i++) { | |
[collected addObject:[NSNull null]]; | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env casperjs | |
# | |
# Example: ./github-users.coffee Greenville | |
# | |
{Casper} = require 'casper' | |
class GitHubUserScraper extends Casper | |
USER_AGENT: 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_7_5) AppleWebKit/537.11 (KHTML, like Gecko) Chrome/23.0.1271.64 Safari/537.11' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
[[[signal | |
// Map YES to 1, NO to -1 | |
map:^(NSNumber* b) { | |
return @(b.boolValue ? 1 : -1); | |
}] | |
// Running sum of yes/1's and no/-1's | |
startWithScan:@0 combine:^(NSNumber* running, NSNumber* next) { | |
return @(running.intValue + next.intValue); | |
}] | |
// A 0-sum means equal number of YES/NO's; Map 0 to YES |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
module UncaughtThrowError | |
def self.===(ex) | |
ArgumentError === ex && ex.message =~ /uncaught throw/ | |
end | |
end | |
begin | |
throw :foo | |
rescue UncaughtThrowError | |
puts 'Success: Rescued UncaughtThrowError' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
CGRect CGRectIntegralScaledEx(CGRect rect, CGFloat scale) | |
{ | |
return CGRectMake(floorf(rect.origin.x * scale) / scale, floorf(rect.origin.y * scale) / scale, ceilf(rect.size.width * scale) / scale, ceilf(rect.size.height * scale) / scale); | |
} | |
CGRect CGRectIntegralScaled(CGRect rect) | |
{ | |
return CGRectIntegralScaledEx(rect, [[UIScreen mainScreen] scale]); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class AppDelegate | |
def application(application, didFinishLaunchingWithOptions:launchOptions) | |
a = NSEntityDescription.new | |
a.name = 'A' | |
b = NSEntityDescription.new | |
b.name = 'B' | |
bs = NSRelationshipDescription.new | |
bs.name = 'bs' | |
bs.destinationEntity = b | |
bs.ordered = true |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
framework 'CoreData' | |
# Create a minimal model | |
$thing = NSEntityDescription.alloc.init | |
$thing.name = 'Thing' | |
$model = NSManagedObjectModel.alloc.init | |
$model.entities = [$thing] | |
# Create the custom store class | |
class CustomStore < NSIncrementalStore |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class << Motion::Project::App | |
real_setup = instance_method(:setup) | |
define_method :setup do |&block| | |
real_setup.bind(self).call(&block) | |
# run after hook here | |
end | |
end |