Skip to content

Instantly share code, notes, and snippets.

View tkersey's full-sized avatar
👹

Tim Kersey tkersey

👹
View GitHub Profile
@tkersey
tkersey / AnimationsAsSemiring.swift
Created November 15, 2017 19:05 — forked from elm4ward/AnimationsAsSemiring.swift
Animations As Semiring
import Foundation
import UIKit
import PlaygroundSupport
// --------------------------------------------------------------------------------
// MARK: - operators
// --------------------------------------------------------------------------------
precedencegroup MonoidComposePrecedence {
associativity: left higherThan: AssignmentPrecedence lowerThan: AdditionPrecedence
@tkersey
tkersey / HKT.swift
Created December 2, 2017 22:20 — forked from anandabits/HKT.swift
Emulating HKT in Swift
// This example shows how higher-kinded types can be emulated in Swift today.
// It acheives correct typing at the cost of some boilerplate, manual lifting and an existential representation.
// The technique below was directly inspired by the paper Lightweight Higher-Kinded Polymorphism
// by Jeremy Yallop and Leo White found at http://ocamllabs.io/higher/lightweight-higher-kinded-polymorphism.pdf
/// `ConstructorTag` represents a type constructor.
/// `Argument` represents an argument to the type constructor.
struct Apply<ConstructorTag, Argument> {
/// An existential containing a value of `Constructor<Argument>`
/// Where `Constructor` is the type constructor represented by `ConstructorTag`
@tkersey
tkersey / combinators.js
Created May 7, 2018 21:19 — forked from Avaq/combinators.js
Common combinators in JavaScript
const I = x => x;
const K = x => y => x;
const A = f => x => f(x);
const T = x => f => f(x);
const W = f => x => f(x)(x);
const C = f => y => x => f(x)(y);
const B = f => g => x => f(g(x));
const S = f => g => x => f(x)(g(x));
const P = f => g => x => y => f(g(x))(g(y));
const Y = f => (g => g(g))(g => f(x => g(g)(x)));

Videos

@tkersey
tkersey / TrackerEmojis.md
Created November 14, 2018 21:23 — forked from mattmcneeney/TrackerEmojis.md
Emojis that are supported in Pivotal Tracker initials

Tracker emojis

A list of emojis that are allowed in Pivotal Tracker initials.

Emoji Unicode
\xE2\x9C\x82
\xE2\x9C\x85
\xE2\x9C\x88
\xE2\x9C\x89
@tkersey
tkersey / libdispatch-efficiency-tips.md
Created November 2, 2020 02:17 — forked from tclementdev/libdispatch-efficiency-tips.md
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

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
@tkersey
tkersey / movie.md
Last active November 18, 2020 20:48 — forked from laser/movie.md

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).

{-# LANGUAGE DeriveFunctor #-}
module Main where
type Algebra f a = f a -> a
type Coalgebra f a = a -> f a
newtype Fix f = In { out :: f (Fix f) }
@tkersey
tkersey / Yoneda.swift
Created November 22, 2021 20:42 — forked from CodaFi/Yoneda.swift
//
// Yoneda.swift
// Basis
//
// Created by Robert Widmann on 12/11/14.
// Copyright (c) 2014 Robert Widmann. All rights reserved.
//
import Basis