Skip to content

Instantly share code, notes, and snippets.

@macguru
macguru / ScopedTask.swift
Last active November 7, 2025 05:28
ScopedTask: A wrapper around Task that auto-cancels when going out of scope.
/// A task that is cancelled if goes out of scope, i.e. the last reference on it has been discarded.
public final class ScopedTask<Success: Sendable, Failure: Error>: Sendable {
/// The underlying task
let wrapped: Task<Success, Failure>
/// Wraps a task into a scoped task.
init(wrapping task: Task<Success, Failure>) {
wrapped = task
}
@henryivesjones
henryivesjones / postgresql_date_timestamp_interval_cheat_sheet.md
Created February 14, 2023 16:56
PostgreSQL DATE, TIMESTAMP, and INTERVAL cheat sheet

PostgreSQL DATE, TIMESTAMP, and INTERVAL cheat sheet

Working with DATE, TIMESTAMP, and INTERVAL in PostgreSQL can be confusing. In this article I will go over the three date/time related data types, and the two most useful date/time functions: DATE_PART and DATE_TRUNC. Finally, I will provide some real life examples of how these types and functions can be used within queries.

Types

PostgreSQL Date/Time Documentation

DATE

The DATE type contains the year, month, and day of a date. It is not possible to do any type of time related functions on a DATE without first converting it to a TIMESTAMP. Subtracting two DATE values from one another results in an INT representing the # of days between.

TIMESTAMP

The TIMESTAMP type contains a year, month, day, hour, minute, second, and microsecond. This is the type that I most often use.

@amirdew
amirdew / ModifyCodable.swift
Last active May 29, 2024 06:05
Modifying private and immutable properties (let) in Codable instances
import Foundation
extension Decodable where Self: Encodable {
/// Creates a new instance and changes the value for the provided key.
///
/// - Parameters:
/// - key: The key path to the property that you want to modify.
/// Use period to separate levels and [] for indexes.
/// Examples: "id", "name.firstName", "children[2].name.firstName"
///
@fabiolimace
fabiolimace / uuidv7.c
Last active January 17, 2024 23:06
UUID v7 for C
#include <time.h>
#include <stdio.h>
#include <errno.h>
#include <stdlib.h>
#include <stdint.h>
#include <sys/random.h>
#define UUID_T_LENGTH (16)
#define UNIX_TS_LENGTH (6)
@insidegui
insidegui / reloadplugins.sh
Created January 29, 2022 23:00
Make your Mac app's extensions immediately available on macOS with a run script build phase
# Add this to a "Run Script" build phase in your app's main target, as the last step.
# It will use the pluginkit command-line tool to force the plugin system on macOS to add your extensions to its database, making them available.
# I made this specifically for widgets, but it should work for pretty much any extension type (appex bundle).
find $CODESIGNING_FOLDER_PATH -name '*.appex' -exec pluginkit -a {} \;
@ktustanowski
ktustanowski / SNClassifySoundRequest.knownClassifications.txt
Created November 6, 2021 10:52
List of supported classifications for SNClassifySoundRequest
0. speech
1. shout
2. yell
3. battle_cry
4. children_shouting
5. screaming
6. whispering
7. laughter
8. baby_laughter
9. giggling
@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
@jordansinger
jordansinger / AppleLogo.swift
Created June 16, 2021 18:37
Original Apple logo in SwiftUI
import SwiftUI
struct ContentView: View {
var body: some View {
VStack(spacing: 0) {
Color.green
Color.green
Color.green
Color.yellow
Color.orange
@kieranb662
kieranb662 / Rainbow.md
Last active July 11, 2025 11:59
[Rainbow ViewModifier] Rainbow animation view modifiers for SwiftUI #SwiftUI #ViewModifier

Rainbow Example

@timothycosta
timothycosta / GeometryFinder.swift
Created July 11, 2019 03:41
Find the geometry of a SwiftUI View
//
// GeometryFinder.swift
//
// Created by Timothy Costa on 2019/06/24.
// Copyright © 2019 timothycosta.com. All rights reserved.
//
import SwiftUI
struct RectPreferenceKey: PreferenceKey {