Skip to content

Instantly share code, notes, and snippets.

View griffin-stewie's full-sized avatar

griffin-stewie griffin-stewie

View GitHub Profile
@chockenberry
chockenberry / ql.sh
Last active March 4, 2024 23:40
QuickLook for macOS shell
#!/bin/sh
# usage:
# ql /tmp/file.jpg
# cat /tmp/file.jpg | ql
# cal -h | ql
if [ -z "$*" ]; then
cat > /tmp/ql.stdin
mime_type=$(file --brief --mime-type /tmp/ql.stdin)
@NSExceptional
NSExceptional / Shell.swift
Created June 25, 2022 23:31
Leverage @dynamicMemberLookup to invoke shell commands dynamically
//
// Shell.swift
//
// Created by Tanner Bennett on 6/25/22.
// Copyright Tanner Bennett (c) 2022
//
import Foundation
extension StringProtocol {
@tarunon
tarunon / TaskContext.swift
Last active September 25, 2021 09:30
Swift Task Extension for slim AsyncSequence access.
import UIKit
class Base: UIViewController {
func mySomeAsyncSequence() -> AsyncStream<String> {
fatalError()
}
func use(_ value: String) {
print(value)
}
@treastrain
treastrain / ConcurrencyNFCApp.swift
Created August 27, 2021 20:45
SwiftUI App + Core NFC + Swift Concurrency を使って書いた、交通系電子マネーカードの残高読み取りサンプル。 https://twitter.com/treastrain/status/1431356306963587072
//
// ConcurrencyNFCApp.swift
// ConcurrencyNFC
//
// Created by treastrain on 2021/08/28.
//
import SwiftUI
import CoreNFC
@jpsim
jpsim / parallel_map.swift
Created June 11, 2021 15:18
Parallel map in Swift
extension Array {
func parallelMap<T>(transform: (Element) -> T) -> [T] {
var result = ContiguousArray<T?>(repeating: nil, count: count)
return result.withUnsafeMutableBufferPointer { buffer in
DispatchQueue.concurrentPerform(iterations: buffer.count) { idx in
buffer[idx] = transform(self[idx])
}
return buffer.map { $0! }
}
}
extension Result {
public func `catch`(_ handler: () throws -> Success) -> Result<Success, Error> {
flatMapError { _ in
.init { try handler() }
}
}
public func `catch`(_ handler: (Failure) throws -> Success) -> Result<Success, Error> {
flatMapError { error in
.init { try handler(error) }
@shaundon
shaundon / ContentView.swift
Created March 4, 2021 11:45
MapView with polyline support in SwiftUI
import SwiftUI
import MapKit
struct ContentView: View {
@State private var region = MKCoordinateRegion(
// Apple Park
center: CLLocationCoordinate2D(latitude: 37.334803, longitude: -122.008965),
span: MKCoordinateSpan(latitudeDelta: 0.01, longitudeDelta: 0.01)
)
@Hiroki-Kawakami
Hiroki-Kawakami / AppDelegate.swift
Created February 10, 2021 19:22
SwiftUI Change Status Bar Color with Custom Hosting Controller
//
// AppDelegate.swift
// StatusBarTest
//
// Created by hiroki on 2021/02/11.
//
import UIKit
import SwiftUI
@nicklockwood
nicklockwood / Color.swift
Created January 19, 2021 23:49
Getting the Display P3 values back out of a UIColor created with init(displayP3Red:green:blue:alpha:)
import UIKit
// Create color using P3 color space
let linearColor = UIColor(displayP3Red: 1, green: 0.5, blue: 0.2, alpha: 1)
do {
var r: CGFloat = 0, g: CGFloat = 0, b: CGFloat = 0, a: CGFloat = 0
linearColor.getRed(&r, green: &g, blue: &b, alpha: &a)
print(r, g, b, a) // 1.07, 0.46, 0.0, 1.0 - not the expected values
}
@1amageek
1amageek / AppDelegate.swift
Created November 4, 2020 08:19
Adding Firebase to AppDelegate in SwiftUI
import SwiftUI
import Firebase
class AppDelegate: UIResponder, UIApplicationDelegate {
func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey : Any]? = nil) -> Bool {
FirebaseApp.configure()
return true
}
}