Skip to content

Instantly share code, notes, and snippets.

Treeki / TurnipPrices.cpp
Last active Dec 3, 2021
AC:NH turnip price calculator
View TurnipPrices.cpp
#include <stdint.h>
#include <stdio.h>
#include <stdlib.h>
// munged from
namespace sead
class Random
shaps80 / Scheduling-AppDelegate.swift
Last active Jul 22, 2021
NSNotification Scheduling Service in Swift. (the only required file is `SchedulingService.swift`)
View Scheduling-AppDelegate.swift
// AppDelegate.swift
// Scheduling
// Created by Shaps Benkau on 19/02/2018.
// Copyright © 2018 152percent Ltd. All rights reserved.
import UIKit
View goroutines.swift
import Foundation
protocol Channel: IteratorProtocol {
func send(_ value: Element?)
/// A blocking channel for sending values.
/// `send` and `receive` must run in separate separate execution contexts, otherwise you get a deadlock.
final class BlockingChannel<A>: Channel {
krzysztofzablocki / FindFinalClasses.swift
Last active Aug 22, 2021
Swift makes classes final if possible
View FindFinalClasses.swift
#!/usr/bin/env bash
<% for type in types.classes { -%>
<%_ if type.attributes["final"] != nil || type.attributes["open"] != nil || types.based[]?.isEmpty == false { continue } -%>
<%_ _%>git grep -lz 'class <%= %>' | xargs -0 perl -i'' -pE "s/class <%= %>(?=\s|:)/final class <%= %>/g"
<% } %>
View NiceJSON.swift
import Vapor
import HTTP
import Foundation
extension Node {
var backDoorToRealValues: Any {
return self.wrapped.backDoorToRealValues
marcan /
Last active Oct 9, 2021
Two images in one using the PNG gamma header trick.
# PNG Gamma trick (by @marcan42 /
# This script implements an improved version of the gamma trick used to make
# thumbnail images on reddit/4chan look different from the full-size image.
# Sample output (SFW; images by @Miluda):
# (click for fullsize)
steipete / Warnings.xcconfig
Last active Mar 13, 2018
Did you knew that Clang Analyzer as alpha checkers? Early Christmas is here! (Ignore the rest... we run our PDF SDK with -Weverything because warnings are awesome to prevent bugs) - See for a list of Xcode 8.3 changes
View Warnings.xcconfig
// clang -cc1 -analyzer-checker-help
// OVERVIEW: Clang Static Analyzer Checkers List
// USAGE: -analyzer-checker <CHECKER or PACKAGE,...>
// alpha.core.BoolAssignment Warn about assigning non-{0,1} values to Boolean variables
// alpha.core.CallAndMessageUnInitRefArg
// Check for logical errors for function calls and Objective-C message expressions (e.g., uninitialized arguments, null function pointers, and pointer to undefined variables)
// alpha.core.CastSize Check when casting a malloc'ed type T, whether the size is a multiple of the size of T
// alpha.core.CastToStruct Check for cast from non-struct pointer to struct pointer
andymatuschak /
Last active Dec 7, 2021
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,

steipete /
Last active Dec 7, 2021
Using iOS 15 devices with Xcode 12.5 (instead of Xcode 13)
# The trick is to link the DeviceSupport folder from the beta to the stable version.
# sudo needed if you run the Mac App Store version. Always download the dmg instead... you'll thank me later :)
# Support iOS 15 devices (Xcode 13.0) with Xcode 12.5:
sudo ln -s /Applications/ /Applications/
# Then restart Xcode and reconnect your devices. You will need to do that for every beta of future iOS versions
# (A similar approach works for older versions too, just change the version number after DeviceSupport)