Skip to content

Instantly share code, notes, and snippets.

@chadbaldwin
chadbaldwin / auto entities card + restriction card + template card.md
Last active September 1, 2023 00:54
auto entities card + restriction card + template card

.

@chadbaldwin
chadbaldwin / alert - garage door open - no motion.yaml
Last active September 1, 2023 00:54
Home Assistant - Create an Alert that announces on Google Home when the garage door has been left open and there has beeen no motion for at least 5 minutes
tts:
- platform: google_translate
template:
- binary_sensor:
- name: garage_open_no_motion
state: >
{{
(is_state('binary_sensor.contact_7_contact', 'on'))
and
@chadbaldwin
chadbaldwin / Garage Left Open - Loop.yaml
Last active October 11, 2022 07:19
Home Assistant automation to send a notification every X minutes the garage door was left open without motion
alias: Garage Door Open Notification
description: Send out repeating notifications or announcements that the garage door is left open
mode: restart
trigger:
- platform: state
entity_id:
- group.garage_motion
- binary_sensor.contact_7_contact
condition:
- condition: state
@chadbaldwin
chadbaldwin / zz Filename Start with Space - added via git
Last active September 1, 2023 00:55
Testing how gist sorts files and readme's
​If you try to add a space to the name in GitHub, it gets trimmed.
If you try to add a space to the name in Windows, it gets trimmed.
The best option seems to be to add the file via command line with the space in the name, then commit and push.
@chadbaldwin
chadbaldwin / test_ripgrep_glob.ps1
Last active February 26, 2025 16:59
Testing globs in ripgrep
$string = 'Functions'
$result = foreach ($l in '','*','/','*/','**/') {
foreach ($r in '','*','/','/*','/**') {
$glob = "!${l}${string}${r}"
$stat = Measure-Command { $list = rg --files -g "${glob}" }
[pscustomobject]@{
Glob = $glob
Count = $list.Count
ExecTimeMS = $stat.Milliseconds
@chadbaldwin
chadbaldwin / sample_template_sensor.yaml
Created April 28, 2022 20:13
HomeAssistant Round template sensor example
# configuration.yaml
template:
- sensor:
- name: new_entity_id
device_class: power
unit_of_measurement: W # watts
state: "{{ states('sensor.target_entity_id') | default(0, true) | round(2, default=0) }}"
# customize.yaml
sensor.new_entity_id:
@chadbaldwin
chadbaldwin / gauge.svg
Last active September 1, 2023 00:56
Simple gauge that can be generated and updated
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
@chadbaldwin
chadbaldwin / number_runs.sql
Last active September 1, 2023 00:57
Find repeating number runs of length N
IF OBJECT_ID('tempdb..#gaps','U') IS NOT NULL DROP TABLE #gaps; --SELECT * FROM #gaps
CREATE TABLE #gaps (
ID int NOT NULL IDENTITY,
Val int NOT NULL,
);
DECLARE @repeat int, @randval int, @sql nvarchar(MAX);
DECLARE @c int = 1000; -- How many islands to create
WHILE (@c > 0)
BEGIN;
------------------------------------------------------------------------------
------------------------------------------------------------------------------
-- DECLARE @VIN VARCHAR(17) = '3FA6PQHR5DR24649O' --VIN with invalid characters test
-- DECLARE @VIN VARCHAR(17) = '3FA6P0HR5DR246490' --VIN with invalid check digit test
DECLARE @VIN VARCHAR(17) = '1FTFX1E58LKF43489'; --Valid VIN test
DECLARE @VINCheck TABLE (Letter CHAR(1) NOT NULL, [Value] TINYINT NOT NULL);
INSERT INTO @VINCheck
VALUES ('A',1),('B',2),('C',3),('D',4),('E',5),('F',6),('G',7),('H',8),
@chadbaldwin
chadbaldwin / auto_equations.tex
Last active September 1, 2023 00:57
Latex code used for generating formulas in Auto Finance Equations blog post
% Standard loan forumula
P=\begin{cases}
\frac{r(PV)}{1-(1+r)^{-n}} &\text{if }r\neq0\\\\
\;\;\;\;\;\frac{PV}{n} &\text{if }r=0
\end{cases}
% Finance Cost - Using Payment and Loan Amount
FC=\frac{P}{PV}
% Finance Cost - Using Rate and Term