Skip to content

Instantly share code, notes, and snippets.

View iamleeg's full-sized avatar
📬
New mailing list for software engineering discussion: https://sicpers.curated.co

Graham Lee iamleeg

📬
New mailing list for software engineering discussion: https://sicpers.curated.co
View GitHub Profile
@iamleeg
iamleeg / sillyloop.m
Last active December 23, 2015 23:59
You probably don't need to tell me that this is a bad idea.
#import <Foundation/Foundation.h>
typedef NS_ENUM(int, GJLRangeDirection) {
GJLRangeDirectionPositive,
GJLRangeDirectionNegative,
};
@interface GJLRange : NSEnumerator
+ (instancetype)rangeWithStart: (NSNumber *)start end: (NSNumber *)end step: (NSNumber *)step;
@iamleeg
iamleeg / gist:5644043
Last active December 17, 2015 17:09
Thoughts on how prototypical inheritance might be done in Objective-C. Notice that the Étoilé runtime (the predecessor to the GNUstep runtime) actually supports such things anyway.
#import <Foundation/Foundation.h>
#import <objc/runtime.h>
@interface A : NSObject
- (void)createPrivateSubclass;
@end
int main(int argc, char *argv[])
{
@autoreleasepool
@iamleeg
iamleeg / CPPHack.mm
Created May 8, 2013 12:23
Creating objects on the stack, ObjC++ style.
@interface GLObject : NSObject
{
int _a;
}
- (void)logA;
@end
struct GLObject_cpp {
@iamleeg
iamleeg / class_addCategory.mm
Created April 22, 2013 12:22
Somewhat-safely add "category" methods to a class, only if they don't already exist.
//
// main.m
// DynamicCategories
//
// Created by Graham Lee on 22/04/2013.
// Copyright (c) 2013 Graham Lee.
//Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
//
//The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
@iamleeg
iamleeg / gist:5290797
Last active December 15, 2015 16:39
Creating objects on the stack in Objective-C
#import <Foundation/Foundation.h>
#include <stdlib.h>
#include <objc/runtime.h>
@interface A : NSObject
@property (assign) int meaning;
@end
@implementation A
@iamleeg
iamleeg / pre-commit.sh
Last active December 11, 2015 15:18
A quick and dirty pre-commit hook to let me flag code that shouldn't be committed.
#!/bin/bash
git diff --cached -SNSLog --quiet
if [ $? -eq 1 ]; then
echo "NSLog call detected, indicating debug code is staged. Please unstage your debug code."
exit 1
fi
exit 0
@iamleeg
iamleeg / RunMyTests.sh
Created December 5, 2012 19:30
Convincing OCUnit that it _is_ allowed to run unit tests from the command line.
#!/bin/bash
export DEVELOPER_DIR="`xcode-select -print-path`"
export DEVELOPER_TOOLS_DIR="${DEVELOPER_DIR}/Tools"
export DEVELOPER_LIBRARY_DIR="${DEVELOPER_DIR}/Platforms/iPhoneSimulator.platform/Developer/Library"
export ACTION="build"
export TEST_AFTER_BUILD="yes"
export PLATFORM_DEVELOPER_TOOLS_DIR="${DEVELOPER_DIR}/Platforms/iPhoneSimulator.platform/Developer/Tools"
export SDKROOT="${DEVELOPER_DIR}/Platforms/iPhoneSimulator.platform/Developer/SDKs/iPhoneSimulator6.0.sdk/"
export TEST_HOST="${PWD}/build/Debug-iphonesimulator/MyProduct.app/MyProduct"
2012-11-10T15:26:15+00:00 heroku[router]: Error H10 (App crashed) -> POST iamleeg-vulcan.herokuapp.com/make dyno= queue= wait= service= status=503 bytes=
2012-11-10T14:04:50+00:00 heroku[web.1]: Starting process with command `bin/web`
2012-11-10T14:04:52+00:00 app[web.1]: at Object.run (/app/node_modules/coffee-script/lib/coffee-script/coffee-script.js:79:25)
2012-11-10T14:04:52+00:00 app[web.1]: at Object.<anonymous> (/app/web.coffee:22:28)
2012-11-10T14:04:52+00:00 app[web.1]: at /app/node_modules/coffee-script/lib/coffee-script/command.js:175:29
2012-11-10T14:04:52+00:00 app[web.1]: at Object.<anonymous> (/app/web.coffee:121:4)
2012-11-10T14:04:52+00:00 app[web.1]: at Object.urlParse [as parse] (url.js:92:11)
2012-11-10T14:04:52+00:00 app[web.1]: at Module._compile (module.js:446:26)
2012-11-10T14:04:52+00:00 app[web.1]: at Object.connect (/app/lib/cloudant.coffee:10:22)
2012-11-10T14:04:52+00:00 app[web.1]: TypeError: Parameter 'url' must be a string, not undefined
2012-11-10T14:04:52+00:00 app[web.1]: at [object Object].emit (events.js:64:17)
$ vulcan build -c "PREFIX=/opt/libobjc2; mkdir $PREFIX; make" -p /opt/libobjc2 -v -o "$TMPDIR/libobjc2.tgz"
Packaging local directory... done
Uploading source package... <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html>
<head>
<meta http-equiv="content-type" content="text/html; charset=ISO-8859-1">
<style type="text/css">
html, body, iframe { margin: 0; padding: 0; height: 100%; }
iframe { display: block; width: 100%; border: none; }
</style>