Skip to content

Instantly share code, notes, and snippets.

View robb's full-sized avatar

Robb Böhnke robb

View GitHub Profile
@hannestyden
hannestyden / post-checkout
Created October 28, 2010 11:26
Prints a random line from the bridge of Metallica's "Master of Puppets" when checking out the master branch.
#!/bin/sh
# .git/hooks/post-checkout
# chmod +x .git/hooks/post-checkout
if [ $(git symbolic-ref HEAD | cut -d '/' -f 3) == 'master' ]; then
lines[0]="Master, Master, where's the dreams that I've been after?"
lines[1]="Master, Master, you promised only lies"
lines[2]="Laughter, laughter, all I hear or see is laughter"
lines[3]="Laughter, laughter, laughing at my cries"
echo " ${lines[$((RANDOM%${#lines[*]}))]}";
@jspahrsummers
jspahrsummers / gist:1670404
Created January 24, 2012 14:22
Macro for safer key-value coding
#define ObjectKeyPath(OBJECT, KEYPATH) \
((void)(NO && ((void)OBJECT.KEYPATH, NO)), @ # KEYPATH )
NSString *str = @"foobar";
NSLog(@"%@", [str valueForKey:ObjectKeyPath(str, length)]);
@0xced
0xced / NSString.m
Created April 1, 2012 12:24
Reverse-engineered implementation of -[NSString isEqual:] and -[NSString isEqualToString:]
/*
* Most NSString instances will actually be __NSCFString instances, so here are both NSString and __NSCFString implementations.
* If you know how to create an NSString instance whose class is actually NSString please let me know.
* Other possible concrete subclasses of NSString are: NSConstantString, __NSCFConstantString, NSPathStore2, NSSimpleCString and __NSLocalizedString.
*/
// CoreFoundation.framework 635.19.0 (Mac OS X 10.7.3)
@implementation NSObject
- (BOOL) isNSString__
@hannestyden
hannestyden / ppjson.sh
Created April 18, 2012 14:07
New version of the old classic
ppjson () {
ruby -e "require 'json'; puts JSON.pretty_generate(JSON.parse(STDIN.read))"
}
[[[NSUserDefaultsController sharedUserDefaultsController] rac_subscribableForKeyPath:@"values.yourDefaultsKey" onObject:self] subscribeNext:(id x) {
// do the things
}];
@calimarkus
calimarkus / NSContainer+Subscripting.h
Created August 10, 2012 14:35
Objective-C Literals: Object Subscripting (LLVM 4.0) - ready to use in iOS 5 & 4!
//
// NSContainer+Subscripting.h
//
// Created by Markus Emrich on 10.08.12.
// Copyright 2012 nxtbgthng. All rights reserved.
//
#if !defined(__IPHONE_6_0) || __IPHONE_OS_VERSION_MIN_REQUIRED < __IPHONE_6_0
#import "NSContainer+Subscripting.h"
@streadway
streadway / uuid22.c
Created September 12, 2012 21:29
Example UUID in 22 bytes. Linux: `cc -luuid uuid22.c` Darwin: `cc uuid22.c`
#include <stdio.h>
#include <uuid/uuid.h>
#include <sys/types.h>
u_int64_t bits2uint64(unsigned char const bits[]) {
return ((u_int64_t)bits[0] << 56)
| ((u_int64_t)bits[1] << 48)
| ((u_int64_t)bits[2] << 40)
| ((u_int64_t)bits[3] << 32)
static NSInteger NSJSONReadingFuckNSNulls = (1UL << 3);
@implementation NSJSONSerialization (FuckNulls)
+ (void)load {
Method originalMethod = class_getClassMethod(self, @selector(JSONObjectWithData:options:error:));
IMP swizzledImplementation = imp_implementationWithBlock([^id (id _self, NSData *_data, NSJSONReadingOptions _opt, NSError **_error){
NSInputStream *stream = [NSInputStream inputStreamWithData:_data];
[stream open];
@phughes
phughes / image.py
Last active March 5, 2023 21:58
An Xcode precompilation script to turn your images into auto-completeable, type-checkable symbols.
import os.path as path
import string
import argparse
import glob
import re
def basename(filename):
base = filename
if filename.find('@2x') > 0:
base = filename[:filename.find('@2x')]
-- Close annoying notification windows that you can't Cmd+Tab to.
-- From: http://www.mentby.com/stockly-ed/window-watcher.html
tell application "System Events"
try
set unc to application process "UserNotificationCenter"
activate unc
set uncw to window 1 of unc
repeat with label in {"OK", "Close", "Ignore", "Cancel"}
try