Skip to content

Instantly share code, notes, and snippets.

set -eu
declare -i STATE_OK=0
declare -i STATE_WARNING=1
declare -i STATE_CRITICAL=2
declare -i STATE_UNKNOWN=3
jplitza /
Created Aug 29, 2018
Flash a router running OpenWrt via SSH
set -eu
if [ "$#" != 2 ]; then
echo "Usage: $(basename "$0") <iface> <file>"
exit 1
# read once and ignore result, as it is bogus at first
cat /sys/bus/w1/devices/*/w1_slave > /dev/null
while sleep "$INTERVAL"; do
for DEV in /sys/bus/w1/devices/*/w1_slave; do
View zbell.zsh
#!/usr/bin/env zsh
# This script prints a bell character when a command finishes
# if it has been running for longer than $zbell_duration seconds.
# If there are programs that you know run long that you don't
# want to bell after, then add them to $zbell_ignore.
# This script uses only zsh builtins so its fast, there's no needless
# forking, and its only dependency is zsh and its standard modules
jplitza / global_toc.rb
Created Feb 11, 2016
Gollum better Global ToC
View global_toc.rb
module Gollum
class Macro
class GlobalTOC < Gollum::Macro
def render(title = "Global Table of Contents")
pages = @wiki.pages.sort do |a,b|
if a.path.include?('/') and b.path.include?('/') then
a.path <=> b.path
elsif a.path.include?('/') then
elsif b.path.include?('/') then
unshare -unpirf --mount-proc sh -c '
hostname sandbox
TMPNAME=$(mktemp -d)
# replace /dev by minimal dummy version
mount -t tmpfs -o nosuid,mode=755 none $TMPNAME
View timeout_popen.lua
local function timeout_popen(timeout, ...)
local outerpiper, outerpipew = nixio.pipe()
if nixio.fork() == 0 then
local innerpiper, innerpipew = nixio.pipe()
local pid = nixio.fork()
if pid == 0 then
nixio.dup(innerpipew, nixio.stdout)
View gist:206cccc1e547615a2331
function update_latency(int link_latency) {
bgp_community.add((64511, link_latency));
if (64511, 9) ~ bgp_community then bgp_community.delete([(64511, 1..8)]);
else if (64511, 8) ~ bgp_community then bgp_community.delete([(64511, 1..7)]);
else if (64511, 7) ~ bgp_community then bgp_community.delete([(64511, 1..6)]);
else if (64511, 6) ~ bgp_community then bgp_community.delete([(64511, 1..5)]);
else if (64511, 5) ~ bgp_community then bgp_community.delete([(64511, 1..4)]);
else if (64511, 4) ~ bgp_community then bgp_community.delete([(64511, 1..3)]);
else if (64511, 3) ~ bgp_community then bgp_community.delete([(64511, 1..2)]);
else if (64511, 2) ~ bgp_community then bgp_community.delete([(64511, 1..1)]);
jplitza / webhook.php
Created Jan 7, 2015
A basic PHP webhook handler for Github, just verifying the signature and some variables before calling another command to do the actual work
View webhook.php
// where to log errors and successful requests
define('LOGFILE', '/tmp/github-webhook.log');
// what command to execute upon retrieval of a valid push event
$cmd = ' 2>&1';
// the shared secret, used to sign the POST data (using HMAC with SHA1)
$secret = '00000000000000000000000000000000';
jplitza /
Last active Jun 28, 2018
Do a git diffstat based on words (using git diff --word-diff and wc -w). Might break on merge commits!
# Copyright (c) 2014 Jan-Philipp Litza <>
# Permission is hereby granted, free of charge, to any person obtaining a copy
# of this software and associated documentation files (the "Software"), to deal
# in the Software without restriction, including without limitation the rights
# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
# copies of the Software, and to permit persons to whom the Software is
# furnished to do so, subject to the following conditions: