Skip to content

Instantly share code, notes, and snippets.

@kylesluder
kylesluder / AutoNotifyTest.m
Last active August 29, 2015 13:55
A demonstration of an inefficiency in mutable array proxies that I think could be improved (rdar://problem/15966921)
// clang -framework Foundation -o AutoNotifyTest AutoNotifyTest.m
/***
Expected results:
willChange:valuesAtIndexes:forKey:
removeObjectFromBarAtIndex:
removeObjectFromBarAtIndex:
removeObjectFromBarAtIndex:
removeObjectFromBarAtIndex:
@kylesluder
kylesluder / cleanup.c
Created February 4, 2014 22:01
Neither of these runs the cleanup function
#include <stdio.h>
static void cleanup_func(int *foo)
{
printf("cleanup! %d\n", *foo);
}
int main(int argc, char **argv)
{
return 0;
@kylesluder
kylesluder / ObjCSuper.m
Last active August 29, 2015 13:56
An Objective-C analogue to the Python super class.
// % clang -framework Foundation -o ObjCSuper ObjCSuper.m SuperTrampoline.s
// % ./ObjCSuper
//
// 2014-02-15 23:03:32.498 ObjCSuper[1296:507] Subclass impl
// 2012014-02-15 23:03:32.498 ObjCSuper[1296:507] Subclass impl4-02-15 23:03:32.500 ObjCSuper[1296:507] b respondsToSelector:@selector(retain)? YES
// 2014-02-15 23:03:32.500 ObjCSuper[1296:507] b respondsToSelector:@selector(subclassMethod)? YES
// 2014-02-15 23:03:32.501 ObjCSuper[1296:507] Superclass impl
// 2014-02-15 23:03:32.501 ObjCSuper[1296:507] b_super respondsToSelector:@selector(retain)? YES
// 2014-02-15 23:03:32.501 ObjCSuper[1296:507] b_super respondsToSelector:@selector(subclassMethod)? NO
@kylesluder
kylesluder / WithoutFirst.swift
Created November 24, 2014 17:08
A version of dropFirst() that works on any SequenceType or GeneratorType
#!xcrun swift
func withoutFirst<T, G: GeneratorType where G.Element == T>(genGiver: () -> G) -> SequenceOf<T> {
return SequenceOf {
_ -> G in
var g = genGiver()
g.next()
return g
}
}
int main(int argc, char **argv)
{
return 0;
}
#import <Foundation/Foundation.h>
@interface Foo : NSObject
-(id)newFoo;
@end
#include <Foundation/Foundation.h>
@interface BusyWaiter : NSObject
{
BOOL _done;
}
- (void)markDone;
- (BOOL)isDone;
@end
shelve () {
local filename=${1:-shelf.patch}
if [[ -a $filename ]]; then
echo 1>&2 shelve: file "'$filename'" already exists
return 256
fi
svn diff | tee $filename | wc -l | read linecount && svn revert -R .
if [[ $linecount -eq 0 ]]; then
#import <Foundation/Foundation.h>
class CppClass
{
public:
void doIt();
}
;
@interface Foo : NSObject
@kylesluder
kylesluder / OQColor.m
Created October 19, 2010 00:08
Version of OQColorGetComponents that goes through a linear RGB color space
OQLinearRGBA OQGetColorComponents(NSColor *c)
{
static dispatch_once_t once;
static NSColorSpace *linearRGBColorSpace;
dispatch_once(&once, ^{
CGColorSpaceRef cgColorSpace = CGColorSpaceCreateWithName(kCGColorSpaceGenericRGBLinear);
linearRGBColorSpace = [[NSColorSpace alloc] initWithCGColorSpace:cgColorSpace];
CGColorSpaceRelease(cgColorSpace);
OBASSERT_NOTNULL(linearRGBColorSpace);
#import <Foundation/Foundation.h>
@protocol Foo
@property (readonly, nonatomic) int blah;
@end
typedef void (^bk)(void);
@interface Foo : NSObject<Foo>
{ int v; }
- (bk)makeBlock:(id<Foo>)otherFoo;