Skip to content

Instantly share code, notes, and snippets.

Avatar

David Sword davidsword

View GitHub Profile
@davidsword
davidsword / convert-alfred-snippets-to-espanso.php
Last active Mar 12, 2021
Convert Alfred Snippets to Espanso matches
View convert-alfred-snippets-to-espanso.php
<?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 Jan 31, 2021
rpi-oled-sys+pihole-stats.py
View 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 Aug 19, 2020
ESP8266 NodeMCU RGB LED Busy Server
View ESP8266 NodeMCU RGB LED Busy Server.ino
/* 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 Jun 25, 2020
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.
View oled-count-game.py
# 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 Jul 10, 2020
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.
View rgb-led-status.py
# 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 Jun 2, 2020
Github GraphQL API - Trace a commit back to a PR and get the username of who approved it
View get-assoc-pr.sh
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\\\") { \
@davidsword
davidsword / ssbl-README.md
Last active Dec 30, 2020
My personal list of statuses for Slack that I use in a custom Alfred Workflow to change my Slack presense and status as well as send a ping to HomeAssistant to change a physical busy light RGB LED for my office so my family knows my current state/focus.
View ssbl-README.md
State Slack Status Emoji Slack Presense Busy Light
Active 🟢 🟢
In a Meeting red-dot 🟢 🔴
On Call red-dot 🟢 🔴
Red 🟢 🔴
Busy red-dot ⚪️ 🔴
BRB yellow-dot ⚪️ 🟡
Lunch yellow-dot ⚪️ 🟡
Family yellow-dot ⚪️ 🟡
View unicorn-phat.html
<style type="text/css">
:root {
--padding: 2px;
--size: 5px;
--total: 7px;
}
body {
background: black;
padding:2px;
margin:0;
@davidsword
davidsword / x_cache_seg.php
Created Nov 25, 2019
Example of Cache Varients on VIP Go
View x_cache_seg.php
<?php
/**
* Example of Cache Varients on VIP Go
*
* @see https://github.com/Automattic/vip-go-mu-plugins/blob/master/cache/examples/segmentation-maintenance-mode-bypass/vip-config.php
*/
function x_cache_seg() {
// Set the response header to let CDN know of possible varient.
header( 'Vary: X-VIP-Go-Segmentation' );
@davidsword
davidsword / darkmode-toggle.html
Created Oct 16, 2019
Toggle Darkmode w/ a body class
View darkmode-toggle.html
<a href='#' data-darkmode-btn>Toggle Darkmode</a>
<script type="text/javascript">
/* eslint-disable */
var darkModeBtn = document.querySelector('a[data-darkmode-btn]');
var bodyEle = document.querySelector('body');
if (localStorage.getItem('darkmode') === 'yes') {
bodyEle.classList.add("darkmode");
}
function darkmodetoggle(e) {