Skip to content

Instantly share code, notes, and snippets.

@joslinm
joslinm / gist:5341452
Created April 8, 2013 23:19
basic objc/runtime usage
#define KEY @"key"
// Set vaulue as a property of obj
id obj = [NSObject alloc] init]
id value = [[NSObject alloc] init]
objc_setAssociatedObject(obj, KEY, value, OBJC_ASSOCIATION_RETAIN_NONATOMIC);
// Get that same value from object
id value = objc_getAssociatedObject(obj, KEY)
@joslinm
joslinm / gist:5341352
Last active December 15, 2015 23:38
view tagging to get user's property
//
// BFViewController.m
// ObjcRuntimeExample
//
// Created by Mark Joslin on 3/26/13.
// Copyright (c) 2013 BitFountain. All rights reserved.
//
#import <objc/runtime.h>
#import "BFTableViewControler.h"
@joslinm
joslinm / objc_runtime_example.mm
Last active December 15, 2015 11:18
<objc/runtime.h> example
//
// BFViewController.m
// ObjcRuntimeExample
//
// Created by Mark Joslin on 3/26/13.
// Copyright (c) 2013 BitFountain. All rights reserved.
//
#import <objc/runtime.h>
#import "BFTableViewControler.h"
@joslinm
joslinm / gist:4742760
Created February 8, 2013 23:18
Websocket-rack closing errors
^C>> Stopping ...
[[:unbind, :connection]]
Closing..
[[:error, #<NoMethodError: undefined method `empty?' for nil:NilClass>]]
Got error: undefined method `empty?' for nil:NilClass
[[:closing, 1000]]
[[:sending_frame, :close, "\x03\xE8"]]
@joslinm
joslinm / gist:4137210
Created November 23, 2012 20:45
Naive quicksort implementation
less_than(List, Pivot) ->
less_than(List, Pivot, []).
less_than([], Pivot, Acc) ->
Acc;
less_than([H|T], Pivot, Acc) when H < Pivot ->
less_than(T, Pivot, [H|Acc]);
less_than([H|T], Pivot, Acc) when H >= Pivot ->
less_than(T, Pivot, Acc).