Skip to content

Instantly share code, notes, and snippets.

@JaviSoto
JaviSoto / zha-moes-zigbee-rotary-smart-knob-remote-control.yaml
Last active July 16, 2023 02:28 — forked from blizzrdof77/zha-moes-zigbee-rotary-smart-knob-remote-control.yaml
ZHA - Moes Tuya Smart Knob (TS004F) controller for light dimming
blueprint:
name: ZHA - Moes Tuya Smart Knob (TS004F) controller for light dimming
description: Control a light with a Tuya smart knob.
domain: automation
source_url: https://gist.github.com/JaviSoto/0a419981a2f3a8d5be0c88a9d4f7bd6d#file-zha-moes-zigbee-rotary-smart-knob-remote-control-yaml
input:
remote:
name: Smart Knob Device
description: Moes Tuya Smart Knob Device to use
selector:
@JaviSoto
JaviSoto / AsyncJSONDecoder.swift
Created January 4, 2022 17:07
AsyncJSONDecoder Swift Playground
import Foundation
import PlaygroundSupport
PlaygroundPage.current.needsIndefiniteExecution = true
let json = """
[
{
"a": 1,
"b": {"c": false, "d": "foo"}
@JaviSoto
JaviSoto / swiftlint.yml
Created June 16, 2020 17:29
disallowed_racist_terms_of_art SwiftLint
disallowed_racist_terms_of_art:
name: "Disallowed racist terms of art"
regex: 'blacklist|whitelist|^((?<!git)[^\n])*master(?! (manifest|playlist))|slave'
message: "Please, refrain from using terms which have racist connotations. Consider alternatives such as allow, disallow, primary, secondary..."
severity: error
@JaviSoto
JaviSoto / UIView+TWSafeAreaInsets.swift
Last active April 14, 2020 11:55
Status-bar agnostic UIView.safeAreaInsets API
extension UIView {
/// Convenience API to query iOS 11's `UIView.safeAreaInsets`'s insets (also known as "#NotEmbraceTheNotch")
/// in a backwards compatible API.
/// It also differs slightly from `UIView.safeAreaInsets` in that it only takes the "Notch" into account
/// and not the status bar. This allows you to inset content so that the notch doesn't clip it, but you can still
/// lay it out below the status bar.
/// Note: This won't be as versitile as the UIKit version because it won't take into account things like navigation bars,
/// but it should be correct for views in "full-screen" view controllers, where the UIKit `safeAreaInsets` API falls short.
var twSafeAreaInsets: UIEdgeInsets {
guard #available(iOS 11.0, *) else {
@JaviSoto
JaviSoto / wwdc16.md
Created July 15, 2016 20:26 — forked from mackuba/wwdc16.md
New stuff from WWDC 2016

Following the tradition from last year, here's my complete list of all interesting features and updates I could find in Apple's OSes, SDKs and developer tools that were announced at this year's WWDC. This is based on the keynotes, the "What's New In ..." presentations and some others, Apple's release notes, and blog posts and tweets that I came across in the last few weeks.

If for some reason you haven't watched the talks yet, I really recommend watching at least the "State of the Union" and the "What's New In" intros for the platforms you're interested in. The unofficial WWDC Mac app is great way to download the videos and keep track of what you've already watched.

If you're interested, here are my WWDC 2015 notes (might be useful if you're planning to drop support for iOS 8 now and start using some iOS 9 APIs).


OSX → macOS 10.12 Sierra

@JaviSoto
JaviSoto / NibInstantiable.swift
Last active April 14, 2020 11:55
RSwift Fabric Extensions
import UIKit
import Rswift
struct NibResource: NibResourceType {
let name: String
let bundle: NSBundle
init(name: String, bundle: NSBundle = NSBundle.mainBundle()) {
self.name = name
self.bundle = bundle
@JaviSoto
JaviSoto / Example.swift
Last active July 17, 2017 06:16
TableSectionDataDiffing
var sections: [MySectionType] {
didSet {
let operations = TableSectionDataDiffing.tableOperationsToUpdateFromSections(sections: oldValue, toSections: sections)
self.tableView.applyTableOperations(operations, withAnimations: updateAnimations)}
}
}
@JaviSoto
JaviSoto / RAC+logEvents.swift
Created April 30, 2016 00:05
RAC logEvents
public enum ReactiveCocoaEventType {
case Started
case Next
case Completed
case Failed
case Terminated
case Disposed
case Interrupted
public static let allEvents: Set<ReactiveCocoaEventType> = {
@JaviSoto
JaviSoto / DataLoadState.swift
Last active April 14, 2020 11:54
DataLoadState
//
// DataLoadState.swift
// Fabric
//
// Created by Javier Soto on 3/16/16.
// Copyright © 2016 Fabric. All rights reserved.
//
import Foundation
import ReactiveCocoa
@JaviSoto
JaviSoto / SampleViewController.swift
Last active January 23, 2020 09:20
Init based Storyboard View Controller Instantiation
final class SampleViewController: StoryboardBackedViewController {
// Unfortunately this must be an IUO var, so that we can set the value after super.init
private var member: Foo!
// Proper dependency injection in a storyboard backed VC!
init(foo: Foo) {
super.init(storyboardIdentifier: "SampleViewControllerIdentifier")
// We have to set the members *after* calling super.init, since it changes the instance of `self`.
self.member = foo