Skip to content

Instantly share code, notes, and snippets.

View adam-zethraeus's full-sized avatar
🏔️

adamz adam-zethraeus

🏔️
View GitHub Profile
@markmals
markmals / *Pointer.swift
Last active November 12, 2024 16:44
An approximation of Rust & C++ smart pointers in Swift with non-copyable types
public protocol Pointer<Pointee>: ~Copyable {
associatedtype Pointee
var pointee: Pointee { get nonmutating set }
}
public struct UniquePointer<Pointee>: ~Copyable, Pointer {
private let memory: UnsafeMutablePointer<Pointee>
public var pointee: Pointee {
get { memory.pointee }
@markmals
markmals / ReferenceSet.swift
Last active November 12, 2024 16:46
Vanilla Reactive System
// A reference type Set
private final class ReferenceSet<Element: Hashable>: Hashable, Collection {
typealias Element = Element
typealias Iterator = Set<Element>.Iterator
typealias Index = Set<Element>.Index
typealias Indices = Set<Element>.Indices
typealias SubSequence = Set<Element>.SubSequence
private var inner = Set<Element>()
@robert-cronin
robert-cronin / concatenate_repo.sh
Last active June 18, 2025 19:25
A script for concatenating all the files of a git repo into one file which you can feed into large context LLMs for understanding dependencies
#!/bin/bash
# Check if the script received the correct number of arguments
if [ "$#" -ne 2 ]; then
echo "Usage: $0 <repo_path> <output_file>"
exit 1
fi
REPO_PATH=$1
OUTPUT_FILE=$2
@ole
ole / swift-has-feature.sh
Last active July 3, 2025 17:02
swift-list-features: List Swift compiler upcoming and experimental feature flags. · swift-has-feature: Check if a given compiler knows a specific feature flag, and whether it's an upcoming or experimental flag.
#!/bin/zsh
# Test if the Swift compiler knows about a particular language feature.
#
# Usage:
#
# swift-has-feature [--swift SWIFT_PATH] [--language-version LANGUAGE_VERSION] FEATURE
#
# The feature should be an upcoming or experimental language feature,
# such as `"StrictConcurrency"` or `"ExistentialAny"`.
@realvjy
realvjy / ChoasLinesShader.metal
Last active June 23, 2025 08:12
Choas Lines - Metal Shader
// Lines
float hash( float n ) {
return fract(sin(n)*753.5453123);
}
// Slight modification of iq's noise function.
float noise(vector_float2 x )
{
vector_float2 p = floor(x);
vector_float2 f = fract(x);
@markmals
markmals / signals.swift
Last active March 24, 2024 06:02
An implementation of Solid.js's signals API using Swift's @observable macro
import Foundation
import Observation
@Observable
final class Signal<T> {
var value: T
init(value: T) {
self.value = value
}
@dkun7944
dkun7944 / CDView.swift
Last active May 28, 2025 23:44
SwiftUI + Swift.Shader CD
//
// CDView.swift
// CD
//
// Created by Daniel Kuntz on 7/3/23.
//
import SwiftUI
struct ShapeWithHole: Shape {
@kylemcdonald
kylemcdonald / function-calling.ipynb
Created June 14, 2023 01:10
Example of OpenAI function calling API to extract data from LAPD newsroom articles.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
public struct Locked<T>: LockedValue {
public init(_ value: T) {
let lock = Self.make(for: value)
withLock = { act in
lock.lock()
defer { lock.unlock() }
return act(&lock.unsafe_wrapped)
}
}
@adam-zethraeus
adam-zethraeus / Collection+Ext.swift
Last active June 11, 2023 21:25
Swift Collection Extensions
extension Collection {
func compact<E>() -> [E] where E? == Element {
compactMap { $0 }
}
}
extension Collection {