Skip to content

Instantly share code, notes, and snippets.

View nst's full-sized avatar

Nicolas Seriot nst

View GitHub Profile
@mikeash
mikeash / test.m
Created July 9, 2012 21:15
Cocoa array slicing
// clang -framework Foundation -fobjc-arc -O3 test.m
#import <Foundation/Foundation.h>
@interface Slice : NSObject
@property NSInteger start;
@property NSInteger length;
@end
@implementation Slice
@0xced
0xced / NSURLCacheCrash.m
Created August 10, 2012 09:37
Yet another NSURLCache bug
/*
This crashes (usually after the first log, but not 100% reliable) on at least iOS 4.3, 5.0 and 5.1
(lldb) bt
* thread #1: tid = 0x1c03, 0x36d60e58 CoreFoundation`CFRetain + 20, stop reason = EXC_BAD_ACCESS (code=1, address=0xe0000000)
frame #0: 0x36d60e58 CoreFoundation`CFRetain + 20
frame #1: 0x33927248 CFNetwork`__CFURLCache::CopyResponseForRequest(_CFURLRequest const*, bool) + 116
frame #2: 0x339271cc CFNetwork`_ZL34__CFURLCacheCopyResponseForRequestPK11_CFURLCachePK13_CFURLRequestb + 48
frame #3: 0x33927e5c CFNetwork`CFURLCacheCopyResponseForRequest + 24
frame #4: 0x32a7487e Foundation`-[NSURLCache cachedResponseForRequest:] + 66
frame #5: 0x0006963c NSURLCacheCrash`main + 504 at main.m:28
@lilyball
lilyball / gist:3391903
Created August 19, 2012 04:19
+[NSObject cast:]
@interface NSObject (Cast)
+ (instancetype)cast:(id)from;
@end
@implementation NSObject (Cast)
+ (instancetype)cast:(id)from {
if ([from isKindOfClass:self]) {
return from;
}
return nil;
@iamleeg
iamleeg / pre-commit.sh
Last active December 11, 2015 15:18
A quick and dirty pre-commit hook to let me flag code that shouldn't be committed.
#!/bin/bash
git diff --cached -SNSLog --quiet
if [ $? -eq 1 ]; then
echo "NSLog call detected, indicating debug code is staged. Please unstage your debug code."
exit 1
fi
exit 0
@ZweiSteinSoft
ZweiSteinSoft / push_destinations.json
Created February 7, 2013 19:49
/account/push_destinations endpoint, API 1.0
{
"available_levels": 1021,
"environment": 3,
"udid": "FC9C22DC-0301-4421-A26A-2DB95985B962",
"enabled_for": 5,
"created_at": "Thu Jan 03 17:25:48 +0000 2013",
"display": 7,
"lang": null,
"id": 1736398994,
"token": "buWWQDx46io1\/1jFRphV4gH9YjrqnhUmWehQ5gF267I=",
@steipete
steipete / AppDelegate.m
Last active December 13, 2015 17:29
Hook onto NSNotificationCenter to see all notifications.
[[NSNotificationCenter defaultCenter] addObserverForName:nil object:nil queue:nil usingBlock:^(NSNotification *note) {
NSLog(@"%@: %@", note.name, note.userInfo);
}];
@iamleeg
iamleeg / gist:5290797
Last active December 15, 2015 16:39
Creating objects on the stack in Objective-C
#import <Foundation/Foundation.h>
#include <stdlib.h>
#include <objc/runtime.h>
@interface A : NSObject
@property (assign) int meaning;
@end
@implementation A
@sburlot
sburlot / gist:5328122
Created April 6, 2013 23:34
Add a Run Script phase to your Xcode project and add this script to detect if you use autolayout in your 5.x target
#!/usr/bin/perl
#
# Check if we're running for 5.1 deployment and any .xib view has autolayout on.
#
use File::Find qw(find);
my $deployment = $ENV{'IPHONEOS_DEPLOYMENT_TARGET'};
my $project_dir = $ENV{'PROJECT_DIR'};
print "Deploy to $deployment\n";
@0xabad1dea
0xabad1dea / tricksy.c
Last active December 17, 2015 14:59
A deceitful C program
// hello clever programmers, would you like to play a game?
// where's the bug?
// by 0xabad1dea :)
#include <stdio.h>
#include <string.h>
int main() {
char input[16] = "stringstring!!!";
char output[8];
@campoy
campoy / wat.js
Created September 13, 2013 17:28
What do you think this will log?
var foo = 1;
func bar() {
if (!foo) {
var foo = 10;
}
console.log(foo);
}
bar();