Skip to content

Instantly share code, notes, and snippets.

@nanoxd
nanoxd / Collection+anySatisfy.swift
Created December 10, 2018 12:17
[Collection.anySatisfy] With the introduction of allSatisfy, we can cleanly represent the inverse.
extension Collection {
func anySatisfy(_ p: (Element) -> Bool) -> Bool {
return !self.allSatisfy { !p($0) }
}
}
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 / run.sh
Last active June 10, 2019 19:44
[Xcode Diet] Clean up after Xcode's voracious hard drive appetite
#!/usr/bin/env sh
set -e
fancy_echo() {
local fmt="$1"; shift
printf "\n$fmt\n" "$@"
}
@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 / fix-xcode
Last active March 15, 2019 12:17
Xcode Scripts
#!/usr/bin/env sh
# Xcode sometimes gets sad and won't index or other shenanigans. You can easily cheer up Xcode
# and get things happy again by simply removing some files. This little script does just that.
# Quit Xcode
osascript -e 'tell app "Xcode" to quit'
# Remove derived data
rm -rf ~/Library/Developer/Xcode/DerivedData/*