Skip to content

Instantly share code, notes, and snippets.

@mckeed
mckeed / pre-commit
Last active April 15, 2024 23:52
Run rubocop on only staged files in git pre-commit
#!/bin/sh
STAGED_FILES=$(git diff-index HEAD --name-only --cached)
if [[ -z $STAGED_FILES ]]
then
exit # no staged files, no need to run rubocop
fi
# Checks if any staged files have unstaged changes
# otherwise rubocop isn't running on what is actually
@mckeed
mckeed / LoadView.swift
Created August 12, 2022 20:02
SwiftUI view that calls a load function and shows a `LoadingView: UIView` until the `isLoading` binding is changed to false, then displays its contents.
import SwiftUI
typealias IsLoadingBool = Bool // To help remember which way the bool goes (false means ready to display)
protocol LoadedView {
func load() -> Binding<IsLoadingBool>
}
// LoadingView is an existing full-screen UIView in my codebase.
// This could be replaced by any custom View
@mckeed
mckeed / strong_parameters.rb
Created June 5, 2012 22:24
Before filters to make rails/strong_parameters work with CanCan's load_resource or load_and_authorize_resource.
require 'strong_parameters'
class ActiveRecord::Base
include ActiveModel::ForbiddenAttributesProtection
end
class ActionController::Base
# Use this with CanCan's load_resource to permit a set of params before
# it tries to build or update a resource with them.
@mckeed
mckeed / zigbee_catchall
Last active November 3, 2020 18:06
Catchall ZigBee packet format
FIELD BYTES
profile ID: 2
cluster ID: 2
source EP: 1
dest EP: 1
options: 2
type: 1
source: 2
clustersp: 1
mfgsp: 1
@mckeed
mckeed / intermatic-dimmer.groovy
Created July 31, 2014 22:04
Intermatic Dimmer SmartThings Device Type
metadata {
// Automatically generated. Make future change here.
definition (name: "Intermatic Dimmer", namespace: "mckeed", author: "Duncan") {
capability "Switch Level"
capability "Actuator"
capability "Switch"
capability "Refresh"
capability "Sensor"
}
@mckeed
mckeed / zwave-smoke-alarm.groovy
Created October 10, 2013 15:48
SmartThings device type handler for the BRK First Alert ZSMOKE
metadata {
simulator {
}
tiles {
standardTile("smoke", "device.smoke", width: 2, height: 2) {
state("clear", label:"clear", icon:"st.alarm.smoke.clear", backgroundColor:"#ffffff")
state("detected", label:"SMOKE", icon:"st.alarm.smoke.smoke", backgroundColor:"#e86d13")
state("tested", label:"TEST", icon:"st.alarm.smoke.test", backgroundColor:"#e86d13")
}
@mckeed
mckeed / ridiculously-automated-zwave-garage-door.groovy
Last active March 20, 2019 17:53
Ridiculously Automated Garage Door for GD00Z
/**
* Ridiculously Automated Garage Door
*
* Author: SmartThings
*
* Monitors arrival and departure of car(s) and
*
* 1) opens door when car arrives,
* 2) closes door after car has departed (for N minutes),
* 3) opens door when car door motion is detected,
@mckeed
mckeed / aeon-siren-with-sound-cmds.groovy
Last active October 24, 2018 01:56
Aeon Siren w/sound commands
/**
* Aeon Siren with Sound Commands + revert to default
*
* Author: SmartThings
* Date: 2014-07-15
*/
metadata {
definition (name: "Aeon Siren", namespace: "smartthings", author: "SmartThings") {
capability "Actuator"
capability "Alarm"
@mckeed
mckeed / aeon-rgbw-bulb.groovy
Created July 17, 2015 04:10
Aeon Labs RGBW LED Bulb device handler
/**
* Copyright 2015 SmartThings
*
* Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except
* in compliance with the License. You may obtain a copy of the License at:
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software distributed under the License is distributed
* on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License
@mckeed
mckeed / rgbw-light.groovy
Created July 17, 2015 04:09
Z-Wave RGBW Light device handler
/**
* Copyright 2015 SmartThings
*
* Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except
* in compliance with the License. You may obtain a copy of the License at:
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software distributed under the License is distributed
* on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License