Skip to content

Instantly share code, notes, and snippets.

View tjw's full-sized avatar

Timothy J. Wood tjw

View GitHub Profile
func f(code:Void -> Void) {
print("no throw version called")
code()
}
func f<Result>(code:Void throws -> Result) rethrows -> Result {
print("rethrow version called")
return try code()
}
@tjw
tjw / generic-ivar.swift
Last active December 2, 2015 01:53
Corruption when assigning to stored properties in classes using generics
import Cocoa
class A<T> : NSViewController {
var x:T? = nil
override init?(nibName nibNameOrNil: String?, bundle nibBundleOrNil: NSBundle?) {
super.init(nibName: nibNameOrNil, bundle: nibBundleOrNil)
}
}
class B : A<NSString> {
override init?(nibName nibNameOrNil: String?, bundle nibBundleOrNil: NSBundle?) {
@tjw
tjw / generic-link-error.swift
Last active December 2, 2015 00:15
Swift generics link error
@tjw
tjw / conflicts-ios.txt
Created November 6, 2015 19:41
system method signature conflicts
2015-11-06 11:34:23.731 OmniFocus-Debug[1518:936775] *** Starting OBPerformRuntimeChecks
2015-11-06 11:34:23.795 OmniFocus-Debug[1518:936775] Method context has conflicting type signatures between class and its superclass:
signature ^{GraphicsContext3D=Iii{RetainPtr<WebGLLayer>=^v}@{HashMap<unsigned int, WebCore::GraphicsContext3D::ShaderSourceEntry, WTF::IntHash<unsigned int>, WTF::HashTraits<unsigned int>, WTF::HashTraits<WebCore::GraphicsContext3D::ShaderSourceEntry> >={HashTable<unsigned int, WTF::KeyValuePair<unsigned int, WebCore::GraphicsContext3D::ShaderSourceEntry>, WTF::KeyValuePairKeyExtractor<WTF::KeyValuePair<unsigned int, WebCore::GraphicsContext3D::ShaderSourceEntry> >, WTF::IntHash<unsigned int>, WTF::HashMap<unsigned int, WebCore::GraphicsContext3D::ShaderSourceEntry, WTF::IntHash<unsigned int>, WTF::HashTraits<unsigned int>, WTF::HashTraits<WebCore::GraphicsContext3D::ShaderSourceEntry> >::KeyValuePairTraits, WTF::HashTraits<unsigned int> >=^{KeyValuePair<unsigned int, WebCore::GraphicsCont
@tjw
tjw / gist:67da25b39f6a18197f4d
Created October 29, 2015 16:12
Build failure w/ObjC modules
CompileC /Users/bungi/Library/Developer/Xcode/DerivedData/OmniFocus-awuidrenlcqzqucuyvzjajjoqbeo/Build/Intermediates/XMLData.build/Debug/XMLDataTestTool.build/Objects-normal/x86_64/XMLDataTestTool_main.o Tests/XMLDataTestTool_main.m normal x86_64 objective-c com.apple.compilers.llvm.clang.1_0.compiler
cd /Users/bungi/Source/Omni/clean/OmniGroup/Applications/OmniFocus/XMLData
export LANG=en_US.US-ASCII
/Applications/Xcode-7.1.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/clang -x objective-c -arch x86_64 -fmessage-length=251 -fdiagnostics-show-note-include-stack -fmacro-backtrace-limit=0 -fcolor-diagnostics -std=gnu99 -fmodules -gmodules -fmodules-cache-path=/Users/bungi/Library/Developer/Xcode/DerivedData/ModuleCache -fmodules-prune-interval=86400 -fmodules-prune-after=345600 -fbuild-session-file=/Users/bungi/Library/Developer/Xcode/DerivedData/ModuleCache/Session.modulevalidation -fmodules-validate-once-per-build-session -Wnon-modular-include-in-framework-module -Werror=non-m
@tjw
tjw / XcodeMindWipe.zsh
Created October 29, 2015 15:43
XcodeMindWipe
XcodeMindWipe () {
rm -rf ~/Library/Developer/Xcode/DerivedData
find . -name $USER.xcuserdatad -o \( -name xcuserdata -o -name "*.xccheckout" \) -print0 | xargs -0 rm -rf
}
@tjw
tjw / ticket-scanner.py
Last active June 30, 2023 08:15 — forked from swizzlevixen/ticket-scanner.py
Python OpenCV program to extract ticket stub images from photographs, via automatic perspective correction for quadrilateral objects.
#!/usr/local/bin/python
# coding: utf-8
import cv2
import sys
import numpy
from matplotlib import pyplot as plt
from scipy.spatial import distance
"""
@tjw
tjw / init-cannot-assign-to-let.swift
Last active August 29, 2015 14:25
init-cannot-assign-to-let.swift
public class Measurement {
public let value: Double
public required init(_ value:Double) {
self.value = value
}
}
public struct Size {
public let width:Measurement
@tjw
tjw / instantiate-from-class.swift
Created July 20, 2015 03:29
instantiate-from-class.swift
protocol P {
static var name: String { get }
init(i:Int)
}
class A: P {
static var name: String {
get { return "A" }
}
required init(i:Int) {}
@tjw
tjw / CGGStack
Created June 3, 2015 04:08
CGGStack dtrace wrapper script
#!/bin/zsh -euf
# NOTE: In order for the -c flag to work, 'main' must not be stripped from the executable.
# If it has been, you'll get the cryptic
#
# dtrace: failed to control pid 82297: process exited with status 0
#
if [ $# -ne 1 ]; then
echo "usage: $0 [executable-name|app-path|app-identifier]" 1>&2