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
// Compile with clang -framework Foundation sethack.m | |
#import <Foundation/Foundation.h> | |
#import <objc/runtime.h> | |
/* | |
CFHashBytes from http://www.opensource.apple.com/source/CF/CF-1153.18/CFUtilities.c | |
*/ | |
#define ELF_STEP(B) T1 = (H << 4) + B; T2 = T1 & 0xF0000000; if (T2) T1 ^= (T2 >> 24); T1 &= (~T2); H = T1; |
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
//Given this: | |
NSArray *objects = @[@1, @2, @3] | |
//These are equivalent in behavior | |
NSNumber *first = [objects objectAtIndex:0] | |
NSNumber *second = (NSNumber *)CFArrayGetValueAtIndex(objects, 0) | |
//But is the code that runs the same? Not so much… in the first one we do… | |
objc_msgSend(objects, <selector reference>, 0) | |
-> http://sealiesoftware.com/msg/x86-mavericks.html |
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 | |
func measure(work:Void->Void) { | |
let start = NSDate() | |
for _ in 0..<100000 { | |
work() | |
} | |
let elapsed = -(start.timeIntervalSinceNow) | |
print(elapsed) | |
} |
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 "Controller.h" | |
#define ENABLE_INLINE | |
#ifdef ENABLE_INLINE | |
#define INLINE static inline | |
#else | |
#define INLINE | |
#endif | |
static inline int INDEX(char letter) { |
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/sbin/dtrace -q -s | |
/* | |
set(char *key, char *domain, char *user, char *host, char *container, char *value) | |
*/ | |
CFPreferences$target:::set { | |
printf("Set request at %Y ( key: %s, domain: %s, user:%s, host: %s, container: %s, value: %s)\n", walltimestamp, copyinstr(arg0), copyinstr(arg1), copyinstr(arg2), copyinstr(arg3), copyinstr(arg4), copyinstr(arg5)); | |
ustack(); | |
printf("\n\n\n"); | |
} |
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/sbin/dtrace -q -s | |
/* | |
CFPreferencesServer$target:::request { | |
printf("REQUEST from pid %d at %Y ( domain: %s, user: %s, host: %s, container: %s, managed: %d)\n", | |
arg0, | |
walltimestamp, | |
arg1 != NULL ? copyinstr(arg1) : "(NULL)", | |
arg2 != NULL ? copyinstr(arg2) : "(NULL)", | |
arg3 != NULL ? copyinstr(arg3) : "(NULL)", | |
arg4 != NULL ? copyinstr(arg4) : "(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
import Foundation | |
class Test | |
{ | |
func testing2(var x : Int) -> Int | |
{ | |
if x % 3 == 0 { | |
x += 10 | |
} | |
x++ |
NewerOlder