Skip to content

Instantly share code, notes, and snippets.

@CodaFi
CodaFi / BritKit.h
Created June 9, 2013 00:10
Quit complaining and @compatability_alias the crap out of "US" class names!
@compatability_alias UIColour UIColor
@compatability_alias NSNotificationCentre NSNotificationCenter
@compatability_alias NSDistributedNotificationCentre NSDistributedNotificationCenter
@compatability_alias NSUserNotificationCentre NSUserNotificationCenter
typedef NSWidthSizable NSWidthSizeable
typedef NSHeightSizable NSHeightSizeable
uint64_t CFISizeOfFilesAtPaths(NSArray *inArray) {
uint64_t accumulator = 0;
NSString *fileString = nil;
for (id file in inArray) {
if ([file isKindOfClass:NSString.class]) {
fileString = file;
} else if ([file isKindOfClass:NSURL.class]) {
fileString = [file path];
}
NSDictionary *fileAttributes = [NSFileManager.defaultManager attributesOfItemAtPath:fileString error:nil];
@CodaFi
CodaFi / REBConditionals.h
Last active December 21, 2015 05:09
Conditionalize execution according to various constraints about a device. All values compared against are "cached"
//
// REBConditionals.h
// Rebase
//
// Created by Robert Widmann on 8/16/13.
// Copyright (c) 2013 CodaFi. All rights reserved.
//
#ifndef Rebase_REBConditionals_h
#define Rebase_REBConditionals_h
@CodaFi
CodaFi / NUIColor.h
Last active June 16, 2021 22:31
Redoing NSColor for no reason whatsoever.
//
// NUIColor.h
// NUIKit
//
// Created by Robert Widmann on 9/21/13.
// Copyright (c) 2013 CodaFi. All rights reserved.
//
#import <Foundation/Foundation.h>
#import <CoreGraphics/CoreGraphics.h>
@CodaFi
CodaFi / CFIMultiMap.c
Last active December 24, 2015 12:59
A fully bridged multimap implementation.
/*
* Copyright (c) 2013 CodaFi. All rights reserved.
*
* @APPLE_LICENSE_HEADER_START@
*
* This file contains Original Code and/or Modifications of Original Code
* as defined in and that are subject to the Apple Public Source License
* Version 2.0 (the 'License'). You may not use this file except in
* compliance with the License. Please obtain a copy of the License at
* http://www.opensource.apple.com/apsl/ and read it before using this
@CodaFi
CodaFi / NUIBindingSeparator.h
Last active December 29, 2015 23:49
Bindings have been notoriously finicky to remove from objects, and this has led to a profusion of controller objects that wind up causing terrible retain cycles when they are bound to because they cannot release the bindings they have accumulated. This proxy takes care of the recording and management of bindings, but also KVO observances if nece…
//
// NUIBindingSeparator.h
// NUIKit
//
// Created by Robert Widmann on 8/31/13.
// Copyright (c) 2013 CodaFi. All rights reserved.
//
#import <Foundation/Foundation.h>
#if __has_feature(objc_arc)
@CodaFi
CodaFi / Main.hs
Created January 26, 2014 07:37
A very simple, very naïve, implementation of a Stack-based calculator language over integers with Haskell.
module Main where
import Control.Monad (forever)
import System.Exit (exitSuccess)
import Data.String
import Data.Char (isDigit)
data Stack a = Empty | Elem a (Stack a)
data OpCode = INT Int |
@CodaFi
CodaFi / critical_section.h
Created February 8, 2014 20:28
A macro for automatically locking and unlocking critical sections of code with OSSpinLocks.
/**
* Usage:
*
* static OSSpinlock lock;
*
* @critical_section(lock, ^{
* //Synchronized Section
* });
*
*/
@CodaFi
CodaFi / Algebra.pl
Last active January 2, 2021 11:14
Algebraic Laws in Prolog
% Introduce reflexive equality
refl(X, X).
% Introduce symmetrical equality
sym(X, Y) :-
refl(X, Y),
refl(Y, X).
% Identity of addition by zero
add_zero(N) :-
module Fin where
data Fin : ℕ → Set where
fzero : {n : ℕ} → Fin (succ n)
fsuc : {n : ℕ} → Fin n → Fin (succ n)
data ⊥ : Set where
empty : Fin zero → ⊥
empty ()