Skip to content

Instantly share code, notes, and snippets.

Avatar

Sviatoslav Abakumov Perlence

View GitHub Profile
View termcolors.awk
#!/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
Decision table generator
View decisions.py
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 Nov 27, 2017
Clear search bar on submit
View clearSearchBar.uc.js
(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;
View dont_write_bytecode.txt
$ 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 Oct 11, 2017
Limit YouTube video height in theater mode to 720p
View youtube-theater-720.css
@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 Feb 22, 2019
Straight-forward thread pool implementation in Racket
View thread-pool.rkt
#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 Mar 17, 2019
FreePIE: Map MIDI notes to keyboard presses
View midi_to_key.py
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 Oct 27, 2016
Log memory usage and average load each 5 seconds
View logmemavgload.fish
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 Aug 21, 2016
WScript wrapper around st
View st.js
/* 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 Jun 17, 2016
Set USLT tag from stdin
View uslt.py
import argparse
import sys
from mutagen.id3 import USLT
from mutagen.mp3 import MP3
def main():
parser = argparse.ArgumentParser()
parser.add_argument('MP3FILE')
You can’t perform that action at this time.