Skip to content

Instantly share code, notes, and snippets.

Avatar

Maciej Leśniewski leshniak

View GitHub Profile
@leshniak
leshniak / odns
Last active Sep 6, 2022
A simple script that overrides /etc/resolv.conf to custom one on per-app basis (Linux only)
View odns
#!/bin/sh
set -e
trap clean TERM INT EXIT
tmp_resolv_conf=""
clean() {
rm -f -- "$tmp_resolv_conf"
}
@leshniak
leshniak / adjust-srt.awk
Created Feb 4, 2022
Adjusts SRT subtitles by a factor or moves them by a shift in milliseconds
View adjust-srt.awk
#!/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 Aug 5, 2020
Building Raspberry Pi kernel
View guide.md

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 Feb 4, 2020
Fish greeting for printing MOTD on byobu init
View fish_greeting.fish
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 Feb 5, 2022
Raspberry Pi MOTD, with TBW for Samsung SSDs (requires smartmontools) and WAN IP from DNS query (requires dig tool)
View 20-rpi
#!/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 Jul 6, 2018
Simple HTTP(S) node proxy
View proxy.js
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 Aug 17, 2016
simple http-monitor
View http-monitor.sh
#!/usr/local/bin/bash
# -- init
timestamp=false
bell=false
kill=false
delay="1s"
cleanup ()