Skip to content

Instantly share code, notes, and snippets.

Avatar

Rob Napier rnapier

View GitHub Profile
@rnapier
rnapier / gist:2837909
Created May 30, 2012
Trying to ignore a property with SMXObject
View gist:2837909
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 Aug 13, 2012
Demonstration of NSOperationQueue w/ and w/o maxCurrentOperations
View JuliaOperation.h
#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 May 14, 2021
Links Xcode SDKs from the /SDKs directory (which you maintain yourself)
View fix-xcode
#!/usr/bin/python
# fix-xcode
# Rob Napier <robnapier@gmail.com>
# 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:
View Makefile
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 Nov 17, 2013
Exploration of thread priorities vs queue priorities
View gist:7515273
// 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 Dec 31, 2013
Demonstrates that structs are not initialized under ARC. Run in Release.
View gist:8202731
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 Jan 17, 2014
Testing memory growth, optimized with standard Xcode settings (paste into Command Line app and hit Cmd-I)
View gist:8466934
#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];
View resource-leak-or-not-mac-os-x.cpp
// 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()
{
View underscore.m
// 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"];
View dispatch-sync-safe.swift
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