Skip to content

Instantly share code, notes, and snippets.

View leshniak's full-sized avatar

Maciej Leśniewski leshniak

View GitHub Profile
@leshniak
leshniak / odns
Last active September 6, 2022 00:06
A simple script that overrides /etc/resolv.conf to custom one on per-app basis (Linux only)
#!/bin/sh
set -e
trap clean TERM INT EXIT
tmp_resolv_conf=""
clean() {
rm -f -- "$tmp_resolv_conf"
}
@leshniak
leshniak / adjust-srt.awk
Created February 4, 2022 23:07
Adjusts SRT subtitles by a factor or moves them by a shift in milliseconds
#!/usr/bin/env -S awk -f
## Adjusts SRT subtitles by a factor or moves them by a shift in milliseconds
##
## Usage:
## ./adjust-srt.awk [-v SCALE=<factor>] [-v SHIFT=<ms>] subtitles.srt > new-subtitles.srt
##
## Useful scales: 25/23.97=1.04297, 23.97/25=0.9588, 25/29.97=0.834168, 29.97/25=1.1988
function convert(timestamp, hh, mm, ss, sss, adjusted){
@leshniak
leshniak / guide.md
Last active August 5, 2020 13:23
Building Raspberry Pi kernel

Making a custom ARM64 kernel for Raspberry Pi

install dependencies

sudo apt install build-essential libgmp-dev libmpfr-dev libmpc-dev libisl-dev libncurses5-dev bc git-core bison flex

build cross-binutils

https://ftp.gnu.org/gnu/binutils/

@leshniak
leshniak / fish_greeting.fish
Created February 4, 2020 21:26
Fish greeting for printing MOTD on byobu init
function fish_greeting
set -l motd "/run/motd.dynamic"
status --is-login
if test $status -ne 0;
and test -n $BYOBU_TTY;
and test $TMUX_PANE = '%1';
and test -f $motd
cat $motd
end
@leshniak
leshniak / 20-rpi
Last active February 5, 2022 22:59
Raspberry Pi MOTD, with TBW for Samsung SSDs (requires smartmontools) and WAN IP from DNS query (requires dig tool)
#!/bin/bash
UP_SECONDS=`/usr/bin/cut -d. -f1 /proc/uptime`
SECS=$(($UP_SECONDS % 60))
MINS=$(($UP_SECONDS / 60 % 60))
HOURS=$(($UP_SECONDS / 3600 % 24))
DAYS=$(($UP_SECONDS / 86400))
UPTIME=`printf "%d days, %02dh %02dm %02ds " "$DAYS" "$HOURS" "$MINS" "$SECS"`
PROCESSES=`ps ax | wc -l | tr -d " "`
@leshniak
leshniak / proxy.js
Created July 6, 2018 07:17
Simple HTTP(S) node proxy
const httpProxy = require('http-proxy');
const http = require('http');
const net = require('net');
const hostRegExp = /^(?<host>[^:]+)(:(?<port>[0-9]+))?$/;
const proxy = httpProxy.createProxyServer({});
const server = http.createServer(function (req, res) {
const { protocol, host } = new URL(req.url);
const target = `${protocol}//${host}`;
@leshniak
leshniak / http-monitor.sh
Created August 17, 2016 15:25
simple http-monitor
#!/usr/local/bin/bash
# -- init
timestamp=false
bell=false
kill=false
delay="1s"
cleanup ()