Skip to content

Instantly share code, notes, and snippets.

View robb's full-sized avatar

Robb Böhnke robb

View GitHub Profile
@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__
@steipete
steipete / PSPDFUIKitMainThreadGuard.m
Last active March 10, 2024 19:23
This is a guard that tracks down UIKit access on threads other than main. This snippet is taken from the commercial iOS PDF framework http://pspdfkit.com, but relicensed under MIT. Works because a lot of calls internally call setNeedsDisplay or setNeedsLayout. Won't catch everything, but it's very lightweight and usually does the job.You might n…
// Taken from the commercial iOS PDF framework http://pspdfkit.com.
// Copyright (c) 2014 Peter Steinberger, PSPDFKit GmbH. All rights reserved.
// Licensed under MIT (http://opensource.org/licenses/MIT)
//
// You should only use this in debug builds. It doesn't use private API, but I wouldn't ship it.
// PLEASE DUPE rdar://27192338 (https://openradar.appspot.com/27192338) if you would like to see this in UIKit.
#import <objc/runtime.h>
#import <objc/message.h>
@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')]
@evancz
evancz / Architecture.md
Last active December 21, 2022 14:28
Ideas and guidelines for architecting larger applications in Elm to be modular and extensible

Architecture in Elm

This document is a collection of concepts and strategies to make large Elm projects modular and extensible.

We will start by thinking about the structure of signals in our program. Broadly speaking, your application state should live in one big foldp. You will probably merge a bunch of input signals into a single stream of updates. This sounds a bit crazy at first, but it is in the same ballpark as Om or Facebook's Flux. There are a couple major benefits to having a centralized home for your application state:

  1. There is a single source of truth. Traditional approaches force you to write a decent amount of custom and error prone code to synchronize state between many different stateful components. (The state of this widget needs to be synced with the application state, which needs to be synced with some other widget, etc.) By placing all of your state in one location, you eliminate an entire class of bugs in which two components get into inconsistent states. We also think yo
@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))"
}
@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[*]}))]}";
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];
@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)]);
@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)
@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 {