Skip to content

Instantly share code, notes, and snippets.

blueprint:
name: Lutron Caseta Pico 2-button Remote
description: Short and long press automations for the Pico 2-button remote
domain: automation
input:
pico_remote:
name: Pico Remote
description: Select the Pico remote to configure
selector:
device:
@nanoxd
nanoxd / xcutils.rb
Created July 18, 2020 02:33
Brew file for xcutil
class Xcutils < Formula
desc 'A collection of utilities that aid with the use of the Xcode CLI, packaged as a single SwiftPM Package.'
homepage 'https://github.com/JosephDuffy/xcutils'
url 'https://github.com/JosephDuffy/xcutils/archive/v0.1.2-rc2.tar.gz'
sha256 '82200150a8d6ce1e91f7258724716e52fb1c932e78bafb596d40e32388c39583'
license 'MIT'
version '0.1.2'
def install
system 'swift', 'build',
class SpmPlayground < Formula
desc "Command line tool to create an Xcode project with a Playground and an SPM library ready for use in it"
homepage "https://github.com/finestructure/SPMPlayground"
url "https://github.com/finestructure/SPMPlayground/archive/0.4.0.tar.gz"
sha256 "774868a14a8bc5f5002979613543463fee7f381b7349b865e956a1a44fbf3940"
version '0.4.0'
depends_on :xcode => ["11.0", :build, :test]
def install
import RxRelay
import RxSwift
@propertyWrapper
public struct BehaviorRelayWrapping<T> {
private let subject: BehaviorRelay<T>
// MARK: PropertyWrapper
public let wrappedValue: Observable<T>
@nanoxd
nanoxd / rbenv.plugin.zsh
Created August 19, 2019 10:51
Plugin for rbenv on ZSH
found_rbenv=''
rbenvdirs=("$HOME/.rbenv" "$HOME/.local/rbenv" "/usr/local/opt/rbenv" "/usr/local/rbenv" "/opt/rbenv")
for rbenvdir in "${rbenvdirs[@]}" ; do
if [ -z "$found_rbenv" ] && [ -d "$rbenvdir/versions" ]; then
found_rbenv=true
if [ -z "$RBENV_ROOT" ]; then
RBENV_ROOT=$rbenvdir
export RBENV_ROOT
fi
@nanoxd
nanoxd / Pendulum.swift
Created March 30, 2019 21:55
A wrapper around a repeating timer that does not require invalidation.
/// A wrapper around a repeating timer that does not require invalidation.
final class Pendulum {
let timer: Timer
init(seconds: TimeInterval, closure: @escaping () -> ()) {
timer = Timer.scheduledTimer(
withTimeInterval: seconds,
repeats: true,
block: { _ in
closure();
@nanoxd
nanoxd / Request+Result.swift
Last active March 30, 2019 21:49
Request+Result.swift #swift
extension Request where Response: Decodable {
func handle(
response: Result<Data, Error>,
completion: (Result<Response, Error>) -> Void) {
completion(Result {
try JSONDecoder().decode(Response.self, from: response.get())
})
}
}
@nanoxd
nanoxd / main.swift
Created February 7, 2019 23:56
[Assert Main Queue] Assert you're on main queue. Note that main thread and main queue are not always the same thing http://blog.benjamin-encz.de/post/main-queue-vs-main-thread/
dispatchPrecondition(
condition: DispatchPredicate.onQueue(DispatchQueue.main)
)
@nanoxd
nanoxd / Either.swift
Created December 22, 2018 03:16
[Either] A type representing an alternative of one of two types.
/// A type representing an alternative of one of two types.
///
/// By convention, and where applicable, `Left` is used to indicate failure, while `Right` is used to indicate success. (Mnemonic: “right” is a synonym for “correct.”)
///
/// Otherwise, it is implied that `Left` and `Right` are effectively unordered alternatives of equal standing.
public enum Either<Left, Right> {
case left(Left)
case right(Right)
/// Returns the value of `Left` instances, or `nil` for `Right` instances.
@nanoxd
nanoxd / HelloWorldViewModel.swift
Created December 16, 2018 02:34
[ViewModelType] Provide a clear contract between inputs/outputs desired in a view model
final class HelloWorldViewModel: ViewModelType {
let input: Input
let output: Output
struct Input {
let name: Anyobserver<String>
}
struct Output {
let greeting: Driver<String>