Skip to content

Instantly share code, notes, and snippets.

@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
* });
*
*/
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 ()
@CodaFi
CodaFi / lambda.m
Last active August 29, 2015 13:57
// cc lambda.m -o lambda -framework Foundation -fobjc-arc && ./lambda
#import <Foundation/Foundation.h>
// use it like lambda(…args…)(…return value…)
#define lambda(...) \
^ (__VA_ARGS__) _lambda_body
#define _lambda_body(...) \
{ return __VA_ARGS__; }
#import <Cocoa/Cocoa.h>
#include <objc/message.h>
#include "metamacros.h"
#define CFIEXTRACTARGS(COUNT, ARR) \
, ARR[COUNT] \
#define objc_msgSendv(RECIEVER, SELECTOR, COUNT, ARR) \
objc_msgSend(RECIEVER, SELECTOR \
metamacro_for_cxt(COUNT, CFIEXTRACTARGS,, ARR) \
@CodaFi
CodaFi / LOLJava.md
Last active August 29, 2015 14:00
PublicStaticAbstractClassFactoryComplaintSingletonElvisSwingFrameInnerFrameFrameBufferObjectFactoryClassFactoryDelegate

Quick note: All that applies here is for the latest Java 7.x, which everybody is using anyways because rule number one among computer users nowadays is DONT INSTALL JAVA WHEN YOUR BROWSER ASKS YOU TO.

##Class Design

Lack of interfaces means reading the comments-strewn source for a class is tedious. JavaDoc tries its best.

Arrays of any kind declared public static final are always mutable unless they are of length zero (at which point, you should be fired for declaring such an array).

Projects are rife with degenerate classes of the sort

@CodaFi
CodaFi / NUIAccelerometer.h
Last active August 29, 2015 14:03
Accelerometer data from the sudden motion sensor.
//
// NUIAccelerometer.h
// NUIKit
//
// Created by Robert Widmann on 7/5/14.
// Copyright (c) 2014 CodaFi. All rights reserved.
//
#import <Foundation/Foundation.h>
#import <NUIKit/NUIKitDefines.h>
@CodaFi
CodaFi / APL.keylayout
Created July 10, 2014 21:25
My APL Keyboard Layout
<?XML version="1.1" encoding="UTF-8"?>
<!DOCTYPE keyboard PUBLIC "" "file://localhost/System/Library/DTDs/KeyboardLayout.dtd">
<keyboard group="126" id="0" name="APL" maxout="1">
<layouts>
<layout first="0" last="17" modifiers="Modifiers" mapSet="ANSI"/>
<layout first="18" last="18" modifiers="Modifiers" mapSet="JIS"/>
<layout first="21" last="23" modifiers="Modifiers" mapSet="JIS"/>
<layout first="30" last="30" modifiers="Modifiers" mapSet="JIS"/>
<layout first="33" last="33" modifiers="Modifiers" mapSet="JIS"/>
<layout first="36" last="36" modifiers="Modifiers" mapSet="JIS"/>
// Playground - noun: a place where people can play
//
// Needle Scratch
/// Swift does not have a notion of pattern matching, at least as supported by the language itself.
/// What it does have are Sum Types with associated fields, otherwise known as (a poor man's, in this
/// case) variant records. Switch statements allow for a measure of destructuring and pattern matching. Exploiting
/// this, one can write pattern matching as a switch statement against one of these "matchers" of the
/// correct arity.
public enum LiftMatch<T> {
@CodaFi
CodaFi / bug.swift
Last active August 29, 2015 14:04 — forked from rbrockerhoff/bug.swift
extension Array {
mutating func merge <S: SequenceType where S.Generator.Element == Element> (seq: S) {
var gen = seq.generate()
while let (key : Element, value : Element) = gen.next() {
self[0] = value
}
}
}
var arr = [0]
@CodaFi
CodaFi / BCKW.swift
Created July 31, 2014 06:52
Sentential Combinators par Curry
// Playground - noun: a place where people can play
/// From Curry's doctoral thesis, Grundlagen der Kombinatorischen Logik, these combinators
/// have been largely abandoned due to the discovery of the SKI calculus (really just S and K).
/// Interestingly, Curry's system is derived from a number of popular axioms in propositional
/// logic. Namely:
///
/// B ≡ (B → C) → ((A → B) → (A → C))
/// C ≡ (A → (B → C)) → (B → (A → C))
/// K ≡ A → (B → A)