Skip to content

Instantly share code, notes, and snippets.

@sevenissimo
sevenissimo / jdownloader.service
Last active December 20, 2022 10:57
Systemd unit to run latest JDownloader2 without any script. Also let JD2 auto update.
[Unit]
Description=JDownloader Headless
After=network.target
[Service]
Restart=on-failure
User=jdownloader
Group=jdownloader
LogsDirectory=jdownloader
StateDirectory=jdownloader
@sevenissimo
sevenissimo / read-overload-1.sh
Last active June 26, 2022 13:05
Bash mandatory and typed input by read overload
#!/bin/bash
function read {
declare -n var="${@: -1}"
case "$1" in
-Z) until [[ -n "$var" ]]; do
builtin read "${@:2}";
done ;;
-D) until [[ "$var" =~ ^[0-9]+$ ]]; do
builtin read "${@:2}";
@sevenissimo
sevenissimo / bash-args.sh
Created June 30, 2022 19:17
Positional arguments handling on Bash scripts
#!/usr/bin/env bash
__iterate_on_args() {
for a; do echo "arg: $a"; done
}
__iterate_on_glob() {
#shopt -o nullglob
for f in *."${1:-sh}"; do
echo "file: $f"
@sevenissimo
sevenissimo / inotifywait-events.sh
Created June 30, 2022 19:19
Linux Inotify events handling in Bash
#!/bin/bash
#set -x
dir="$(mktemp -d)"
mkfifo "${fifo:=$dir/FIFO}"
inotifywait -m -e create $dir 1>$fifo 2>/dev/null & jobs %%
for i in {1..10}; do
( sleep 2; touch "$dir/$i" ) &
#!/bin/bash
#set -x
function job {
: ${RANDOM:0:2}
sleep $_ && echo "Job $1 done in $_ sec"
}
for n in {1..12}; do
if [[ ${jobs:=0} -ge 3 ]]; then
#!/usr/bin/env bash
#set +x
# Create an array named as param ($1) or 'FOO'
# and fill it with random numbers without naming it
rand() {
declare -n ref="${1:-FOO}"
for i in {1..10}; do
ref[$i]=$RANDOM
done
@sevenissimo
sevenissimo / openmiio_agent.lua
Created March 3, 2024 09:54
Disable buzzer when switch alarm type (issue #1279)
function miio_request(from, method, req)
-- Disable buzzer when switch alarm type (issue #1279)
if from == 32 and method == "local.status" and req:find("alarm_long_one") then
return nil
end
end
@sevenissimo
sevenissimo / mktempfifo.sh
Created June 6, 2024 15:39
Setup temporary FIFO, ensure cleanup
# Setup FIFO
mkfifo ${f:=$(mktemp -u)}
trap "rm -f $f" EXIT
exec {fd}<>$f # Needed to enable FIFO
@sevenissimo
sevenissimo / IPv6Tunnel.ps1
Created July 1, 2024 08:00
A PowerShell script to activate (and update) a 6-in-4 tunnel in Windows 10/11 using Hurricane Electric IPv6 Tunnel Broker
$TunnelName = "IPv6Tunnel"
$TunnelID = "123456"
$ServerIPv6Address = "2001:a:b:c::1"
$ServerIPv4Address = "200.1.2.3"
# When behind a firewall appliance that passes protocol 41,
# use the IPv4 address you get from your appliance's DHCP service
# instead of the IPv4 endpoint you provided to Tunnelbroker
@sevenissimo
sevenissimo / smb.conf
Created July 7, 2024 03:48
Default smb.conf from Git 2024-07-07
# This is the main Samba configuration file. You should read the
# smb.conf(5) manual page in order to understand the options listed
# here. Samba has a huge number of configurable options (perhaps too
# many!) most of which are not shown in this example
#
# For a step to step guide on installing, configuring and using samba,
# read the Samba-HOWTO-Collection. This may be obtained from:
# http://www.samba.org/samba/docs/Samba-HOWTO-Collection.pdf
#
# Many working examples of smb.conf files can be found in the