Skip to content

Instantly share code, notes, and snippets.

Avatar

Justin Spahr-Summers jspahrsummers

View GitHub Profile
View ship.lua
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 Nov 2, 2011
Returning multiple values using blocks
View gist:1334548
// 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 Nov 10, 2011
Sketch of aspect-oriented programming in Objective-C
View aspects.m
/* 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 Jan 24, 2012
Macro for safer key-value coding
View gist:1670404
#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 Oct 2, 2015
AppKit classes not supporting weak references (on 10.7)
View gist:2268658
# 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 Apr 16, 2012
Guessing game written in LLVM assembly
View guessing-game.ll
; 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 Apr 20, 2012
An example of creating animated bindings, using PROBinding and Velvet animations
View VELAnimatedBinding.h
//
// VELAnimatedBinding.h
// Velvet
//
// Created by Justin Spahr-Summers on 01.04.12.
// Copyright (c) 2012 Bitswift. All rights reserved.
//
#import <Proton/Proton.h>
View EXTADTTest.m
#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
View gist:3068780
$ 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