Skip to content

Instantly share code, notes, and snippets.

View indragiek's full-sized avatar

Indragie Karunaratne indragiek

View GitHub Profile
@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
@josh-
josh- / JPAppDelegate.m
Created April 23, 2014 03:46
NSMenu Services Example
@implementation JPAppDelegate
- (void)applicationDidFinishLaunching:(NSNotification *)aNotification
{
[NSApp registerServicesMenuSendTypes:[NSArray arrayWithObjects:NSStringPboardType, nil] returnTypes:[NSArray arrayWithObjects:nil]];
[self updateMenu];
}
#pragma mark - Services
@0xced
0xced / uncruftapidiff.m
Created June 18, 2014 22:17
Uncruft iOS 8.0 and OS X 10.10 API diffs
//
// Copyright (c) 2014 Cédric Luthi “0xced”
//
// ./uncruftapidiff https://developer.apple.com/library/prerelease/ios/releasenotes/General/iOS80APIDiffs/index.html iOS8_0APIDiffs.html
// ./uncruftapidiff https://developer.apple.com/library/prerelease/mac/documentation/General/Reference/APIDiffsMacOSX10_10SeedDiff/index.html OSX10_10APIDiffs.html
//
#import <Foundation/Foundation.h>
#import <sysexits.h>
@ka-interview
ka-interview / gist:a6478004c6cee552f225
Created October 14, 2014 23:57
Sketch of type safe, non-AnyObject-supporting data source
public protocol CountableCollectionType: CollectionType {
var count: Int { get }
}
extension Array: CountableCollectionType {}
public protocol CollectionViewCellFactoryType {
typealias Item
typealias Cell: UICollectionViewCell
func cellForItem(item: Item, inCollectionView collectionView: UICollectionView, atIndexPath indexPath: NSIndexPath) -> Cell
anonymous
anonymous / NSStringVariations.m
Created February 18, 2015 08:32
#import <Foundation/Foundation.h>
int main(int argc, const char * argv[]) {
@autoreleasepool {
void (^benchmark)(const char *str) = ^(const char *str) {
const long count = 10000000;
NSDate *start = [NSDate date];
for (long i = 0; i < count; i++) {
(void)[[NSString alloc] initWithUTF8String:str];
}
#!/bin/bash
target_name="foo" # Remember to set your name here
target_email="foo@example.com" # Set the new email here
git filter-branch --commit-filter 'if [ "$GIT_AUTHOR_NAME" = $target_name ];
then export GIT_AUTHOR_EMAIL=$target_email;
fi; git commit-tree "$@"'
@stigi
stigi / gist:966511
Created May 11, 2011 14:09
Flipping Coordinates
CGPoint CGPointFlipped(CGPoint point, CGRect bounds) {
return CGPointMake(point.x, CGRectGetMaxY(bounds)-point.y);
}
CGRect CGRectFlipped(CGRect rect, CGRect bounds) {
return CGRectMake(CGRectGetMinX(rect),
CGRectGetMaxY(bounds)-CGRectGetMaxY(rect),
CGRectGetWidth(rect),
CGRectGetHeight(rect));
}
@wearhere
wearhere / whatsabool.m
Created August 29, 2012 00:33
Boolean literals are only sometimes of type BOOL.
- (void)testBooleanLiteralsAreOfTypeBool {
NSNumber *testBoolNumber = @YES;
const char *typeString = [testBoolNumber objCType];
STAssertTrue('c' == *typeString, @"Boxed BOOL is of type %s, not of type 'c' (signed char, aka BOOL).", typeString);
}
- (void)testBoxedBooleanLiteralsAreOfTypeBool {
// Boxing works fine if a BOOL value is boxed directly...
BOOL testBool = YES;
NSNumber *testBoolNumber = @(testBool);
@jspahrsummers
jspahrsummers / gist:3780283
Created September 25, 2012 13:26
Figuring out the object that a non-string, compiler-verified key path refers to
// doesn't work with __block variables
#define keypath2(PATH) \
do { \
const char *_path = strchr(# PATH, '.') + 1; \
\
id _capturingBlock = ^{ \
return PATH; \
}; \
\
struct _literal { \
@shepting
shepting / NodeTraversal.swift
Last active November 24, 2015 22:55
Print out a tree of nodes with multiple children each.
//
// main.swift
// NodeTraversal
//
// Created by Steven Hepting on 11/16/15.
// Copyright © 2015 Steven Hepting. All rights reserved.
// Algorithm from http://bit.ly/1kSdSvc
//
import Foundation