Skip to content

Instantly share code, notes, and snippets.

@jared-hughes
jared-hughes / switch-lengths.py
Last active April 27, 2024 12:44
Print out the lengths of switch statements in code
#!/usr/bin/env python3
import sys, re
# Assume space after 'switch' or 'match'
startre = re.compile(r"(\s*)(switch|match) ")
def switch_lengths(filename):
@jared-hughes
jared-hughes / submit-tex.sh
Created August 30, 2023 09:13
Golf a TeX solution with tex-autogolfer (https://github.com/jared-hughes/tex-autogolfer), then submit to code.golf with golfc (https://github.com/jared-hughes/golfc). Requires those two dependencies, and a specific directory structure.
#!/bin/bash
set -euo pipefail
if [[ $# -lt 1 ]]; then
echo "Usage: submit-tex.sh [hole] [options]"
echo "Example: ./submit-tex.sh ./src/fizz-buzz.tex"
echo "Requires directory setup where all .tex files are in ./src."
exit 1
fi
@jared-hughes
jared-hughes / search_windows.py
Created April 23, 2023 08:04
search_windows. Bind to Super+X. Old code
#!/usr/bin/env python3
import sys, tty, termios
import subprocess
from fuzzywuzzy import fuzz
import re
import curses
from curses import wrapper
def getch():
fd = sys.stdin.fileno()
@jared-hughes
jared-hughes / discord-dracula-code-blocks.theme.css
Last active January 20, 2023 22:22
Dracula theme for Discord code blocks
:root {
/* Dracula Base Colors */
--dracula-background: #282a36 !important;
--dracula-current-line: #44475a !important;
--dracula-selection: #44475a !important;
--dracula-foreground: #f8f8f2 !important;
--dracula-comment: #6272a4 !important;
--dracula-cyan: #8be9fd !important;
--dracula-green: #50fa7b !important;
--dracula-orange: #ffb86c !important;
// ==UserScript==
// @name Expose topLevelComponents
// @namespace http://tampermonkey.net/
// @version 0.1
// @description Expose Desmos's topLevelComponents as window._topLevelComponents. The global window._topLevelComponents is available after Desmos loads. Make sure to run at document-start.
// @author fireflame241
// @match https://www.desmos.com/calculator
// @icon https://www.google.com/s2/favicons?sz=64&domain=desmos.com
// @grant none
// ==/UserScript==
@jared-hughes
jared-hughes / lolps1.bash
Last active June 1, 2022 11:42 — forked from duckythescientist/lololps1.bash
Rainbow colored bash prompt PS1 string
lolps1() {
PREV_EXIT_CODE=$?
# PS1 rainbow modified from https://gist.github.com/duckythescientist/8338f028e018fd3fecae58e4f1c45def
# Replace $HOME with ~
mypwd=${PWD/#$HOME/"~"}
# Make a persistent, incrementing seed to make a smooth rainbow effect from line to line
if [ -z ${LOLCAT_SEED+x} ]; then LOLCAT_SEED=1; else let "LOLCAT_SEED += 1"; fi
PS1=$(echo " $mypwd" | lolcat --force --freq 0.3 --seed $LOLCAT_SEED 2>/dev/null)
# Strip the "reset colors to normal" commands
PS1=$(echo "$PS1" | sed $'s/\033\[0m//g')
@jared-hughes
jared-hughes / audio-device-switch.sh
Created April 13, 2022 02:29
Switch audio device
#!/bin/bash
# Switch audio device
# Based on https://askubuntu.com/a/1203350/647230
declare -i next_sink_index=`pacmd list-sinks | sed -n -e 's/[[:space:]][[:space:]]index:[[:space:]]\([[:digit:]]\)/\1/p'`
# Change the default sink
pacmd "set-default-sink ${next_sink_index}"
@jared-hughes
jared-hughes / desmos-dependency-analysis.js
Created January 4, 2022 00:22
Desmos Dependency Analysis
function computeContext() {
// Emulate what happens in the web worker
const Context = require("core/math/context").Context;
const context = new Context();
const changeSet = {
isCompleteState: true,
statements: {},
};
for (let stmt of Calc.controller.getAllItemModels()) {
if (stmt.type !== "expression") continue;
@jared-hughes
jared-hughes / desmos-graph-network.js
Last active January 4, 2022 02:36
Desmos Graph Network. Incomplete
function download(url, filename) {
var a = document.createElement("a");
a.href = url;
a.download = filename;
document.body.appendChild(a);
a.click();
setTimeout(function () {
document.body.removeChild(a);
window.URL.revokeObjectURL(url);
}, 0);
@jared-hughes
jared-hughes / phi_plus_n_graph.py
Created July 10, 2021 10:14
Network graph of n→n+φ(n), investigating different starting values from http://oeis.org/A074693, as suggested by tox#6692
from sympy.ntheory import factorint
from sympy.ntheory.factor_ import totient
import functools
import itertools
import networkx as nx
from collections import deque
# pygraphviz is optional; you can use command-line graphviz instead if you want
import pygraphviz as pgv