Skip to content

Instantly share code, notes, and snippets.


Tim Kersey tkersey

View GitHub Profile
View LayoutPlayground.swift
//: A Cocoa based Playground to present user interface
import SwiftUI
import PlaygroundSupport
struct ContentView: View {
var body: some View {
HStack {
VStack {
HStack {
tkersey / ExampleDomain.swift
Created Feb 20, 2021 — forked from lukeredpath/ExampleDomain.swift
An enum equivalent of IfLetStore for The Composable Architecture
View ExampleDomain.swift
enum AppState: Equatable {
case featureOne(FeatureState)
case featureTwo(FeatureState)
case featureThree(FeatureState)
enum AppAction: Equatable {
case featureOne(FeatureAction)
case featureTwo(FeatureAction)
case featureThree(FeatureAction)
tkersey / IndicesAndLevels.hs
Created Jan 31, 2021 — forked from ekmett/IndicesAndLevels.hs
a pragmatic mix of de bruijn indices and levels
View IndicesAndLevels.hs
{-# language PolyKinds #-}
{-# language BlockArguments #-}
{-# language AllowAmbiguousTypes #-}
{-# language StrictData #-}
{-# language DerivingStrategies #-}
{-# language GeneralizedNewtypeDeriving #-}
{-# language TypeApplications #-}
{-# language BangPatterns #-}
{-# language NPlusKPatterns #-}
{-# language TypeFamilies #-}
View take_until.swift
// let base = [1,2,4,6,5,8,6]
// let filtered = base.takeUntil{ $0.isMultiple(of: 2) } // [2,4,6]
// let base = [2,4,6,5,8,6]
// let filtered = base.takeUntil{ $0.isMultiple(of: 2) } // [2,4,6]
// It stops collecting when the predicate fails (5,8,6 are not evaluated)
// Idea by
View AutoLayoutDSL.swift
import UIKit
/// Represents a single `NSLayoutConstraint`
enum LayoutAnchor {
case constant(attribute: NSLayoutConstraint.Attribute,
relation: NSLayoutConstraint.Relation,
constant: CGFloat)
case relative(attribute: NSLayoutConstraint.Attribute,
relation: NSLayoutConstraint.Relation,
tkersey / GADT.swift
Created Nov 27, 2020 — forked from rxwei/GADT.swift
GADT in Swift
View GADT.swift
/// A type equality guarantee is capable of safely casting one value to a
/// different type. It can only be created when `S` and `T` are statically known
/// to be equal.
struct TypeEqualityGuarantee<S, T> {
private init() {}
/// Safely cast a value to the other type.
func cast(_ value: T) -> S {
return value as! S

Movie Ticket Kata

What Are We Building?

Write a program that calculates purchase price for movie tickets using any language you like. It should not be a full-blown web app; it can be a simple class or collection of methods invokable by your test suite. We'll provide you with some requirements, test-cases, and even a sample interface - all you have to do is give us some software.

Base Admission Rate

The Base Admission Rate cover movies to be viewed on a regular weekday (see "Special Movie Day" below), in 2D, with a length of <= 120 minutes, viewed from the main seating area (there is also a balcony seating area, which is much fancier).


With scoped effects, handlers must be a part of the program

It is seductive to imagine that effect handlers in an algebraic effect system are not part of the program itself but metalanguage-level folds over the program tree. And in traditional free-like formulations, this is in fact the case. The Eff monad represents the program tree, which has only two cases:

data Eff effs a where
  Pure :: a -> Eff effs a
  Op :: Op effs a -> (a -> Eff effs b) -> Eff effs b

data Op effs a where
View InterfaceOrientation.swift
enum InterfaceOrientation {
static let `default`: UIInterfaceOrientationMask = .portrait
private(set) static var value: UIInterfaceOrientationMask = `default`
static func `default`(_ orientation: UIInterfaceOrientationMask = `default`) {
value = orientation
static func lock(_ orientation: UIInterfaceOrientationMask) {
value = orientation
tkersey /
Created Nov 2, 2020 — forked from tclementdev/
Making efficient use of the libdispatch (GCD)

libdispatch efficiency tips

The libdispatch is one of the most misused API due to the way it was presented to us when it was introduced and for many years after that, and due to the confusing documentation and API. This page is a compilation of important things to know if you're going to use this library. Many references are available at the end of this document pointing to comments from Apple's very own libdispatch maintainer (Pierre Habouzit).

My take-aways are:

  • You should create very few, long-lived, well-defined queues. These queues should be seen as execution contexts in your program (gui, background work, ...) that benefit from executing in parallel. An important thing to note is that if these queues are all active at once, you will get as many threads running. In most apps, you probably do not need to create more than 3 or 4 queues.

  • Go serial first, and as you find performance bottle necks, measure why, and if concurrency helps, apply with care, always validating under system pressure. Reuse