Skip to content

Instantly share code, notes, and snippets.

@dabrahams
dabrahams / ConcurrentMap.swift
Last active April 3, 2024 04:59
Concurrent Map Implementations, Benchmarked
// See commentary below this gist.
import Foundation
import QuartzCore
// Implementation from https://talk.objc.io/episodes/S01E90-concurrent-map
public final class ThreadSafe<A> {
var _value: A
let queue = DispatchQueue(label: "ThreadSafe")
init(_ value: A) { self._value = value }
@patrickhulce
patrickhulce / mac-setup.sh
Last active September 11, 2024 15:06
GitHub Self-Hosted Runners
#!/bin/bash
# Non-scripted Tasks:
# - Configure device name in Preferences > Sharing
# - Enable Remote Login & Remote Management in Preferences > Sharing
# - Enable automatic login/disable password after sleep in Preferences > Security & Privacy > General
# - Disable screensaver/sleep in Preferences > Energy Saver
# - Disable spotlight indexing of home directory
# - Add a runner in GitHub UI to grab your token https://github.com/<org>/<repo>/settings/actions/runners/new
@shaps80
shaps80 / SwiftUI-TextView.md
Last active May 6, 2023 22:17
A SwiftUI view that wraps a UITextView but provides almost all functionality though modifiers and attempts to closely match the Text/TextField components.
@kiding
kiding / HDRGainMap.swift
Last active May 13, 2025 03:30
Extracting HDR Gain Map from iOS 14.1+ (iPhone 12+) photos
import UIKit
import MobileCoreServices.UTCoreTypes
if #available(iOS 14.1, *) {
let input = Bundle.main.url(forResource: "IMG_0037", withExtension: "HEIC")!
let output = FileManager().temporaryDirectory.appendingPathComponent("IMG_0037.GAIN_MAP.BMP")
let source = CGImageSourceCreateWithURL(input as CFURL, nil)!
// urn:com:apple:photo:2020:aux:hdrgainmap
let dataInfo = CGImageSourceCopyAuxiliaryDataInfoAtIndex(source, 0, kCGImageAuxiliaryDataTypeHDRGainMap)! as Dictionary
import SQLKit
import FluentKit
/// Read each method's comments in the order they appear (from `fieldKey(for:)` through `sqlColumn(for:)`) for an
/// _EXTREMELY_ detailed breakdown of how the heck this all works.
extension Fields {
/// Returns the singular `FieldKey` corresponding to a specific property of the model.
///
/// Detailed operation:
///
@dehesa
dehesa / TaskProgression.swift
Last active February 24, 2025 20:47
Experimental mechanism to track progressions on Swift 6 concurrency.
/// Gathers progression information of all computations within the `operation` block.
///
/// This free function sets the `@TaskLocal` value `Task.unsafeProgress`, which serves as an
/// indicator to any task in the structure concurrency tree to start gathering progression information.
/// Functions supporting _progress_ will forward such data into the `progress` handler.
///
/// ## Features
/// - Progress data forwarding to the `progress` handler.
/// - No locks (and no thread hopping).
/// - Supports concurrent operations.
@MihaelIsaev
MihaelIsaev / Instruction.md
Last active April 18, 2025 04:57
How to patch Swift `static-linux-sdk` with `mimalloc` step-by-step

According to the Performance penalty from the Static Linux SDK post I would like to provide a step-by-step instruction of how to patch static-linux-sdk with mimalloc

Why?

It is important for swift apps – especially for server-side apps – to be performant

Doesn't Static Linux SDK already have mimalloc?

Great question! Maybe in the future — who knows?

If you're from the future, you can check your SDK by running