Skip to content

Instantly share code, notes, and snippets.

View emanuele6's full-sized avatar
🐄

Emanuele Torre emanuele6

🐄
  • Provincia di Varese, Italy
  • 13:27 (UTC +01:00)
View GitHub Profile
@emanuele6
emanuele6 / actually_playable_zork
Last active May 13, 2022 02:28
A simple tcl/expect script that gives DELETE key support to jzip (z-machine emulator) so that I can sanely play zork on my laptop. (my laptop's BACKSPACE key does not work)
#!/bin/sh --
# \
exec tclsh -encoding ascii "$0" "$@"
# usage: actually_playable_zork [zork_command] [save_file]
package require Expect
if {$::argc >= 1} {
set zork [lindex $::argv 0]
#!/bin/bash -
get_rect() {
local target
target=$(bspc query -N -n "$1.floating") || return
bspc subscribe node_geometry | while IFS=' ' read -r _ _ _ wid rect; do
if (( wid == target )); then
printf '%s\n' "$rect"
break
fi
@emanuele6
emanuele6 / awk1.awk
Created December 5, 2021 17:27
aoc day 5 2021
function hvcoo(p, f, hv) {
if (hv == "h")
return p SUBSEP f
return f SUBSEP p
}
BEGIN { FS = ",| -> " }
$1 == $3 { hv = "v"; f = $1; a = $2; b = $4 }
$2 == $4 { hv = "h"; f = $2; a = $1; b = $3 }
@emanuele6
emanuele6 / jcsvid
Last active June 20, 2022 18:02
simple script to watch videos from jcs.org with mpv (using bash, curl, xj and jq).
#!/bin/bash --
if [[ $# != 1 ]]; then
printf >&2 'Usage: jcsvid URL\n'
exit 2
fi
eval -- "$(curl -LSgs -- "$1" | xj | jq -r '
first(
.. | .video? | arrays |
#!/bin/sh --
# \
exec jq --unbuffered --stream -rn --args -f "$0" -- "$@"
$ARGS.positional |
if length != 1 then
@json "Invalid arguments: \(.).\n" | halt_error(2)
else . end |
(
.[0] |
@emanuele6
emanuele6 / bashrematch_stack.bash
Created May 31, 2022 00:29
BASH_REMATCH stack: a secret bash feature :O
#!/bin/bash --
# https://lists.gnu.org/archive/html/bug-bash/2022-05/msg00052.html
bashrematch_push () {
local BASH_REMATCH a
for a
do [[ $a =~ .* ]]
done
}
bashrematch_pop () {
@emanuele6
emanuele6 / bspdeskjson2dot
Last active July 20, 2024 22:32
bspwm tree visualiser
#!/bin/sh --
# \
exec jq -Crf "$0" -- "$@"
def children:
objects |
.path as $p |
(.firstChild | objects | .path = $p + "/1"),
(.secondChild | objects | .path = $p + "/2") |
select(has("id"));
@emanuele6
emanuele6 / sharewordle.py
Last active September 27, 2023 22:51
sharewordle
#!/bin/python3 --
import argparse
import datetime
import itertools
import sys
ap = argparse.ArgumentParser()
ap.add_argument("--number", "-N", type=int,
help="The number to use in the header instead of the "
@emanuele6
emanuele6 / linenum.ed
Last active June 7, 2024 09:04
POSIX ed script that adds line numbers in front of the lines of a file.
1s/^/1 /
2,$g/^/-t -\
s/ .*//\
s/^9*$/0&/\
t .\
s/^.*[^9]\(9*\)$/\1 /\
s/9/0/g\
-s/9*$//\
s/8$/9/\
s/7$/8/\