Skip to content

Instantly share code, notes, and snippets.

Media Sync

  • Auto Sync
    • When a hard drive is connected (one allowed by usbguard), run an application
    • Using an /etc config file, the UUID maps to what type of content to sync
    • rsync the type of content to the mount point of the hard drive
    • in the background, regularly check the progress of the transfer (du -sbc /dst | tail -1 | cut -f1) / (du -sbc /src | tail -1 | cut -f1) and write the percentage to /tmp/media/mount_point
      • if the size > 100, flip the division
      • if rsync is not running, empty /tmp/media/mount_point
  • if the media is not mounted, remove /tmp/media/mount_point
@s1037989
s1037989 / xprogress.c
Created March 30, 2025 15:59
multiple progress bars for x11
// $ rm -f xprogress.c ; vi xprogress.c ; gcc -o xprogress xprogress.c -lX11
// $ mkdir -p media ; echo 10 > media/media1.txt ; echo 20 > media/media2.txt ; ./xprogress media
#include <X11/Xlib.h>
#include <X11/Xutil.h>
#include <X11/Xatom.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <unistd.h>
# https://arminreiter.com/2022/01/create-your-own-certificate-authority-ca-using-openssl/
# https://blog.xelnor.net/firefox-systemcerts/
CANAME=${1:-MyOrg-RootCA}
# optional, create a directory
mkdir $CANAME
cd $CANAME
# generate aes encrypted private key
openssl genrsa -aes256 -out $CANAME.key 4096
# create certificate, 1826 days = 5 years
package Mojolicious::Command::start;
use Mojo::Base 'Mojolicious::Command', -signatures;
use Mojo::Util qw(extract_usage getopt);
has description => 'Show versions of available modules';
has usage => sub { shift->extract_usage };
has perlbrew_with => sub {
return undef unless $ENV{PERLBREW_ROOT} && $ENV{PERLBREW_HOME} && $ENV{PERLBREW_PERL};
@s1037989
s1037989 / gist:0119f95d593b700bdef8a0e56e6e9e98
Created November 14, 2024 01:00
Flickr API OAuth and Upload
package Mojolicious::Plugin::Flickr;
use Mojo::Base 'Mojolicious::Plugin', -signatures;
use Digest::SHA qw(hmac_sha1);
use Mojo::Collection qw(c);
use Mojo::JSON qw(j);
use Mojo::Parameters;
use Mojo::Util qw(b64_encode hmac_sha1_sum md5_sum url_escape);
has app => undef, weak => 1;
function cd {
local _TMUX_PANE=${TMUX_PANE:-%0}
HISTFILE=$HISTFILE_PREFIX-${_TMUX_PANE:1}
export LC_HISTFILE=$HISTFILE
if [ "$1" == -q ]; then shift; test -d "$1" || return; fi; builtin cd "$@"; echo $(pwd) > ${HISTFILE/bash_histories/pwd};
}
function history-file { echo $HISTFILE; }
function reload {
umask 0022
readonly -p | grep -q TMOUT= || unset TMOUT
@s1037989
s1037989 / README
Last active September 25, 2024 09:50
Process Trust
# This demonstrates the concept for a program to only execute by a trusted caller
# This demonstration uses an extremely simple algorithm, but of course the idea is only to make it more annoyng for someone to spoof the caller
# as the attacker needs to know the algorithm
# And of course caller and callee need to implement the exact same algorithm pair
# Indeed, use RSA to make this idea more cryptographically secure
$ perl a 123 # "a" single argument is a filename
{
"a" => {
"file" => 123, # message dumped to stderr for inspection
---
displayMode: compact
---
gantt
    title Roadmap
    dateFormat YYYY-MM-DD
    axisFormat %b '%y
    tickInterval 3month
    2023 : 2023-11-01, 2023-12-31
@s1037989
s1037989 / gist:73779409c197b704bf4501f65be32ec9
Created January 27, 2024 20:24
POC for storing git log in a db via HTTP
diff --git a/examples/blog/lib/Blog.pm b/examples/blog/lib/Blog.pm
index 57a2291..ebf83cb 100644
--- a/examples/blog/lib/Blog.pm
+++ b/examples/blog/lib/Blog.pm
@@ -30,6 +30,8 @@ sub startup {
$r->get('/posts/:id/edit')->to('posts#edit')->name('edit_post');
$r->put('/posts/:id')->to('posts#update')->name('update_post');
$r->delete('/posts/:id')->to('posts#remove')->name('remove_post');
+
+ $r->post('/log')->to('posts#log')->name('log_post');
@s1037989
s1037989 / Makefile
Last active March 25, 2025 17:59
minimal raw ethernet socket send/recv C program
# requires libssl-dev
all:
gcc -c -o send_recv.o send_recv.c -Wno-psabi
gcc -c -o recv.o recv.c -lcrypto
gcc -o recv send_recv.o recv.o -lm -lcrypto -Wno-psabi
gcc -c -o send.o send.c -Wno-psabi
gcc -o send send_recv.o send.o -lm -lcrypto -Wno-psabi