Skip to content

Instantly share code, notes, and snippets.

View jspahrsummers's full-sized avatar

Justin Spahr-Summers jspahrsummers

View GitHub Profile
local ship = { entropy.loadtexture("data/ships/fighter/base.png") }
local glow = { entropy.loadtexture("data/ships/fighter/glow.png") }
local lights = { entropy.loadtexture("data/ships/fighter/lights.png") }
function shutdown ()
entropy.deletetexture(ship[1])
entropy.deletetexture(glow[1])
entropy.deletetexture(lights[1])
end
@jspahrsummers
jspahrsummers / gist:1334548
Created November 2, 2011 19:03
Returning multiple values using blocks
// only works with object types, but such is Cocoa
typedef id (^generator)(void);
- (generator)methodReturningMultipleValues {
__block int value = 0;
return ^{
switch (value++) {
case 0:
return [NSNumber numberWithInt:5];
@jspahrsummers
jspahrsummers / aspects.m
Created November 10, 2011 05:49
Sketch of aspect-oriented programming in Objective-C
/* Logger.m */
@aspect Logger
// called for any selector
- (void)before {
// '_cmd' is special -- the selector for the actual method with the advice
// applied to it
NSLog(@"starting -[%@ %@]", self, _cmd);
}
// only called for 'deposit:'
@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)]);
@jspahrsummers
jspahrsummers / gist:2268658
Last active October 2, 2015 15:28
AppKit classes not supporting weak references (on 10.7)
# In a class-dump of AppKit:
$ ack -l '\)(retain|release);' . | awk -F '.' '{ print $1 }'
__NSATSStringSegment
__NSFontTypefaceInfo
__NSSharedFontInstanceInfo
_NSCachedAttributedString
_NSStateMarker
NSATSGlyphStorage
NSATSTypesetter
@jspahrsummers
jspahrsummers / guessing-game.ll
Created April 16, 2012 18:44
Guessing game written in LLVM assembly
; run this with one of the following:
;
; lli guessing-game.ll
; llc guessing-game.ll && clang -o guessing-game guessing-game.s && ./guessing-game
;
; note: you may need to 'brew install llvm' first
; type representing a FILE handle in C (like stdin)
%FILE = type opaque
@jspahrsummers
jspahrsummers / VELAnimatedBinding.h
Created April 20, 2012 23:16
An example of creating animated bindings, using PROBinding and Velvet animations
//
// VELAnimatedBinding.h
// Velvet
//
// Created by Justin Spahr-Summers on 01.04.12.
// Copyright (c) 2012 Bitswift. All rights reserved.
//
#import <Proton/Proton.h>
#1 "Tests/EXTADTTest.m"
#1 "Tests/EXTADTTest.m" 1
#1 "<built-in>" 1
#1 "<built-in>" 3
#152 "<built-in>" 3
#1 "<command line>" 1
#1 "<built-in>" 2
#1 "Tests/EXTADTTest.m" 2
$ make repl
=> (NSLog "%@" 5)
2012-07-07 04:33:01.074 a.out[65142:303] 5
=> (def print (fn [str] (NSLog "%@" str) nil))
2012-07-07 17:33:31.414 a.out[15035:303] 5
=> (print "foobar")
2012-07-07 17:33:31.414 a.out[15035:303] 5