Skip to content

Instantly share code, notes, and snippets.

View rnapier's full-sized avatar

Rob Napier rnapier

View GitHub Profile
@rnapier
rnapier / gist:2837909
Created May 30, 2012 17:49
Trying to ignore a property with SMXObject
MyObject *one = [[MyObject alloc] init];
one.message = @"Hello World!";
one.intValue = 1;
MyObject *two = [MyObject objectFromArchive:[one archivedObject]];
NSLog(@"Retrieved Message: %@", two.message);
NSLog(@"Should be 0, but is 1: %d", two.intValue);
@interface MyObject : SMXObject
@rnapier
rnapier / JuliaOperation.h
Created August 13, 2012 18:46
Demonstration of NSOperationQueue w/ and w/o maxCurrentOperations
#import <Foundation/Foundation.h>
#import <complex.h>
@interface JuliaOperation : NSOperation
@property (nonatomic, readwrite, assign) NSUInteger width;
@property (nonatomic, readwrite, assign) NSUInteger height;
@property (nonatomic, readwrite, assign) complex long double c;
@property (nonatomic, readwrite, assign) complex long double blowup;
@property (nonatomic, readwrite, assign) CGFloat contentScaleFactor;
@property (nonatomic, readwrite, assign) NSUInteger rScale;
@rnapier
rnapier / fix-xcode
Last active October 31, 2024 13:54
Links Xcode SDKs from the /SDKs directory (which you maintain yourself)
#!/usr/bin/python
# fix-xcode
# Rob Napier <[email protected]>
# Script to link in all your old SDKs every time you upgrade Xcode
# Create a directory called /SDKs (or modify source_path).
# Under it, put all the platform directories:
# MacOSX.platform iPhoneOS.platform iPhoneSimulator.platform
# Under those, store the SDKs:
all: test
testa: source.o libA.a libB.a
g++ source.cpp -o test libA.a libB.a
testb:
g++ source.cpp -o test libB.a libA.a
libA.a: a.o aprime.o
ar -r libA.a a.o aprime.o
@rnapier
rnapier / gist:7515273
Created November 17, 2013 16:38
Exploration of thread priorities vs queue priorities
// Main thread priorty = 0.758065
NSLog(@"main:%@:%f", [NSThread currentThread], [NSThread threadPriority]);
// High priority = 0.532258
dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_HIGH, 0), ^{
NSLog(@"high:%@:%f", [NSThread currentThread], [NSThread threadPriority]);
// run forever! Note that other queues still happily process, even though our high-priority block never ends
while(1) {}
});
@rnapier
rnapier / gist:8202731
Created December 31, 2013 22:10
Demonstrates that structs are not initialized under ARC. Run in Release.
int main(int argc, const char * argv[]) {
@autoreleasepool {
struct Stuff {
int x;
int y;
};
int x;
struct Stuff s;
printf("%d:%d\n", x, s.y);
@rnapier
rnapier / gist:8466934
Created January 17, 2014 01:31
Testing memory growth, optimized with standard Xcode settings (paste into Command Line app and hit Cmd-I)
#import <Foundation/Foundation.h>
int main(int argc, const char * argv[])
{
@autoreleasepool {
for(NSUInteger i = 0; i < 10000; i++)
{
for(NSUInteger j = 0; j < 10000; j++)
{
NSNumber* n = [NSNumber numberWithUnsignedInteger:j];
// Example for http://stackoverflow.com/questions/21699184/resource-leak-or-not-mac-os-x
#import <CoreServices/CoreServices.h>
#import <SystemConfiguration/SCDynamicStore.h>
#import <SystemConfiguration/SCDynamicStoreCopySpecific.h>
#include <iostream>
#include <thread>
void Execute()
{
// With dot syntax (and standard Xcode indentation, just hit "Cmd-I")
NSArray *tweets = Underscore.array(results)
.filter(Underscore.isDictionary)
.reject(^BOOL (NSDictionary *tweet) {
return [tweet[@"iso_language_code"] isEqualToString:@"en"];
})
.map(^NSString *(NSDictionary *tweet) {
NSString *name = tweet[@"from_user_name"];
NSString *text = tweet[@"text"];
func dispatch_sync<R> (queue: dispatch_queue_t, block: Void -> R ) -> R {
var result: R!
dispatch_sync(queue) {
result = block()
}
return result
}
func result() -> String {
return