Skip to content

Instantly share code, notes, and snippets.

View ddrscott's full-sized avatar

Scott Pierce ddrscott

View GitHub Profile
@ddrscott
ddrscott / combinations.sql
Created December 7, 2021 03:06
Simple non-repeating pairs of numbers in all combinations
WITH inputs AS (
SELECT
row_number() over () as idx,
letter
FROM unnest(ARRAY['a', 'b', 'c', 'd']) letters(letter)
)
SELECT
a.letter,
b.letter
FROM inputs a, inputs b
@ddrscott
ddrscott / say_last_child.js
Created June 3, 2021 18:47
Helper to watch for DOM elements getting added and saying the contents.
function sayLastChild(selector) {
// Select the node that will be observed for mutations
const targetNode = document.querySelector(selector);
// Options for the observer (which mutations to observe)
const config = { attributes: true, childList: true, subtree: true };
// Callback function to execute when mutations are observed
const callback = function(mutationsList, observer) {
// Use traditional 'for loops' for IE 11
@ddrscott
ddrscott / data.csv
Last active March 3, 2021 23:25
Use Pandas to spread/flatten dictionary's items into individual columns
id color meta
1 red {"x":123}
2 green {"y":456}
3 blue {"x":789,"y":234}
@ddrscott
ddrscott / Makefile
Last active March 8, 2021 17:49
Convert cbr files to PDF files
src_dir = sources
dist_dir = dist
cbr_files = $(wildcard $(src_dir)/*.cbr)
pdf_files = $(cbr_files:$(src_dir)/%.cbr=$(dist_dir)/%.pdf)
image_dir = .images-$<
all: ${pdf_files} | $(dist_dir)
@echo Done
clean:

Terminal Illness - Lightning Talk

This is a shotgun blast of commands I use from terminal for fun and profit. Some say I'm crazy for living in the "black screen", I like to think of it as a Terminal Illness.

Pipes are the only friends that won't let you down

@ddrscott
ddrscott / remove_ads.js
Last active March 23, 2024 21:10
TamperMonkey - Remove Ads elements after Ajax stuff loads
// ==UserScript==
// @name Remove Ads
// @namespace https://ddrscott.github.io/remove_ads
// @version 0.5
// @description Removes elements that are thought to be ads.
// @author Scott Pierce
// @match https://*/*
// @grant none
// ==/UserScript==
(function() {

Heart of Five (红心五)

Heart of Five is a multiplayer playing card game. A player wins by discarding all their cards first, a player loses by having cards at the end.

Players and Cards

This game is best played with 4 players, but could be played with 2 to N

function simulateKey (keyCode, type, modifiers, elm) {
var evtName = (typeof(type) === "string") ? "key" + type : "keydown";
var modifier = (typeof(modifiers) === "object") ? modifier : {};
var event = document.createEvent("HTMLEvents");
event.initEvent(evtName, true, false);
event.keyCode = keyCode;
for (var i in modifiers) {
event[i] = modifiers[i];
@ddrscott
ddrscott / stdin_tty_demo.py
Last active March 9, 2020 13:59
Example of reading from STDIN and Console TTY at the same time.
#!/usr/bin/env python
import os
import sys
import termios
import tty
import threading
def main():
@ddrscott
ddrscott / setup.sh
Created January 3, 2020 16:28
My zsh + tmux + nvim setup
#!/bin/sh
export LC_ALL=C.UTF-8
export LANG=C.UTF-8
export LANGUAGE=C.UTF-8
# Terminal settings and colors
export TERM=xterm-256color
export BASE16_THEME=ocean