Skip to content

Instantly share code, notes, and snippets.

@realvjy
realvjy / ChoasLinesShader.metal
Last active February 23, 2024 04:32
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
}
@kylemcdonald
kylemcdonald / function-calling.ipynb
Created June 14, 2023 01:10
Example of OpenAI function calling API to extract data from LAPD newsroom articles.
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 {
import SwiftUI
struct ContentView: View {
@State var pictureExpanded = false
var body: some View {
VStack(alignment: .leading, spacing: 20.0) {
Text("Once upon a time there was a turtle named George who made friends with a giraffe at the local water park and then they went on lots of adventures together.")
Button {
@adam-zethraeus
adam-zethraeus / RandomPastelUIColor.swift
Last active March 7, 2023 09:28
UIColor extension to generate a random pastel
import UIKit
public extension UIColor {
private static var randomLightness: CGFloat {
Double.random(in: 0...1)
}
private static var randomRGB: UIColor {
UIColor(
import PackageDescription
import Foundation
import Swift
extension PackageDescription.Product {
public static func iOSApplication(
name: Swift.String,
targets: [Swift.String],
bundleIdentifier: Swift.String? = nil,
teamIdentifier: Swift.String? = nil,
@kylehughes
kylehughes / TornRectangle.swift
Last active August 12, 2023 01:20
A rectangle shape for SwiftUI that can render any edge like a torn piece of paper.
// Copyright 2021 Kyle Hughes
//
// 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 all copies or substantial portions of the
// Software.
//
@saagarjha
saagarjha / library_injector.cpp
Last active March 27, 2024 09:50
Load a library into newly spawned processes (using DYLD_INSERT_LIBRARIES and EndpointSecurity)
// To compile: clang++ -arch x86_64 -arch arm64 -std=c++20 library_injector.cpp -lbsm -lEndpointSecurity -o library_injector,
// then codesign with com.apple.developer.endpoint-security.client and run the
// program as root.
#include <EndpointSecurity/EndpointSecurity.h>
#include <algorithm>
#include <array>
#include <bsm/libbsm.h>
#include <cstdint>
#include <cstdlib>