Skip to content

Instantly share code, notes, and snippets.

View vdka's full-sized avatar

Ethan Jackwitz vdka

View GitHub Profile
func longZip<S1: Sequence, S2: Sequence>(_ seq1: S1, _ seq2: S2) -> AnyIterator<(S1.Iterator.Element?, S2.Iterator.Element?)?> {
var (iter1, iter2) = (seq1.makeIterator(), seq2.makeIterator())
return AnyIterator { () -> (S1.Iterator.Element?, S2.Iterator.Element?)? in
let (l, r) = (iter1.next(), iter2.next())
switch (l, r) {
case (nil, nil):
return nil
let digits = Array("1234567890".characters)
let identChars = Array("_abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ".characters)
let opChars = Array("<>+-=*/!%^&?|".characters)
struct Lexer: IteratorProtocol {
var scanner: BufferedScanner<Character>
init(_ string: String) {
//
// Curly.swift
// Curly
//
// Created by Adolfo Rodriguez on 2014-11-04.
// Copyright (c) 2014 Wircho. All rights reserved.
//
// NOTE(vdka): Taken from https://github.com/wircho/Curly
import Foundation
extension Date {
static var now: Date { return Date() }
}
func curtime() -> Double {
var tv = timeval()
gettimeofday(&tv, nil)
// hehehe
struct ­ {
var ­­: String
}
let ­­: ­ = ­(­­: "Invisble characters should not be acceptable identifiers.")
print(­­)
import Vapor
import Darwin.C
func curTime() -> Double {
var tv = timeval()
gettimeofday(&tv, nil)
@vdka
vdka / UUID.swift
Last active August 25, 2016 02:42
Unsafe UUID's
import Darwin
struct UUID {
var storage: (UInt64, UInt64)
var bytes: UnsafeBufferPointer<UInt8> {
var `self` = self
let pointer = withUnsafeMutablePointer(to: &self) { pointer in
@vdka
vdka / ByteHashable.swift
Last active August 24, 2016 15:07
Everything is Memory.
func hashMemory<T>(of input: T) -> Int {
// make a copy beacuse we *might* mutate input when getting an UnsafePointer to the value. Dammit. That sucks.
// *should* be no cost provided the compiler sees we are not actually mutating the value in there. But it sure
// would be nice to have a way to tell the compiler I would like to just *look* at the memory.
var input = input
return withUnsafePointer(to: &input) { pointer in
@vdka
vdka / labels.json
Last active August 23, 2016 23:53
Github Labels file for use with https://github.com/himynameisdave/git-labelmaker
[
{ "name": "bug", "color": "#e34424" },
{ "name": "feature", "color": "#6cc644" },
{ "name": "ready", "color": "#EAC04B" },
{ "name": "in progress", "color": "#56d1f3" },
{ "name": "on hold", "color": "#7d59c3" },
{ "name": "regression", "color": "#fe9a00" },
{ "name": "discussion", "color": "#7d59c3" },
{ "name": "weight: 1", "color": "#ededed" },
{ "name": "weight: 2", "color": "#ededed" },
@vdka
vdka / example.swift
Created August 18, 2016 13:36
Swift enum with private cases
public struct Key {
private let rawValue: UInt8
private init(_ rawValue: UInt8) {
self.rawValue = rawValue
}
public let somePublicCase = Key(0)
private let somePrivateCase = Key(1)
private let anotherPrivateCase = Key(2)