Skip to content

Instantly share code, notes, and snippets.

#!/usr/bin/env perl
use Mojolicious::Lite -signatures;
use Mojo::File qw(path);
use Mojo::IOLoop;
use Mojo::JSON qw(false true);
use Mojo::Log;
my $tmp = path('/dev/shm/v')->make_path;
@s1037989
s1037989 / gist:74bc5b0d5bd4e1da409be8850456e1a7
Last active February 18, 2021 02:47
pack non-binary files into a single text file, and unpack them again
txtpack() {
if test -d "$1"/.git; then
cd "$1"
local tmp=$(mktemp -t "$1.$(git rev-parse --short HEAD).XXXX")
cd -
else
local tmp=$(mktemp -t "$1.xxxxxxxxx.XXXX")
fi
for i in $(find "$1" ! -path "*/.git/*" -type f); do
if iconv -f utf-8 -t utf-8 "$i" > /dev/null 2>&1; then
#!/usr/bin/env bash
iwatch() {
local OPTARG OPTIND
while getopts 'qv:V:' o; do
case "$o" in
q) quiet=1;;
v) quiet=1; _REPLY=$OPTARG;;
V) _REPLY=$OPTARG;;
esac
@s1037989
s1037989 / DiePids.pm
Last active January 3, 2021 17:05
Simple TCP Key-Value store in Perl
package DiePids;
use 5.010;
use strict;
use warnings;
use Time::HiRes qw(usleep);
sub new { bless [], shift }
@s1037989
s1037989 / README.md
Last active January 9, 2024 00:37
ip-discover: Setup a device for discovery on a network using socat

ip-discover

Setup a device for discovery on a network using socat

On the device to be discovered:

  • Copy ip-discovery to /usr/bin and run chmod +x /usr/bin/ip-discovery
  • Copy ip-discovery.service to /etc/systemd/system, adjust the code-word, and run sudo systemctl daemon-reload && sudo systemctl start ip-discovery

On the device wanting to discover the device to be discovered:

  • Copy ip-discover to your home folder and run . ~/ip-discover
@s1037989
s1037989 / ff
Last active February 1, 2021 04:05
file filter
#!/usr/bin/env bash
check_perm() {
local path="$1"
local min="$2"
local max="$3"
local owner="$4"
local group="$5"
local stat=( $(stat -L -c "0%#a %U %G" $path 2>/dev/null) )
local fperm=${stat[0]}
sqlite> CREATE TABLE widget1 ( id INTEGER PRIMARY KEY AUTOINCREMENT, t TIMESTAMP DEFAULT (DATETIME('2020-12-04 04:22:00')), width int);
sqlite> CREATE TABLE widget2 ( id INTEGER PRIMARY KEY AUTOINCREMENT, t TIMESTAMP DEFAULT (DATETIME('2020-12-04 04:22:00')), width int);
sqlite> insert into widget1 (width) values (74);
sqlite> insert into widget1 (width) values (1345);
sqlite> insert into widget1 (width) values (445);
sqlite> insert into widget1 (width) values (6);
sqlite> insert into widget2 (width) values (9999);
sqlite> insert into widget2 (width) values (1);
sqlite> insert into widget2 (width) values (12);
sqlite> insert into widget2 (width) values (4563);
#!/usr/bin/env bash
FILE=`which file 2>/dev/null` || exit 1
finish_writing() {
local file=$1; shift
if [ $still_growing_timeout -gt 0 ]; then
printf "waiting for $file to finish\n" >$stderr
wait_file $file
! file "$file" "$mime_type" && return
@s1037989
s1037989 / gist:53ad6513eef6cf8232d734697f8c19d8
Last active November 7, 2020 04:07
Bash manage child processes
#!/usr/bin/env bash
cleanup() {
flock unlock
exit
}
die() {
echo "$*"
exit
set -x
/home/stefan/perl5/perlbrew/perls/perl-5.18.4/bin/perl -MExtUtils::Command -e 'mkpath' -- blib/lib/List
chmod 755 blib/lib/List
touch blib/lib/List/.exists
/home/stefan/perl5/perlbrew/perls/perl-5.18.4/bin/perl -MExtUtils::Command -e 'mkpath' -- blib/arch
chmod 755 blib/arch
touch blib/arch/.exists
/home/stefan/perl5/perlbrew/perls/perl-5.18.4/bin/perl -MExtUtils::Command -e 'mkpath' -- blib/lib/auto/List/Util
chmod 755 blib/lib/auto/List/Util
touch blib/lib/auto/List/Util/.exists