Skip to content

Instantly share code, notes, and snippets.

View vdka's full-sized avatar

Ethan Jackwitz vdka

View GitHub Profile
import UIKit
import PhoneNumberKit
/* Dear Future Me,
You abandoned this code as you realized, immediately after implemented it, and getting it to work that there were multiple points still left unaddresssed.
1. You were unsure how this text field would interact with accessibility, you set the attributedText to include the suffix of the placeholder ... this would get read by any voice over and would completely ruin an experience of something simple for people using voice over.
2. While this text field lets you type over the placeholder the moment you stray from the placeholder format it makes the experience worse.
3. You decided simple is better than fancy looking but extremely complicated.
@propertyWrapper
class LazyToOne<Value: Decodable & FetchableRecord>: Decodable {
var field: String
var table: String
var id: String?
var cachedValue: Value?
init(field: String, table: String) {
@vdka
vdka / CustomAlertController.swift
Created May 8, 2018 00:39
A custom alert view controller styled like the airpods controller
import UIKit
@available(iOS 10.0, *)
class CustomAlertController: UIViewController {
var statusBarFadeWindow = UIWindow()
var previousViewControllerStatusBarStyle = UIStatusBarStyle.default
var contentView = UIView()
var buttons: [UIButton] = []
var instructions: [UInt32] = []
let supported = archSupported(.arm64)
if !supported {
print("Your installation of unicorn does not include support for ARM64")
print(" If you installed with homebrew you can include the ARM64 instruction set using the install flag --with-all")
exit(1)
}
var mov = encodeMOVZi(use64Bits: true, hw: 0, imm16: 2, .R0)
#if os(macOS)
import Darwin
#else
import Glibc
#endif
final class ThreadLocal<T> {
var key: pthread_key_t
@vdka
vdka / workspace.kai
Last active February 23, 2018 03:55
#import builtin("compiler")
#import kai("fmt")
#import kai("time")
#import kai("os")
// NOTE: This is internal to the builtin package "compiler"
#compiler {
BeginWorkspace :: fn(named: string, configure: (*compiler.Workspace) -> void) -> void { /* ... */ }
#import builtin("types")
u8 :: types.Integer{width: 8, signed: false}
u16 :: types.Integer{width: 16, signed: false}
u32 :: types.Integer{width: 32, signed: false}
u64 :: types.Integer{width: 64, signed: false}
i8 :: types.Integer{width: 8, signed: true}
i16 :: types.Integer{width: 16, signed: true}
@vdka
vdka / types.kai
Last active February 23, 2018 01:50
#import builtin("platform")
UnmaskTypePointer :: fn(ptr: *$T) -> *T {
return cast(*T) ((cast(platform.UIntptr) type) & ~0b111)
}
#assert(SizeOf(Type) == platform.PointerSize)
// NOTE: This just means the compiler skips over this code it's provided for reference
@vdka
vdka / timemyxcodebuilds.swift
Created August 14, 2017 07:05
A utility script you can call from xcode when builds begin and finish to track the time spent waiting for builds
#!/usr/bin/swift
import Foundation
func usage() -> Never {
print("usage: exec (start | finish | total | history | nuke)")
exit(1)
}
guard CommandLine.arguments.count > 1 else {
func longZip<S1: Sequence, S2: Sequence>(_ seq1: S1, _ seq2: S2) -> AnySequence<(S1.Iterator.Element?, S2.Iterator.Element?)> {
var (iter1, iter2) = (seq1.makeIterator(), seq2.makeIterator())
return AnySequence {
return AnyIterator { () -> (S1.Iterator.Element?, S2.Iterator.Element?)? in
let (l, r) = (iter1.next(), iter2.next())
switch (l, r) {
case (nil, nil):
return nil