Skip to content

Instantly share code, notes, and snippets.

#!/usr/bin/awk -f
BEGIN {
# first the system ones:
print "System colors:"
for (color = 0; color < 8; color++) {
printf "\x1b[48;5;" color "m "
}
print "\x1b[0m"
for (color = 8; color < 16; color++) {
printf "\x1b[48;5;" color "m "
@Perlence
Perlence / decisions.py
Created May 1, 2018 19:08
Decision table generator
import csv
import itertools
import sys
def main():
reader = csv.reader(sys.stdin, delimiter='\t')
conditions = {} # ordered dict is assumed
for line in reader:
if not line:
@Perlence
Perlence / clearSearchBar.uc.js
Created November 27, 2017 12:10
Clear search bar on submit
(function () {
function initSearchTextRemover () {
let searchbar = window.document.getElementById('searchbar');
if (!searchbar) return;
patchSearchbar(searchbar);
}
function patchSearchbar (searchbar) {
if (searchbar.__patched__) return;
let origDoSearch = searchbar.doSearch;
$ python -V
Python 3.7.0a2
$ env PYTHONDONTWRITEBYTECODE=1 python -c 'import sys; print(sys.dont_write_bytecode)'
False
@Perlence
Perlence / youtube-theater-720.css
Last active October 11, 2017 08:54
Limit YouTube video height in theater mode to 720p
@namespace url(http://www.w3.org/1999/xhtml);
@-moz-document domain("youtube.com") {
ytd-watch[theater] :not(.ytp-fullscreen)>.html5-video-container>.html5-main-video {
max-height: 720px;
}
ytd-watch[theater] #player.ytd-watch {
max-height: 720px;
}
@Perlence
Perlence / thread-pool.rkt
Last active September 21, 2021 22:41
Straight-forward thread pool implementation in Racket
#lang racket/base
(require racket/match
racket/async-channel
net/http-client)
(define urls '(["icanhazip.com" "/"]
["icanhazepoch.com" "/"]
["example.com" "/"]))
@Perlence
Perlence / midi_to_key.py
Last active March 17, 2019 13:31
FreePIE: Map MIDI notes to keyboard presses
NOTE_TO_KEY = {
36: Key.Q,
38: Key.W,
40: Key.E,
41: Key.R,
}
def update(midi):
data = midi.data
@Perlence
Perlence / logmemavgload.fish
Last active October 27, 2016 12:09
Log memory usage and average load each 5 seconds
free -s 5 | stdbuf -o0 awk '/^Mem/ {mem = $3}; /buffers\/cache/ {buffers = $3}; /^Swap/ {swap = $3; print mem ";" buffers ";" swap}' > free.log &
fish -c 'while true; cat /proc/loadavg; sleep 5s; end' | stdbuf -o0 awk '{print $1}' > loadavg.log &
program
kill %1 %2
@Perlence
Perlence / st.js
Last active August 21, 2016 21:35
WScript wrapper around st
/* global WScript */
// Convert WScript.Arguments to Array
var wargs = WScript.Arguments;
var args = [];
var isPathRe = /^[A-Za-z]:\\.*/;
var driveRe = /^([A-Za-z]):/;
for (var i = 0; i < wargs.length; i++) {
var warg = wargs(i);
// Convert Windows path to POSIX path
@Perlence
Perlence / uslt.py
Last active June 17, 2016 21:26
Set USLT tag from stdin
import argparse
import sys
from mutagen.id3 import USLT
from mutagen.mp3 import MP3
def main():
parser = argparse.ArgumentParser()
parser.add_argument('MP3FILE')