Skip to content

Instantly share code, notes, and snippets.

View emanuele6's full-sized avatar
🐄

Emanuele Torre emanuele6

🐄
  • Provincia di Varese, Italy
  • 15:35 (UTC +02:00)
View GitHub Profile
@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) {
@emanuele6
emanuele6 / gron.jq
Last active December 21, 2023 15:24
gron in jq
#!/bin/sh --
# \
exec jq -nsRrf "$0" --args -- "$@"
def path2gronpath:
reduce .[] as $k ("json"; . + ($k |
if type == "number" or . == "" or test("^[0-9]|[^0-9a-zA-Z_]")
then @json "[\(.)]"
else ".\(.)"
end));
@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 / linenum.ed
Last active February 9, 2024 22:52
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/\
@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 / bspdeskjson2dot
Last active August 17, 2023 13:56
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 / 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 / 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 |