Skip to content

Instantly share code, notes, and snippets.

@n8gray
n8gray / ArrayTest.swift
Created June 7, 2014 17:46
Testing Swift array variance
//
// ArrayTest.swift
// SwiftTest
//
// Swift array subtyping semantics test
//
// Created by Nathan Gray on 6/7/14.
// Copyright (c) 2014 Mellmo. All rights reserved.
//
@n8gray
n8gray / MonadTest.swift
Last active August 29, 2015 14:02
Demonstrates using a cell to work around Swift compiler limitations.
/*
It appears that the Swift code generator requires fixed layout in a lot of contexts
where one might reasonably desire to use generics. Trying to do so gets you a
lovely error of this sort:
LLVM ERROR: unimplemented IRGen feature! non-fixed multi-payload enum layout
This is my hacky solution to that problem. I use a cell to encapsulate the generic
as a fixed-layout value. I've provided a prefix * operator to retrieve the value
(how retro!) in order to minimize the syntactic overhead of using the cell class.
@n8gray
n8gray / OptionalFail.swift
Created June 18, 2014 18:44
This is why Optionals should not be allowed in if statement tests
val shouldLaunchMissiles : Bool? = false
// A million lines later, programmer forgets that shouldLaunchMissiles is an optional
if shouldLaunchMissiles {
println("The only way to win is not to play")
missiles.launch()
} else {
println("Let there be peace on Earth")
kittens.release()
}
@n8gray
n8gray / hahahaha.m
Created June 25, 2014 04:59
No Jerry, I'm not fucking with you
// At some point I thought this was very clever
//
// Six months later I was like, why the hell is the tag on this view 1008017??!?!
-(void)awakeFromNib
{
[super awakeFromNib];
int tag = [self tag];
if (tag > 1000000) {
int residue = tag - (tag / 1000000) * 1000000;
@n8gray
n8gray / remove_sim_dups.py
Last active August 29, 2015 14:26 — forked from buscarini/remove_sim_dups.py
Remove Xcode duplicated simulators
#!/usr/bin/env python
# -*- coding: utf-8 -*-
import re
from subprocess import Popen, PIPE
from subprocess import call
# Change this to True to see what will be deleted without deleting anything
DRY_RUN = False
(* This is the original function. It works fine, but makes extra calls to check_left and check_right. *)
let sorting_hat id =
if not (base_case id) then Dead
else
begin
if check_left id && check_right id then Central
else if check_left id then Left
else if check_right id then Right
else Dead
end
@n8gray
n8gray / configure-ios
Created January 19, 2012 18:51
A script to configure autotools software for iOS
#!/bin/bash
################################################################################
#
# Copyright (c) 2008-2009 Christopher J. Stawarz
#
# Modified by Nathaniel Gray in 2012 to support Clang, custom dev tool locations,
# and armv7. Also removed "make install" phase, since that can easily be done by
# hand.
#
@n8gray
n8gray / git-details
Last active October 26, 2017 17:23
Git: Show the details of a commit and all its parents
#!/bin/zsh
#
# Shows the raw details of a commit and all its parents
#
if [[ $# < 1 ]]; then
SHA=HEAD
else
SHA=$1
@n8gray
n8gray / git-submodule-of-commit
Created September 19, 2016 19:15
Shows a list of submodules that exist at the given commit, along with their corresponding submodule commits.
#!/bin/sh
if [[ $# != 1 ]]; then
echo "usage: $0 SHA"
echo " Shows a list of submodules that exist at the given commit, along with their corresponding"
echo " submodule commits."
exit 1
else
SHA=$1
fi
@n8gray
n8gray / link-simulators.sh
Created June 9, 2014 17:04
Xcode 6: Make a symlink to each iOS simulator's data directory