Skip to content

Instantly share code, notes, and snippets.

@mergesort
mergesort / AnimationDemo.swift
Last active December 18, 2023 02:34
A SwiftUI prototype animation for adding/removing players from a game
import SwiftUI
let colors = [
Color.pink,
Color.blue,
Color.green,
Color.orange,
Color.purple,
Color.black,
]
@andymatuschak
andymatuschak / States-v3.md
Last active April 12, 2024 16:06
A composable pattern for pure state machines with effects (draft v3)

A composable pattern for pure state machines with effects

State machines are everywhere in interactive systems, but they're rarely defined clearly and explicitly. Given some big blob of code including implicit state machines, which transitions are possible and under what conditions? What effects take place on what transitions?

There are existing design patterns for state machines, but all the patterns I've seen complect side effects with the structure of the state machine itself. Instances of these patterns are difficult to test without mocking, and they end up with more dependencies. Worse, the classic patterns compose poorly: hierarchical state machines are typically not straightforward extensions. The functional programming world has solutions, but they don't transpose neatly enough to be broadly usable in mainstream languages.

Here I present a composable pattern for pure state machiness with effects,

@marius-serban
marius-serban / _playbackQuality.markdown
Last active December 17, 2015 15:07
Measuring playback quality

The purpose of this document is to present several ways in which the quality of music streaming can be measured in a quantitative way.

The benefit in continuously tracking these metrics is that we can measure the impact of improvements and and detect when we've done something wrong and broken the user's listening experience.

Basic benchmarks

Playback latency

Measuring the time it takes from the moment the user requests playback until the audio starts. This is equal to the sum of the connection time and the initial buffer load time. See an example graph(1): music latency graph

Stutters per track

@johnboiles
johnboiles / enable-charles-proxy.sh
Last active January 28, 2021 07:48
Add this as a "Run Script" build phase in Xcode to enable Charles Proxy on iOS 9
#!/bin/sh
# enable-charles-proxy.sh
#
# Created by John Boiles on 9/21/15.
#
# This script sets :NSAppTransportSecurity:NSAllowsArbitraryLoads to true in the Info.plist file if building the Debug configuration.
# This enables debugging from https proxies such as Charles.
INFO_PLIST="${TARGET_BUILD_DIR}/${INFOPLIST_PATH}"
@steipete
steipete / PSPDFUIKitMainThreadGuard.m
Last active March 10, 2024 19:23
This is a guard that tracks down UIKit access on threads other than main. This snippet is taken from the commercial iOS PDF framework http://pspdfkit.com, but relicensed under MIT. Works because a lot of calls internally call setNeedsDisplay or setNeedsLayout. Won't catch everything, but it's very lightweight and usually does the job.You might n…
// Taken from the commercial iOS PDF framework http://pspdfkit.com.
// Copyright (c) 2014 Peter Steinberger, PSPDFKit GmbH. All rights reserved.
// Licensed under MIT (http://opensource.org/licenses/MIT)
//
// You should only use this in debug builds. It doesn't use private API, but I wouldn't ship it.
// PLEASE DUPE rdar://27192338 (https://openradar.appspot.com/27192338) if you would like to see this in UIKit.
#import <objc/runtime.h>
#import <objc/message.h>