Skip to content

Instantly share code, notes, and snippets.

View emanuele6's full-sized avatar
๐Ÿ„

Emanuele Torre emanuele6

๐Ÿ„
  • Provincia di Varese, Italy
  • 07:40 (UTC +02:00)
View GitHub Profile
@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 }
#!/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 / 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]
@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 |
@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 () {
#!/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 / setproctitle.c
Last active November 18, 2023 22:01
bash loadable builtin to set proctitle (ps -ocmd) on linux [VERY HACKY]
#include <errno.h>
#include <string.h>
#include <fcntl.h>
#include <unistd.h>
#include <bash/builtins.h>
#include <bash/shell.h>
#include <bash/builtins/bashgetopt.h>
#include <bash/builtins/common.h>
@emanuele6
emanuele6 / chainif.c
Last active February 16, 2024 00:41
chainif -- maintained version available at https://github.com/emanuele6/emanutils
#include <errno.h>
#include <stdbool.h>
#include <stdio.h>
#include <spawn.h>
#include <sys/wait.h>
#include <unistd.h>
extern char **environ;
@emanuele6
emanuele6 / gmail_html_selectall.js
Created February 16, 2024 18:45
qutebrowser greasemonkey userscript that adds a "Select All" button to the "basic HTML" gmail client <https://mail.google.com/mail/u/0/h/>
// ==UserScript==
// @name select all button on GMail basic HTML client
// @include /^https?://mail\.google\.com/mail/u/0/h/.*/
// ==/UserScript==
const inputs = document.querySelector("form[name='f'] table tr td")
if (inputs) {
const selectall = document.createElement("input");
selectall.type = "checkbox";
selectall.onchange = function(e) {