Skip to content

Instantly share code, notes, and snippets.


David Sword davidsword

View GitHub Profile
davidsword /
Last active Aug 10, 2020
My personal list of statuses for Slack that I use (1) in an Alfred Workflow to change state, and (2) for a Busy Light that polls Slack status and reflects accordindly. This is the canonical source for these statuses, both tools pull the json file from this repo directly.
State Slack Status Emoji Slack Presense Busy Light Notes
Active 🟢 🟢
BRB yellow-dot ⚪️ 🟡 variant states: "Lunch" and "Family"
In a Meeting spiral_calendar_pad 🟢 🔴 Set by Google Calendar Slack App
Busy red-dot ⚪️ 🔴
AFK afk ⚪️ ⚪️
Offline ⚪️ ⚪️
davidsword / ESP8266 ESP 12E RGB LED Busy Server.ino
Last active Aug 9, 2020
ESP8266 ESP 12E RGB LED Busy Server
View ESP8266 ESP 12E RGB LED Busy Server.ino
/* ESP8266 ESP 12E 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 /
Last active Jul 10, 2020 - Raspberry Pi control a common anode or common cathode RGB LED. e sure to know the difference of your RGB LED. Usage: `python3 <avaliable|busy|offline>` to set as green, red, or off respectively.
import sys
import RPi.GPIO as GPIO
# Note this is BOARD numbering.
redPin = 3
davidsword /
Last active Jun 25, 2020 Raspberry Pi - Learn to count to 5 game. Pressing button, count up to number on OLED screen, then celebrate once reached.
import time
import busio
import adafruit_ssd1306
import RPi.GPIO as GPIO
from board import SCL, SDA
from PIL import Image, ImageDraw, ImageFont
# settings
View basic_curl_and_cache_of_json.php
// settings
$url = ""; // json source
$cache = __DIR__."/json.cache"; // make this file in same dir
$force_refresh = false; // dev
$refresh = 60*60; // once an hour
// cache json results so to not over-query (api restrictions)
if ($force_refresh || ((time() - filectime($cache)) > ($refresh) || 0 == filesize($cache))) {
davidsword /
Last active Jun 2, 2020
Github GraphQL API - Trace a commit back to a PR and get the username of who approved it
# 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\\\") { \
View unicorn-phat.html
<style type="text/css">
:root {
--padding: 2px;
--size: 5px;
--total: 7px;
body {
background: black;
davidsword / x_cache_seg.php
Created Nov 25, 2019
Example of Cache Varients on VIP Go
View x_cache_seg.php
* Example of Cache Varients on VIP Go
* @see
function x_cache_seg() {
// Set the response header to let CDN know of possible varient.
header( 'Vary: X-VIP-Go-Segmentation' );
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') {
function darkmodetoggle(e) {
davidsword / wpcli-media-count.php
Last active Oct 2, 2019
WordPress WPCLI - Count Media Library by Types
View wpcli-media-count.php
* Implements `media-count` command.
class WPCLI_Media_Library_Count {
* Get total count of all media and break down counts for each media type.
You can’t perform that action at this time.