Skip to content

Instantly share code, notes, and snippets.

@andymatuschak
andymatuschak / States-v3.md
Last active December 6, 2025 23:58
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,

1:1 questions

Always end with an assignment

What can I hold you accountable for next time we talk?

What can I be accountable to you for the next time we talk?

Short term

How is [project] going? What could we do to make it better?

Is there anything blocking you from getting your work done?

Are there any projects you’d really like to work on if you were given the opportunity?

@sgr-ksmt
sgr-ksmt / file.swift
Created September 26, 2016 05:55
Safe DispatchQueue.main.sync (Swift3.0)
extension DispatchQueue {
class func mainSyncSafe(execute work: () -> Void) {
if Thread.isMainThread {
work()
} else {
DispatchQueue.main.sync(execute: work)
}
}
class func mainSyncSafe<T>(execute work: () throws -> T) rethrows -> T {
anonymous
anonymous / .swift
Created September 29, 2016 13:28
import UIKit
class LoginController: UIViewController {
let inputContainerView : UIView = {
let view = UIView()
view.backgroundColor = UIColor.white
extension TimeInterval {
// builds string in app's labels format 00:00.0
func stringFormatted() -> String {
var miliseconds = self.roundTo(places: 1) * 10
miliseconds = miliseconds.truncatingRemainder(dividingBy: 10)
let interval = Int(self)
let seconds = interval % 60
let minutes = (interval / 60) % 60
return String(format: "%02d:%02d.%.f", minutes, seconds, miliseconds)
}
@francois-blanchard
francois-blanchard / debug_travis_build.md
Last active September 15, 2020 08:55
How to debug a failed travis.ci build

How to debug a failed travis.ci build

1/ Go to travais build

https://travis-ci.com/gitUser/gitRepo/builds/XXXXXX

build

2/ Connect to travis build with ssh

@Gurdeep0602
Gurdeep0602 / AppStoryboard.swift
Last active April 2, 2024 09:54
AppStoryboard enumeration
//
// AppStoryboards.swift
// AppStoryboards
//
// Created by Gurdeep on 15/12/16.
// Copyright © 2016 Gurdeep. All rights reserved.
//
import Foundation
import UIKit
@runys
runys / search-controller.swift
Last active September 27, 2018 14:47
Search Controller in Table View Controller in iOS 11 with Swift 4. From: https://www.raywenderlich.com/113772/uisearchcontroller-tutorial
// The code bellow must be written in your Table View Controller
// Remember to use your own classes and properties when creating your own search.
// 1. Create a new property in your class
// The Search Controller is the responsible to do the "searching magic"
let searchController = UISearchController(searchResultsController: nil)
// 2. At the viewDidLoad() add those initializations
searchController.searchResultsUpdater = self // You will get an error here for now, but it will vanish at step number 5
searchController.dimsBackgroundDuringPresentation = false
@tadija
tadija / FontNames-iOS-17.4.swift
Last active June 26, 2025 20:25
iOS - All Font Names
/*
*** Academy Engraved LET ***
AcademyEngravedLetPlain
---------------------
*** Al Nile ***
AlNile
AlNile-Bold
---------------------
*** American Typewriter ***
AmericanTypewriter
@ollieatkinson
ollieatkinson / HTTPStatusCode.swift
Last active April 12, 2025 22:44
HTTP status codes as a Swift enum.
/// This is a list of Hypertext Transfer Protocol (HTTP) response status codes.
/// It includes codes from IETF internet standards, other IETF RFCs, other specifications, and some additional commonly used codes.
/// The first digit of the status code specifies one of five classes of response; an HTTP client must recognise these five classes at a minimum.
enum HTTPStatusCode: Int, Error {
/// The response class representation of status codes, these get grouped by their first digit.
enum ResponseType {
/// - informational: This class of status code indicates a provisional response, consisting only of the Status-Line and optional headers, and is terminated by an empty line.
case informational