Skip to content

Instantly share code, notes, and snippets.

Copyright (c) 2011-2013 Ole Petter Bang <olepbang@gmail.com>
Permission is hereby granted, free of charge, to any person obtaining
a copy of this software and associated documentation files (the
'Software'), to deal in the Software without restriction, including
without limitation the rights to use, copy, modify, merge, publish,
distribute, sublicense, and/or sell copies of the Software, and to
permit persons to whom the Software is furnished to do so, subject to
the following conditions:
@Coneko
Coneko / gist:5884356
Last active December 19, 2015 02:38
[<Test 0x1002120d0> setNilValueForKey]: could not set nil as the value for the key primitive.
#import <Foundation/Foundation.h>
#import <ReactiveCocoa/ReactiveCocoa.h>
@interface Test : NSObject
@property (nonatomic, strong) Test *object;
@property (nonatomic) NSUInteger primitive;
@end
@implementation Test
@end
@Coneko
Coneko / main.mm
Created January 8, 2013 23:51
Testing -[RACScheduler scheduleRecursiveBlock:]'s memory consumption.
#import <Foundation/Foundation.h>
#import <ReactiveCocoa/ReactiveCocoa.h>
@interface CountUpToXEnumerator : NSEnumerator
+ (instancetype)countUpTo:(NSUInteger)x;
@end
@implementation CountUpToXEnumerator {
@Coneko
Coneko / gist:4234842
Created December 7, 2012 17:24
How to get your code to run on different cores in OSX / iOS without CHUD.
#import <pthread.h>
#import <mach/thread_act.h>
// These two functions are declared in mach/thread_policy.h, but are commented out.
// They are documented here: https://developer.apple.com/library/mac/#releasenotes/Performance/RN-AffinityAPI/_index.html
kern_return_t thread_policy_set(
thread_t thread,
thread_policy_flavor_t flavor,
thread_policy_t policy_info,
mach_msg_type_number_t count);
@Coneko
Coneko / gist:4234770
Created December 7, 2012 17:12
How to check what core your code is running on.
// The x86 cpuid instruction gives information about the processor
static inline void cpuid(uint32_t code, uint32_t data[4]) {
asm volatile("cpuid":"=a"(*data),"=b"(*(data+1)),
"=c"(*(data+2)),"=d"(*(data+3)):"a"(code));
}
// Gets the APIC ID of the processor. Returns a unique identifier for each core.
static inline uint8_t apic_id(void) {
uint32_t data[4];
cpuid(1, data);
@Coneko
Coneko / gist:4156996
Created November 27, 2012 21:03
+combineLatest:reduce: serialization issue.
for(id<RACSignal> signal in signals) {
RACDisposable *disposable = [signal subscribe:[RACSubscriber subscriberWithNext:^(id x) {
@synchronized(lastValues) {
[lastValues setObject:x ? : [RACTupleNil tupleNil] forKey:[NSString stringWithFormat:@"%p", signal]];
if(lastValues.count == signals.count) {
NSMutableArray *orderedValues = [NSMutableArray arrayWithCapacity:signals.count];
for(id<RACSignal> o in signals) {
[orderedValues addObject:[lastValues objectForKey:[NSString stringWithFormat:@"%p", o]]];
@Coneko
Coneko / gist:4019491
Created November 5, 2012 18:39
-repeat band-aid
describe(@"-repeat", ^{
__block id<RACSubscribable> subscribable = nil;
beforeEach(^{
subscribable = [RACSubscribable createSubscribable:^RACDisposable *(id<RACSubscriber> subscriber) {
[subscriber sendNext:nil];
[subscriber sendCompleted];
return nil;
}];
});
@Coneko
Coneko / gist:4017177
Created November 5, 2012 13:28
(Not a really good) use of RACStashSubject
- (instancetype)initWithURL:(NSURL *)url type:(NSString *)type {
self = [super initWithURL:url type:type];
if (!self) {
return nil;
}
_contentBacking = [RACReplaySubject replaySubjectWithCapacity:1];
NSError *error;
NSString *content = [NSString stringWithContentsOfURL:url encoding:NSUTF8StringEncoding error:&error];
if (!error) {
[_contentBacking sendNext:content];
@Coneko
Coneko / build.js
Created August 18, 2012 23:29
r.js failing to optimize OpenLayers
({
name: "almond",
out: "main-built.js",
include: ["main"],
insertRequire: ["main"],
wrap: true, // This is the crucial option
mainConfigFile: "main.js",
optimize: "none"
})