Skip to content

Instantly share code, notes, and snippets.

@Treeki
Treeki / TurnipPrices.cpp
Last active April 5, 2024 13:55
AC:NH turnip price calculator
#include <stdint.h>
#include <stdio.h>
#include <stdlib.h>
// munged from https://github.com/simontime/Resead
namespace sead
{
class Random
{
@rmcdongit
rmcdongit / macOS_SytemPrefs.md
Last active April 24, 2024 23:31
Apple System Preferences URL Schemes

macOS 10.15 System Preference Panes

Below are a list of System Preference pane URLs and paths that can be accessed with scripting to assist users with enabling macOS security settings without having to walk them through launching System Preferences, finding panes, and scrolling to settings. Not all panes have an accessible anchor and some are OS specific.

To find the Pane ID of a specific pane, open the System Preferences app and select the desired Preference Pane. With the pane selected, open the ScriptEditor.app and run the following script to copy the current Pane ID to your clipboard and display any available anchors:

tell application "System Preferences"
	set CurrentPane to the id of the current pane
	set the clipboard to CurrentPane
@shaps80
shaps80 / Scheduling-AppDelegate.swift
Last active February 16, 2022 03:14
NSNotification Scheduling Service in Swift. (the only required file is `SchedulingService.swift`)
//
// AppDelegate.swift
// Scheduling
//
// Created by Shaps Benkau on 19/02/2018.
// Copyright © 2018 152percent Ltd. All rights reserved.
//
import UIKit
@chriseidhof
chriseidhof / goroutines.swift
Created February 16, 2018 12:36
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
krzysztofzablocki / FindFinalClasses.swift
Last active August 22, 2021 12:12
Swift makes classes final if possible
#!/usr/bin/env bash
<% for type in types.classes { -%>
<%_ if type.attributes["final"] != nil || type.attributes["open"] != nil || types.based[type.name]?.isEmpty == false { continue } -%>
<%_ _%>git grep -lz 'class <%= type.name %>' | xargs -0 perl -i'' -pE "s/class <%= type.name %>(?=\s|:)/final class <%= type.name %>/g"
<% } %>
import Vapor
import HTTP
import Foundation
extension Node {
var backDoorToRealValues: Any {
return self.wrapped.backDoorToRealValues
}
}
@lattner
lattner / TaskConcurrencyManifesto.md
Last active April 25, 2024 18:22
Swift Concurrency Manifesto
@marcan
marcan / gamma_trick.sh
Last active December 10, 2023 22:06
Two images in one using the PNG gamma header trick.
#!/bin/sh
# PNG Gamma trick (by @marcan42 / marcan@marcan.st)
#
# 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):
# https://mrcn.st/t/homura_gamma_trick.png
# https://www.reddit.com/r/test/comments/6edthw/ (click for fullsize)
# https://twitter.com/marcan42/status/869855956842143744
@steipete
steipete / Warnings.xcconfig
Last active March 13, 2018 14:47
Did you knew that Clang Analyzer as alpha checkers? Early Christmas is here! (Ignore the rest... we run our PDF SDK https://pspdfkit.com with -Weverything because warnings are awesome to prevent bugs) - See https://gist.github.com/steipete/28849365e603dc2015c7107d85142e7b/revisions for a list of Xcode 8.3 changes
// clang -cc1 -analyzer-checker-help
// OVERVIEW: Clang Static Analyzer Checkers List
// USAGE: -analyzer-checker <CHECKER or PACKAGE,...>
//
// CHECKERS:
// 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
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,