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
// replace annoying boilerplate with declarative justice using FunctionalKit: | |
UITableViewCell *cell = [aTableView dequeueReusableCellWithIdentifier:CellIdentifier]; | |
if (cell == nil) { | |
cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleSubtitle reuseIdentifier:CellIdentifier] autorelease]; | |
} | |
// => | |
// nota bene: category on UITableView for convenient factory method is highly recommended. | |
id maybeCell = [[aTableView maybe] dequeueReusableCellWithIdentifier:CellIdentifier]; |
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
#include <stdio.h> | |
void addOne(int num); | |
void addOnePtr(int *num); | |
int main (int argc, const char * argv[]) { | |
int i = 3; // an int | |
printf("i == %d\n", i); | |
printf("&i == %p\n", &i); // reference/address-of operator & |
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
# A nifty class providing recursive graph generation | |
class Graph | |
def initialize(*args, &blk) | |
@edges = [] | |
@block = blk | |
@nodes = 0 | |
@inited = false | |
yield self, *args if block_given? | |
end | |
def init |
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
require "json" | |
require "zlib" | |
require "open-uri" | |
require "pp" | |
scores = Hash.new {|h,k| h[k] = [] } | |
for user in %w[13414 9388 9495 8318 4408 3117 219 292 13 5472 218] | |
print "Fetching page #{p}..." | |
response = JSON.parse Zlib::GzipReader.new(open("http://api.stackexchange.com/2.0/users/#{user}/answers?key=U4DMV*8nvpm3EOpvf69Rxw((&page=1&pagesize=35&fromdate=1331856000&todate=1333367940&order=desc&sort=votes&site=apple&filter=!b3Wz0N7mYj4b)3")).read |
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 "JTAsynchronousImageView.h" | |
@interface JTAsynchronousImageView () | |
@property (nonatomic, copy) void (^loadingBlock)(JTAsynchronousImageViewLoadCompletionHandler completionHandler); | |
@property (nonatomic, strong) void (^cancellationBlock)(); | |
@end | |
@implementation JTAsynchronousImageView { | |
// Queue for the image that is currently loading. | |
dispatch_queue_t _currentQueue; |
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
func bytes<T: UnsignedInteger>(val: T) -> GeneratorOf<UInt8> { | |
var current = val as UInt64 | |
var step = 0 | |
return GeneratorOf<UInt8> { | |
if step >= sizeof(T) { return nil } | |
current >>= 8; step++ | |
return UInt8(current & UInt64(UInt8.max)) | |
} | |
} |
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
func sift<T, S: Sequence where S.GeneratorType.Element == Optional<T>>(xs: S) -> GeneratorOf<T> { | |
var gen = xs.generate() | |
return GeneratorOf<T> { | |
var next: T?? | |
do { | |
next = gen.next() | |
if !next { return nil } | |
} while !(next!) | |
return next! | |
} |
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
// The free monoid | |
protocol Free { | |
class var ε: Self { get } | |
func +(lhs: Self, rhs: Self) -> Self | |
} | |
extension String: Free { | |
static var ε: String { return "" } | |
} |
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
[merge] | |
conflictstyle = diff3 | |
[alias] | |
b = branch | |
ci = commit | |
co = checkout | |
cp = cherry-pick | |
di = diff | |
ds = diff --stat | |
f = fetch -pt |
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
// Before realizing that NSFastGenerator exists... | |
func enumerate(c: NSFastEnumeration) -> SequenceOf<AnyObject> { | |
return SequenceOf<AnyObject> { () -> GeneratorOf<AnyObject> in | |
let bufSize = 16 | |
var objects = UnsafeMutablePointer<AnyObject?>.alloc(bufSize) | |
var state = NSFastEnumerationState() | |
var currentCount = 0 |
OlderNewer