Skip to content

Instantly share code, notes, and snippets.

@wildthink
wildthink / programming-as-theory-building.md
Created January 9, 2024 00:11 — forked from onlurking/programming-as-theory-building.md
Programming as Theory Building - Peter Naur

Programming as Theory Building

Peter Naur

Peter Naur's classic 1985 essay "Programming as Theory Building" argues that a program is not its source code. A program is a shared mental construct (he uses the word theory) that lives in the minds of the people who work on it. If you lose the people, you lose the program. The code is merely a written representation of the program, and it's lossy, so you can't reconstruct

@wildthink
wildthink / Tweaker.swift
Created January 7, 2024 03:20
Swift Talk Episode 388 - Tweakable Values
//
// Swift Talk Episode 388:
// [Tweakable Values: Finishing Up](https://talk.objc.io/episodes/S01E388-tweakable-values-finishing-up)
import SwiftUI
struct PreferenceValue: Equatable {
var initialValue: Any
var label: String
var edit: (String, Binding<Any>) -> AnyView
init<T>(initialValue: T, label: String, edit: @escaping (String, Binding<T>) -> AnyView) {
@wildthink
wildthink / ApiKey.swift
Created November 11, 2023 14:08
Using iCloud for storing keys and then pushing into keychain of device.
import CloudKit
import Foundation
import Locksmith
/**
API Key used by this app is fetched from CloudKit. This class manages fetching and saving it into Keychain
*/
class ApiKey {
private static let RECORD_NAME = <# RECORD_NAME_IN_CLOUDKIT #>
private static let KEY = <# KEY_NAME_IN_CLOUDKIT #>
@wildthink
wildthink / FrameCaptureModifier.swift
Created November 26, 2022 15:32 — forked from marcpalmer/FrameCaptureModifier.swift
Code to capture frames of views for use elsewhere in the SwiftUI hierarchy
//
// FrameCaptureModifier.swift
// FrameCaptureModifier
//
// Created by Marc Palmer on 31/03/2020.
//
// This is free and unencumbered software released into the public domain.
//
// Anyone is free to copy, modify, publish, use, compile, sell, or
// distribute this software, either in source code form or as a compiled
import Foundation
/*
MIT License
Copyright (c) 2022 Parable Health
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
@wildthink
wildthink / ResultBuilder.swift
Last active April 14, 2022 23:32
Default @resultBuilder implementation makes make Result Builder easy
import Foundation
// WildThink
// https://gist.github.com/wildthink/386305f84d1e3ec0e1a198656733babe
// refs:
// https://github.com/apple/swift-evolution/blob/main/proposals/0289-result-builders.md#virtualized-abstract-syntax-trees-asts
public indirect enum ResultBuilderTerm<Expression> {
case expression(Expression)
case lambda(() -> Expression)
case block([ResultBuilderTerm])
@wildthink
wildthink / cult_of_ignorance.md
Created April 11, 2022 03:31 — forked from wgmitchener/cult_of_ignorance.md
A Cult Of Ignorance, Isaac Asimov

A Cult of Ignorance

Newsweek January 21, 1980

Isaac Asimov/My Turn

It's hard to quarrel with that ancient justification of the free press: "America's right to know." It seems almost cruel to ask, ingenously, "America's right to know what, please? Science? Mathematics? Economics? Foreign languages?"

None of those things, of course.

@wildthink
wildthink / script.swift
Created January 16, 2022 16:43 — forked from chriseidhof/script.swift
SwiftUI
import SwiftSyntax
import SwiftSemantics
import Foundation
let source = try! String(contentsOf: URL(fileURLWithPath: "/Applications/Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS13.2.sdk/System/Library/Frameworks/SwiftUI.framework/Modules/SwiftUI.swiftmodule/arm64e.swiftinterface"))
var collector = DeclarationCollector()
let tree = try SyntaxParser.parse(source: source)
tree.walk(&collector)
@wildthink
wildthink / Always.swift
Created December 12, 2021 09:51 — forked from sharplet/Always.swift
A Combine publisher that repeatedly emits the same value as long as there is demand
// Copyright (c) 2019–20 Adam Sharp and thoughtbot, inc.
//
// Permission is hereby granted, free of charge, to any person obtaining a copy
// of this software and associated documentation files (the "Software"), to deal
// in the Software without restriction, including without limitation the rights
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
// copies of the Software, and to permit persons to whom the Software is
// furnished to do so, subject to the following conditions:
//
// The above copyright notice and this permission notice shall be included in
@wildthink
wildthink / EasyMeasurements.swift
Last active November 10, 2021 04:12
Syntactic Sugar for Measurements in Swift
import Foundation
public typealias Mass = Measurement<UnitMass>
public typealias Duration = Measurement<UnitDuration>
public typealias Angle = Measurement<UnitAngle>
public typealias Length = Measurement<UnitLength>
public typealias Speed = Measurement<UnitSpeed>
public extension Measurement where UnitType: Dimension {
static var zero: Measurement<UnitType> {