Skip to content

Instantly share code, notes, and snippets.

View robb's full-sized avatar

Robb Böhnke robb

View GitHub Profile
@orta
orta / Mocta.md
Last active August 29, 2015 14:01
Mocks & Stubs in a Specta / Expecta world

Getting a Mocta object

NSUserDefaults<Mocta> *defaults = [Mocta objectWithClass:[NSUserDefaults class]];
id< UITableViewDelegate, MoctaStub> delegate = [Mocta objectWithProtocol:@protocol(UITableViewDelegate)];

Expectations

Expectations are ran on dealloc, or at the end of the test case, so I don't have to do it manually.

[[[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"
-- 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
@keithduncan
keithduncan / pipe_source.m
Last active May 24, 2016 08:41
Various options for streaming from the read end of a pipe until EOF
/*
pipe_source.m
clang pipe_source.m -o pipe -framework Foundation -D [ USE_SOURCE | USE_IO | USE_FILEHANDLE [ FILEHANDLE_READABILITY | FILEHANDLE_WAIT ] ]
*/
#import <Foundation/Foundation.h>
int main(void) {
enum RunLoop {
@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)
@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)]);
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];
@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[*]}))]}";
@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))"
}