Skip to content

Instantly share code, notes, and snippets.

View finestructure's full-sized avatar

Sven A. Schmidt finestructure

View GitHub Profile
@finestructure
finestructure / OrderedDict.swift
Last active September 13, 2020 14:20
Swift ordered dictionary
import Foundation
struct OrderedDictionary<K: Hashable, V> {
var keys: [K] = []
var dict: [K: V] = [:]
var count: Int {
assert(keys.count == dict.count, "internal inconsistency")
return keys.count
// Add a marker protocol to allow for new TestCase subclasses to be
// picked up automatically by adopting it.
protocol LinuxTesting {}
// Extend XCTestCase to conform
extension XCTestCase: LinuxTesting {}
@finestructure
finestructure / LinuxMain.stencil
Last active November 28, 2018 11:59
Stencil file to autogenerate swift package manager linux tests with Sourcery
import XCTest
{{ argument.testimports }}
// swiftlint:disable trailing_comma
{% for type in types.classes|based:"XCTestCase" %}
{% if not type.annotations.disableTests %}extension {{ type.name }} {
static var allTests: [(String, ({{ type.name }}) -> () throws -> Void)] = [
{% for method in type.methods %}
{% if method.parameters.count == 0 and method.shortName|hasPrefix:"test" %}

Keybase proof

I hereby claim:

  • I am finestructure on github.
  • I am finestructure (https://keybase.io/finestructure) on keybase.
  • I have a public key whose fingerprint is 215B 3D32 5FF1 5AA4 4EB9 843E A138 F568 B059 543D

To claim this, I am signing this object:

@finestructure
finestructure / pre-commit
Created October 21, 2018 12:32
pre-commit hook to generate LinuxMain.swift via Sourcery
#!/bin/sh
./update_linux_tests.sh &>/dev/null
if [[ -n $(git diff) ]]; then
echo "Linux tests were out of date."
echo "Files have been updated, please review add them to the commit."
exit 1
fi
@finestructure
finestructure / Error.swift
Created August 2, 2016 09:26
posix_spawn based system call (swift 3.0-p1-ish, WIP)
/*
This source file is part of the Swift.org open source project
Copyright 2015 - 2016 Apple Inc. and the Swift project authors
Licensed under Apache License v2.0 with Runtime Library Exception
See http://swift.org/LICENSE.txt for license information
See http://swift.org/CONTRIBUTORS.txt for Swift project authors
*/
@finestructure
finestructure / randomized_response.ipynb
Created June 20, 2016 13:31 — forked from uncommoncode/randomized_response.ipynb
Randomized Response Function for Differential Privacy
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
public final class SmartPointer<T> {
public let pointer: UnsafeMutablePointer<T>
private let destructor: (UnsafeMutablePointer<T>) -> Void
public init(pointer: UnsafeMutablePointer<T>, destructor: (UnsafeMutablePointer<T>) -> Void) {
self.pointer = pointer
self.destructor = destructor
}
deinit {
@finestructure
finestructure / try.swift
Last active August 29, 2015 14:17
Attempt at a wrapper for NSError** parameter calls (as typically seen when calling objc APIs)
// https://gist.github.com/feinstruktur/2f427934e171a8ab13af
import Foundation
public class Box<T> {
let unbox: T
init(_ value: T) { self.unbox = value }
}
@finestructure
finestructure / SenTestCase+Async.h
Created August 6, 2012 11:37
Async test for SenTestCase
//
// SenTestCase+Async.h
//
// Created by Sven A. Schmidt on 2012-08-06.
//
#import <SenTestingKit/SenTestingKit.h>
@interface SenTestCase (Async)