Skip to content

Instantly share code, notes, and snippets.

@davidsword
davidsword / http-status-codes.json
Created July 7, 2022 23:16
HTTP STATUS CODES IN .JSON parsed from https://github.com/waldemarnt/http-status-codes . forked text a little, I added prepended extras on descriptions of 301+302 for myself.
{
"100" : {
"title": "Continue",
"description": "Client should continue with request."
},
"101" : {
"title": "Switching Protocols",
"description": "Server is switching protocols."
},
"102" : {
<body onload="showOrHideAlert()">
<div id='alert' style="background:yellow">
Alert banner generated by PHP, always in the HTML
<a id='alert_dismiss' onclick="setDismissAlertCookie()">[X]</a>
</div>
<script>
function showOrHideAlert() {
const hidden = document.cookie.split('; ').find(row => row.startsWith('dismissAlert='))?.split('=')[1];
@davidsword
davidsword / dsca-convert-db-to-localhost.sh
Created April 7, 2022 18:59
script to do s+r on mysql dump from davidsword.ca -> local dev env
#!/bin/bash
#$1 is the first parameter being passed when calling the script. The variable filename will be used to refer to this.
FILENAME=$1
DSCA_LOCALHOST_ADDR=""
echo "🏃 doing r+r"
# s+r https to http (until I get a RP setup locally)
@davidsword
davidsword / dollarsign-minimal.zsh-theme
Last active January 3, 2022 23:13
Minimal ZSH theme, for those who copy/pasta their terminal a lot.
# install:
#
# 1. create a file with this gists contents
# $ vi ~/.oh-my-zsh/themes/dollarsign-minimal.zsh-theme
#
# 2. edit ~/.zshrc and set `ZSH_THEME="dollarsign-minimal"`
# $ vi ~/.zshrc
#
# 3. reload zshrc
# $ source ~/.zshrc
@davidsword
davidsword / convert-alfred-snippets-to-espanso.php
Last active November 8, 2022 00:38
Convert Alfred Snippets to Espanso matches
<?php
/**
* Convert Alfred Snippets to Espanso matches
*
* @see https://www.alfredapp.com/help/features/snippets/
* @see https://espanso.org/
*/
define('SNIPPETS_DIR', '/path/to/export/of/Alfred/snippets/');
@davidsword
davidsword / rpi-oled-sys+pihole-stats.py
Last active January 31, 2021 22:16
rpi-oled-sys+pihole-stats.py
# System and PiHole stats for 128x32 OLED screen
#
# Add to: `/etc/rc.local` for boot start.
#
# @author learn.adafruit.com, davidsword
# @link https://gist.github.com/davidsword/0e9556ac19b5ef02d93d73931fec659e
# @version 20210131
import time
import subprocess
@davidsword
davidsword / ESP8266 NodeMCU RGB LED Busy Server.ino
Last active August 19, 2020 14:42
ESP8266 NodeMCU RGB LED Busy Server
/* ESP8266 NodeMCU RGB LED Busy Server
*
* Set an RGB LED to current status via web request
*
* 1. Flash this file to a ESP-12E
* 2. Open Serial to get the IP address of board
* 3. Optionally set a dedicated DHCP reservation at the router level to ensure same IP address is used
* 4. Connect common anode or common cathode RGB LED (see pins below)
* 5. Make `GET` request to `http://<IP>/<status>`
*
@davidsword
davidsword / oled-count-game.py
Last active June 25, 2020 21:19
https://davidsword.ca/learning-to-count-to-5-with-a-raspberry-pi/ Raspberry Pi - Learn to count to 5 game. Pressing button, count up to number on OLED screen, then celebrate once reached.
# https://davidsword.ca/learning-to-count-to-5-with-a-raspberry-pi/
import time
import busio
import adafruit_ssd1306
import RPi.GPIO as GPIO
from board import SCL, SDA
from PIL import Image, ImageDraw, ImageFont
# settings
@davidsword
davidsword / rgb-led-status.py
Last active July 10, 2020 06:55
https://davidsword.ca/a-cheaper-diy-status-light/ - Raspberry Pi control a common anode or common cathode RGB LED. e sure to know the difference of your RGB LED. Usage: `python3 rgb-led-status.py <avaliable|busy|offline>` to set as green, red, or off respectively.
# https://davidsword.ca/a-cheaper-diy-status-light/
import sys
import RPi.GPIO as GPIO
GPIO.setwarnings(False)
# Note this is BOARD numbering.
GPIO.setmode(GPIO.BOARD)
redPin = 3
@davidsword
davidsword / get-assoc-pr.sh
Last active June 2, 2020 22:14
Github GraphQL API - Trace a commit back to a PR and get the username of who approved it
GH_TOKEN=""
GH_REPO=""
GH_OWNER=""
GH_SHA=""
# Get the PULL number that's realted to the commit on this build
PULL=$(curl -H "Authorization: bearer ${GH_TOKEN}" -s -d "{ \
\"query\": \"query { \
repository(owner: \\\"$GH_OWNER\\\", name: \\\"$GH_REPO\\\") { \
commit: object(expression: \\\"$GH_SHA\\\") { \