Skip to content

Instantly share code, notes, and snippets.


Andrew Pouliot darknoon

View GitHub Profile
View Who implements?
@interface A : NSObject
- (void)doSomething;
@implementation A
- (void)doSomething;
darknoon / burst.vsh
Created Jun 17, 2011
Antialiased burst from color stripes
View burst.vsh
//Declare a 2D texture as a uniform variable
uniform sampler2D texture;
uniform float samples;
void main()
vec2 poissonDisk[8];
poissonDisk[0] = vec2(-0.613392, 0.617481);
darknoon / gist:4482025
Created Jan 8, 2013
Safe KVC macro by Andrew Pouliot. In the public domain.
View gist:4482025
//o is an object type, k is the key on which to check validity
//returns a NSString constant of the relevant key
#define KVC(o, k) (0 && sizeof(o.k) ? @#k : @#k)
ObjectWithMethodCalledKeyName *object = ...;
[object addObserver:self forKeyPath:KVC(object, keyName) options:0 context:NULL];
View kdebug-minimal.h
#define DBG_MACH_CHUD 0x0A
#define DBG_FUNC_START 1
#define DBG_FUNC_END 2
#define DBG_APPS 33
#define KDBG_CODE(Class, SubClass, code) (((Class & 0xff) << 24) | ((SubClass & 0xff) << 16) | ((code & 0x3fff) << 2))
#define APPSDBG_CODE(SubClass,code) KDBG_CODE(DBG_APPS, SubClass, code)
darknoon / OutlineView.m
Last active Sep 6, 2016
This is the simplest way I could figure out how to make a view-based NSOutlineView
View OutlineView.m
@interface AppDelegate : NSObject <NSApplicationDelegate, NSOutlineViewDataSource, NSOutlineViewDelegate>
@implementation AppDelegate {
NSWindow *_w;
NSDictionary *_data;
- (void)_setValue:(CGFloat)value forAnimatedKey:(NSString *)animationKey
POPSpringAnimation *ps = [self pop_animationForKey:animationKey];
if (!ps) {
ps = [POPSpringAnimation animation]; = [POPAnimatableProperty propertyWithName:animationKey initializer:^(POPMutableAnimatableProperty *prop) {
prop.readBlock = ^(DEViewerView *view, CGFloat *vs) {
vs[0] = [[view valueForKey:animationKey] floatValue];
prop.writeBlock = ^(DEViewerView *view, const CGFloat *vs) {
darknoon / classWithIvar.cocoascript.js
Last active Jul 31, 2018
You can use ivars so you don't need to make so many hilarious classes
View classWithIvar.cocoascript.js
// Make a class with some handlers.
function Class(handlers){
var uniqueClassName = "fetchDelegate_" + NSUUID.UUID().UUIDString();
var cls = MOClassDescription.allocateDescriptionForClassWithName_superclass_(uniqueClassName, NSObject);
// Add each handler to the class description
for(var selectorString in handlers) {
var sel = NSSelectorFromString(selectorString);
cls.addInstanceMethodWithSelector_function_(sel, handlers[selectorString]);
// Add ivar to store instance-specific info
darknoon / whatthe.cocoascript.js
Created Mar 22, 2017
JSON.stringify doesn't really work on NSDictionary plist types does it…
View whatthe.cocoascript.js
const colorList = {
Haus: '#F3F4F4',
Night: '#333',
Sur: '#96DBE4',
'Sur Dark': '#24828F',
Peach: '#EFADA0',
'Peach Dark': '#E37059',
Pear: '#93DAAB',
'Pear Dark': '#2E854B',
darknoon / ObjCClass.cocoascript.js
Created Mar 23, 2017
A little bit disgusting, but you can totally create classes with ivars in cocoa script :D
View ObjCClass.cocoascript.js
// Copy-paste this into 💎 and run it 🔥
// Scroll to bottom for usage
// Use any C function, not just ones with BridgeSupport
function CFunc(name, args, retVal) {
// Due to particularities of the JS bridge, we can't call into MOBridgeSupport objects directly
// But, we can ask key value coding to do the dirty work for us ;)
function setKeys(o, d) {
const funcDict = NSMutableDictionary.dictionary()
funcDict.o = o
darknoon / createStructure.cocoascript.js
Created Mar 24, 2017
Create any arbitrary structure when you don't have a constructor exported for it
View createStructure.cocoascript.js
// Recursively create a struct
function makeStruct(def) {
if (typeof def !== 'object') {
return def;
const name = Object.keys(def)[0];
const values = def[name];
const structure = MOStruct.structureWithName_memberNames_runtime(name, Object.keys(values), null);