Skip to content

Instantly share code, notes, and snippets.

View StephenWetzel's full-sized avatar

Stephen Wetzel StephenWetzel

View GitHub Profile
#!/bin/bash
set -o pipefail
rid=$(uuidgen)
# Create a check on https://healthchecks.io/ and replace HEALTH-CHECK-KEY below
health_check_url="https://hc-ping.com/HEALTH-CHECK-KEY/server_backup_root_drive"
curl -fsS --retry 5 --retry-all-errors --retry-max-time 60 -o /dev/null $health_check_url/start?rid=$rid
date_string=$(date +"%Y-%m-%dT%H_%M_%S")
echo "$date_string $rid"
@StephenWetzel
StephenWetzel / color_loop.yaml
Created October 18, 2023 21:16
Home Assistant Script: Color Loop
alias: LED Color Loop
variables:
transistion_time: 60
sequence:
- service: light.turn_on
target:
entity_id: light.rec_room_led_strip_2
data:
color_name: violet
brightness_pct: 50
@StephenWetzel
StephenWetzel / turn_up_light.yaml
Created October 18, 2023 21:15
Home Assistant Script: Turn Light Up
alias: Turn Light Up
mode: single
description: >-
A script that turns on lights to a given brightness level only if they are
currently lower than that level (or off).
fields:
light_entity:
description: The entity id of the light you want to turn on
example: light.living_room_lights
brightness_pct:
#!/bin/sh
# unifi-ap6-professional
# u6-lite-us
# Run with:
# ~/bin/check_stock.sh unifi-ap6-professional >> ~/logs/check_stock.log 2>&1
email="example@gmail.com"
url=https://store.ui.com/products/$1
@StephenWetzel
StephenWetzel / bcd_to_decimal_conversion.sql
Created June 10, 2022 06:47
Converting values which were incorrectly treated as binary, instead of BCD
select
(SUBSTRING(binary_num, 1, 4)::bit(4)::int::varchar ||
SUBSTRING(binary_num, 5, 4)::bit(4)::int::varchar ||
SUBSTRING(binary_num, 9, 4)::bit(4)::int::varchar ||
SUBSTRING(binary_num, 13, 4)::bit(4)::int::varchar ||
SUBSTRING(binary_num, 17, 4)::bit(4)::int::varchar)::int * 10 as new_state
, state_id, * from (
select right((state::int / 10)::bit(32)::varchar, 20) as binary_num, *
from states
where entity_id = 'sensor.water_meter'
@StephenWetzel
StephenWetzel / backup_full_pi.sh
Last active December 13, 2021 05:57
Backup Pi to NFS drive
#!/bin/sh
# Add to /etc/fstab:
# 192.168.1.123:/mnt/media /mnt/nfs/server/media nfs defaults,rw,user 0 0
# Cron:
# 03 * * * * /home/pi/bin/backup_full_pi.sh
date
backup_dir="/mnt/nfs/server/media/Backup/Pi/$(hostname)/"
#!/bin/sh
# Configure aws with: aws configure --profile backup
### Config ###
FILENAME="Full_Backup_`date --iso-8601=seconds`.7z"
BACKUP_TO_FILE_PATH="$HOME/Backups/$FILENAME"
BACKUP_ARCHIVE_FILE_PATH="$HOME/Backups/archive/$FILENAME"
BACKUP_FROM_PATH="$HOME/Documents/"
S3_PATH="backups/`date +%Y`/FullLocal/"
#!/bin/sh
# Configure aws with: aws configure --profile backup
### Config ###
FILENAME="Daily_Backup_`date --iso-8601=seconds`.7z"
BACKUP_TO_FILE_PATH="$HOME/Backups/$FILENAME"
BACKUP_ARCHIVE_FILE_PATH="$HOME/Backups/archive/$FILENAME"
BACKUP_FROM_PATH="$HOME/Documents/"
S3_PATH="backups/`date +%Y`/Daily/"
@StephenWetzel
StephenWetzel / stocktwits.formatted.json
Created April 13, 2016 21:04
StockTwits Formatted
{
"id":18584239,
"body":"$RSOL $ASTI Happy New Year, all!",
"created_at":"2014-01-01T00:00:07Z",
"user":{
"id":239266,
"username":"jshank25",
"name":"Jason Shank",
"avatar_url":"http://avatars.stocktwits.com/production/239266/thumb-1371174418.png",
"avatar_url_ssl":"https://s3.amazonaws.com/st-avatars/production/239266/thumb-1371174418.png",
@StephenWetzel
StephenWetzel / stocktwits.unformatted.json
Created April 13, 2016 21:03
StockTwits Unformatted
{"id":18584239,"body":"$RSOL $ASTI Happy New Year, all!","created_at":"2014-01-01T00:00:07Z","user":{"id":239266,"username":"jshank25","name":"Jason Shank","avatar_url":"http://avatars.stocktwits.com/production/239266/thumb-1371174418.png","avatar_url_ssl":"https://s3.amazonaws.com/st-avatars/production/239266/thumb-1371174418.png","official":false,"identity":"User","classification":[],"join_date":"2013-06-12","followers":0,"following":3,"ideas":56,"following_stocks":1,"location":"CA","bio":null,"website_url":null,"trading_strategy":{"assets_frequently_traded":[],"approach":"Fundamental","holding_period":"Long Term Investor","experience":"Novice"}},"source":{"id":1,"title":"StockTwits","url":"http://stocktwits.com"},"symbols":[{"id":952,"symbol":"ASTI","title":"Ascent Solar Technologies, Inc.","exchange":"NASDAQ","sector":"Technology","industry":"Semiconductor - Specialized","trending":false},{"id":3420,"symbol":"RGSE","title":"Real Goods Solar, Inc.","exchange":"NASDAQ","sector":"Industrial Goods","industry"