This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
export function uuid(value?: string): bigint { | |
const uuid = value || crypto.randomUUID() | |
return BigInt('0x' + uuid.replace(/-/g, '')) | |
} | |
export function uuidString(uuid?: bigint): string { | |
if (!uuid) { | |
return crypto.randomUUID() | |
} | |
const str = uuid.toString(16).padStart(32, '0') |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* MIT License | |
* Copyright (c) 2025 frzi (github.com/frzi) | |
* 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 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
export default class TypedEventTarget<Events extends object> extends EventTarget { | |
override addEventListener<K extends keyof Events, U = Events[K] extends Event ? Events[K] : CustomEvent<Events[K]>>( | |
type: K, | |
listener: (this: this, event: U) => void, | |
options?: AddEventListenerOptions | boolean | |
) { | |
super.addEventListener(type as string, listener as any, options) | |
} | |
override dispatchEvent<K extends keyof Events>(type: K, detail: Events[K]): boolean |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import Combine | |
import SwiftUI | |
import WebKit | |
struct WebView: NSViewRepresentable { | |
let url: URL | |
@Binding var title: String | |
private(set) var onCommitHandlers: [(URL) -> Void] = [] |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import Cocoa | |
final class App { | |
private static var shared: App? | |
static func main() { | |
shared = App() | |
} | |
// MARK: - |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import SwiftUI | |
#if os(macOS) | |
import AppKit | |
struct Blur: NSViewRepresentable { | |
fileprivate var blending: NSVisualEffectView.BlendingMode | |
fileprivate var style: NSVisualEffectView.Material | |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* Keychain.swift | |
* Created by frzi (github.com/frzi) | |
*/ | |
import Foundation | |
import Security | |
class Keychain { | |
fileprivate class func getKeychainQuery(_ key: String) -> NSMutableDictionary { |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/// Example of usage: | |
/// ```swift | |
/// @UserDefault("username") var username: String? = nil | |
/// @UserDefault("maxItems") var maxItems = 100 | |
/// ``` | |
@propertyWrapper | |
struct UserDefault<T> { | |
let defaultValue: T | |
let key: String | |
private let environment: UserDefaults |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* Custom written EventEmitter. | |
* Shares most of the same interface as Node.js' Event Emitter. | |
* Except everything is strongly typed and stored in `#listeners`. | |
*/ | |
type Arguments<T> = [T] extends [(...args: infer U) => any] ? U : [T] extends [void] ? [] : [T] | |
type Listener<T> = (...argv: Arguments<T>) => void | |
interface DefaultEvents { |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// https://gist.github.com/frzi/5c397d396db3b94c281d57e803227db8 | |
const MINE = -1 | |
function generateSpaces(width = 9, height = 9, mines = 15) { | |
const totalSpaces = width * height | |
mines = Math.min(totalSpaces - 1, Math.abs(mines)) | |
let spaces = new Array(totalSpaces).fill(0) | |
let openSpaces = spaces.map((_, index) => index) |
NewerOlder