Skip to content

Instantly share code, notes, and snippets.

@gavinmn
gavinmn / KeyboardAttachedView.swift
Created August 20, 2024 02:38
Attach a view to the keyboard with interactive dismissal support
//
// ContentView.Swift
// KeyboardAttachedView
//
// Created by Gavin Nelson on 8/19/24.
//
import SwiftUI
import UIKit
@myleshyson
myleshyson / Command.swift
Last active October 24, 2024 05:57
Execute CLI Commands with Swift. Supports generating output, streaming output, and running sudo commands.
import Foundation
struct ShellCommand {
@discardableResult
static func stream(_ command: String) -> Int32 {
let outputPipe = Pipe()
let task = self.createProcess([command], outputPipe)
outputPipe.fileHandleForReading.readabilityHandler = { fileHandle in self.streamOutput(outputPipe, fileHandle) }
do {
@macshome
macshome / IOKit.swift
Last active February 25, 2025 20:26
This playground shows you a few different ways to get device info via IOKit.
// This playground shows you a few different ways to get device info via IOKit.
// If you want to explore IOKit and look for interesting data I would download
// the Additional Developer Tools from Apple and use the IORegistryExplorer app.
// It makes it super easy to poke around in the IOKit planes.
import IOKit
import Foundation
// For convient access we can make a computed getter for the PlatformExpert.
// Traditionally this has been where you go to find all sorts of data about the
@kirb
kirb / Device.swift
Last active January 2, 2024 04:18
Get Mac device image based on device class - https://kirb.me/2023/04/15/mac-device-icon-by-device-class.html
import Cocoa
import UniformTypeIdentifiers
extension UTTagClass {
static let deviceModelCode = UTTagClass(rawValue: "com.apple.device-model-code")
}
extension UTType {
static let macBook = UTType("com.apple.mac.laptop")
static let macBookWithNotch = UTType("com.apple.mac.notched-laptop")
@christianselig
christianselig / Locale+SFSymbol.swift
Created September 3, 2021 21:54
Returns an SF Symbol currency image that match's the device's current locale, for instance dollar in North America, Indian rupee in India, etc.
extension Locale {
/// Returns an SF Symbol currency image that match's the device's current locale, for instance dollar in North America, Indian rupee in India, etc.
func currencySFSymbol(filled: Bool, withConfiguration configuration: UIImage.Configuration? = nil) -> UIImage {
// Default currency symbol will be the Animal Crossing Leaf coin 􁂬 to remain impartial to any specific country
let defaultSymbol = UIImage(systemName: "leaf.circle\(filled ? ".fill" : "")")!
guard let currencySymbolName = currencySymbolNameForSFSymbols() else { return defaultSymbol }
let systemName = "\(currencySymbolName).circle\(filled ? ".fill" : "")"
return UIImage(systemName: systemName, withConfiguration: configuration) ?? defaultSymbol
@rjchatfield
rjchatfield / ArrayBuilder.swift
Last active February 20, 2025 12:33
ArrayBuilder - Swift ~~FunctionBuilder~~ ResultBuilder
@resultBuilder
public struct ArrayBuilder<Element> {
public static func buildPartialBlock(first: Element) -> [Element] { [first] }
public static func buildPartialBlock(first: [Element]) -> [Element] { first }
public static func buildPartialBlock(accumulated: [Element], next: Element) -> [Element] { accumulated + [next] }
public static func buildPartialBlock(accumulated: [Element], next: [Element]) -> [Element] { accumulated + next }
// Empty Case
public static func buildBlock() -> [Element] { [] }
// If/Else
@IsaacXen
IsaacXen / README.md
Last active March 2, 2025 02:20
(Almost) Every WWDC videos download links for aria2c.
@atomicbird
atomicbird / wwdc2019-online-sessions.md
Last active May 29, 2020 22:59
WWDC 2019 Online-only Sessions

At WWDC 2019 Apple released some videos directly online, with no corresponding live session. This is a list of those videos with links to the video pages.

Some sessions were presented during WWDC but then split into multiple videos when posted online. This list includes the online versions, since they don't appear in the WWDC schedule. For example WWDC included session 711, "Introducing Combine and Advances in Foundation". This was split into two online videos-- 722, "Introducing Combine", and 723, "Advances in Foundation". Both 722 and 723 are included here.

@rhythmus
rhythmus / all-Unicode-BMP-chars-sorted-by-UCA.md
Created April 10, 2018 21:55
All Unicode characters, sorted alphabetically by Unicode Collation algorithm

All Unicode characters, sorted alphabetically

Using Unicode Collation Algorithm (as implemented by ICU Project).

See discussion at forum.glyphsapp.com.

҈ ҉ ؀ ؁ ؂ ؃ ؄ ؅ ـ ۝ ܏ ߺ ࠤ ࠨ ः ং ঃ ਃ ઃ ଂ ଃ ఁ ం ః ಂ ಃ ം ഃ ං ඃ ༾ ༿ ཿ း ះ ៈ ᠊ ᪾ ⃝ ⃞ ⃟ ⃠ ⃢ ⃣ ⃤ 〮 〯 ꙰ ꙱ ꙲ ﱞ ﱟ ﱠ ﱡ ﱢ ﱣ ﳲ ﳳ ﳴ ﹰ ﹱ ﹲ ﹳ ﹴ ﹶ ﹷ ﹸ ﹹ ﹺ ﹻ ﹼ ﹽ ﹾ ﹿ ゙ ゚    ‾ ﹉ ﹊ ﹋ ﹌ _ ︳ ︴ ﹍ ﹎ ﹏ _ ‗ - ﹣ - ֊ ᠆ ᠇ ‐ ‑ ‒ – ︲ — ︱ ﹘ ― ⸺ ⸻ ⁓ ⸗ ⹀ 〜 〰 ゠ ・ ・ , ︐ ﹐ , ⸴ ⸲ ⹁ ՝ ، ؍ ٫ ٬ ߸ ᠂ ᠈ 、 ︑ ﹑ 、 ﹅ ﹆ ; ; ︔ ﹔ ; ؛ ⁏ ⸵ : ︓ ﹕ : ⩴ ։ ؞ ܃ ܄ ܅ ܆ ܇ ܈ ࠰ ࠱ ࠲ ࠳ ࠴ ࠵ ࠶ ࠷ ࠸ ࠹ ࠺ ࠻ ࠼ ࠽ ࠾ ፡ ፣ ፤ ፥ ፦ ᠄ ᠅ ༔ ៖ ! ︕ ﹗ ! ‼ ⁉ ¡ ՜ ߹ ? ︖ ﹖ ? ⁈ ⁇ ¿ ⸮ ՞ ؟ ܉ ፧ ⳺ ⳻ ‽ ⸘ . ․ ﹒ . ‥ ︰ … ︙ ᠁ ۔ ܁ ܂ ። ᠃ ᠉ ⳹ ⳾ ⸰ ⸼ 。 ︒ 。 · · ⸱ ⸳ । ॥ ᰻ ᰼ ꤯ ၊ ။ ។ ៕ ܀ ߷ ჻ ፠ ፨ ⁕ ⁖ ⁘ ⁙ ⁚ ⁛ ⁜ ⁝ ⁞ ⸪ ⸫ ⸬ ⸭ ⸽ ⳼ ⳿ ⸙ ' ' ‘ ’ ‚ ‛ ‹ › " “ ” „ ‟ ⹂ 〝 〞 〟 « » ( ⁽ ₍ ︵ ﹙ ( ⑴ ⑽ ⑾ ⑿ ⒀ ⒁ ⒂ ⒃ ⒄ ⒅ ⒆ ⑵ ⒇ ⑶ ⑷ ⑸ ⑹ ⑺ ⑻ ⑼ ⒜ ⒝ ⒞ ⒟ ⒠ ⒡ ⒢ ⒣ ⒤ ⒥ ⒦ ⒧ ⒨ ⒩ ⒪ ⒫ ⒬ ⒭ ⒮ ⒯ ⒰ ⒱ ⒲ ⒳ ⒴ ⒵ ㈀ ㈎ ㈁ ㈏ ㈂

@DivineDominion
DivineDominion / FolderContentMonitor.swift
Last active March 10, 2023 15:50
Wrapper for using C FSEvents with Swift 4
//
// Based on: https://blog.beecomedigital.com/2015/06/27/developing-a-filesystemwatcher-for-os-x-by-using-fsevents-with-swift-2/
//
import Foundation
public struct Event: CustomStringConvertible {
public let eventId: FSEventStreamEventId
public let eventPath: String