Skip to content

Instantly share code, notes, and snippets.

import SwiftUI
import WebKit
import Combine
class WebViewData: ObservableObject {
@Published var loading: Bool = false
@Published var scrollPercent: Float = 0
@Published var url: URL? = nil
@Published var urlBar: String = "https://nasa.gov"
@mecid
mecid / Calendar.swift
Last active September 2, 2025 01:55
SwiftUI Calendar view using LazyVGrid
import SwiftUI
extension Calendar {
func generateDates(
inside interval: DateInterval,
matching components: DateComponents
) -> [Date] {
var dates: [Date] = []
dates.append(interval.start)
@dynamicMemberLookup
struct Template {
var template : String
private var data : [String:String]
var populatedTemplate : String { data.reduce(template) { $0.replacingOccurrences(of: "${\($1.key)}", with: $1.value) } }
init(template: String, data: [String:String] = [:]) {
self.template = template
self.data = data
}
@maximkrouk
maximkrouk / Index.md
Last active December 15, 2023 03:43
Index of all gists
#! /usr/bin/swift
//
// - This is just some AppKit boilerplate to launch a window.
//
import AppKit
@available(OSX 10.15, *)
class AppDelegate: NSObject, NSApplicationDelegate {
let window = NSWindow()
let windowDelegate = WindowDelegate()
import Foundation
public protocol JSONEncodable: Encodable {
static var keyEncodingStrategy: JSONEncoder.KeyEncodingStrategy { get }
static var dateEncodingStrategy: JSONEncoder.DateEncodingStrategy { get }
static var dataEncodingStrategy: JSONEncoder.DataEncodingStrategy { get }
static var nonConformingFloatEncodingStrategy: JSONEncoder.NonConformingFloatEncodingStrategy { get }
func toJSON() throws -> Data
}
// Created by Marcin Krzyzanowski
import Foundation
public protocol JSONEncodable: Encodable { }
public extension JSONEncodable {
func toJSON(using encoder: @autoclosure () -> JSONEncoder = JSONEncoder()) throws -> String {
try String(decoding: encoder().encode(self), as: UTF8.self)
}
@AvdLee
AvdLee / DarwinNotificationCenter.swift
Last active March 25, 2025 19:09
A notification center for Darwin Notifications. MIT License applies.
//
// DarwinNotificationCenter.swift
//
// Copyright © 2017 WeTransfer. All rights reserved.
//
import Foundation
/// A Darwin notification payload. It does not contain any userInfo, a Darwin notification is purely event handling.
public struct DarwinNotification {
@dannyhertz
dannyhertz / TalkDockViewController.swift
Created December 21, 2018 18:52
VC & VM from FuncConf Talk "From Sketch to Xcode: Building Functional Reactive View Models from the Ground Up"
//
// TalkDockViewController.swift
// Dockee
//
// Created by Danny Hertz on 11/30/18.
// Copyright © 2018 Danny Hertz. All rights reserved.
//
import Foundation
import RxCocoa