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) |
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
/** | |
* Potential candidate for @types/polka. | |
*/ | |
// Type definitions for polka 1.0.0 | |
// Project: https://github.com/lukeed/polka | |
// Definitions by: Freek Zijlmans <https://github.com/frzi> | |
// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped | |
// TypeScript Version: 3.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
// Put me somewhere accessible. | |
const useForceUpdate = () => { | |
const [_, setState] = useState(0) | |
return () => setState(val => val + 1) | |
} | |
// Example. | |
const Component = () => { | |
const forceUpdate = useForceUpdate() |
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
// Fuck it. | |
private func makeString(prefix: String? = nil, values: [Any]) -> String { | |
var str = prefix ?? "" | |
for val in values { | |
str += "\(val) " | |
} | |
return str | |
} |
NewerOlder