Skip to content

Instantly share code, notes, and snippets.

@IanKeen
IanKeen / Example.swift
Last active June 26, 2024 07:38
ObservableObjectContainer: Consolidate nested/child ObservableObjects into a single publisher, useful for 'parent' ObservableObjects
// Setup
class Child: ObservableObject {
@Published var value = ""
}
class Parent: ObservableObjectContainer {
let single = Child()
let array = [Child(), Child()]
func updateSingle() {
@IanKeen
IanKeen / EnvironmentValues.swift
Last active January 5, 2024 08:49
SwiftUI: Peek at/extract hidden environment values
import Foundation
import SwiftUI
extension EnvironmentValues {
public func value<T>(_: T.Type = T.self, forKey key: String) -> T? {
guard let value = first(where: { name($0, equals: key) }) else {
print("No EnvironmentValue with key '\(key)' found.")
return nil
}
@stuartcarnie
stuartcarnie / NSEvent+Publisher.swift
Last active March 5, 2023 19:08
Combine Publisher support for NSEvent.addLocalMonitorForEvents
@available(macOS 10.15, *)
extension NSEvent {
static func publisher(scope: Publisher.Scope, matching: EventTypeMask) -> Publisher {
return Publisher(scope: scope, matching: matching)
}
public struct Publisher: Combine.Publisher {
public enum Scope {
case local, global
}
import Foundation
// MARK: - typed predicate types
public protocol TypedPredicateProtocol: NSPredicate { associatedtype Root }
public final class CompoundPredicate<Root>: NSCompoundPredicate, TypedPredicateProtocol {}
public final class ComparisonPredicate<Root>: NSComparisonPredicate, TypedPredicateProtocol {}
// MARK: - compound operators
@bacongravy
bacongravy / js-eval.sh
Last active January 23, 2018 04:28
js-eval - Execute JavaScript, parse JSON, on vanilla macOS (no dev tools or packages installed)
#!/bin/sh
alias js-eval="osascript -l JavaScript -e"
# examples:
js-eval "1+1"
# 2
js-eval "Math.PI"
@stefanbuck
stefanbuck / upload-github-release-asset.sh
Last active November 26, 2023 12:40
Script to upload a release asset using the GitHub API v3.
#!/usr/bin/env bash
#
# Author: Stefan Buck
# License: MIT
# https://gist.github.com/stefanbuck/ce788fee19ab6eb0b4447a85fc99f447
#
#
# This script accepts the following parameters:
#
# * owner
@millermedeiros
millermedeiros / example.js
Last active September 10, 2022 03:06
execute multiple shell commands in series on node.js
// USAGE ------
// ============
var shell = require('./shellHelper');
// execute a single shell command
shell.exec('npm test --coverage', function(err){
console.log('executed test');
}});