Skip to content

Instantly share code, notes, and snippets.

View jplitza's full-sized avatar

Jan-Philipp Litza jplitza

View GitHub Profile
#!/bin/sh
CMD="${@:-bash}"
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
local function timeout_popen(timeout, ...)
local outerpiper, outerpipew = nixio.pipe()
if nixio.fork() == 0 then
outerpiper:close()
local innerpiper, innerpipew = nixio.pipe()
local pid = nixio.fork()
if pid == 0 then
outerpipew:close()
innerpiper:close()
nixio.dup(innerpipew, nixio.stdout)
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
jplitza / webhook.php
Created January 7, 2015 14:36
A basic PHP webhook handler for Github, just verifying the signature and some variables before calling another command to do the actual work
<?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 = 'update-jekyll.sh 2>&1';
// the shared secret, used to sign the POST data (using HMAC with SHA1)
$secret = '00000000000000000000000000000000';
@jplitza
jplitza / git-word-stat.sh
Last active June 28, 2018 19:56
Do a git diffstat based on words (using git diff --word-diff and wc -w). Might break on merge commits!
#!/bin/bash
# Copyright (c) 2014 Jan-Philipp Litza <janphilipp@litza.de>
#
# 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:
@jplitza
jplitza / channelsurvey.json
Last active August 29, 2015 14:06
Transform and plot channel survey data. See http://bremen.freifunk.net/blog/2014/09/21/Auswertung-Kanalanalyse.html for explanation
[{"2412": ["6511A5AF+", "9CA6B13E+", "C7A646CE", "238742BA"], "2472": ["1A2B3912-"], "2462": ["80DFA95A", "0543E2A4", "C7A6A76E", "96D72006"], "2437": ["0F6EB6A4", "2506C763", "1D19D85E", "1DD19B4A", "4FB59AB4"], "2452": ["83BF6A82", "24FE03AD-"], "2442": ["2308AD52-"]}, {"2412": ["03557B22", "2308015E+", "2DB38AD9+"], "2472": ["1C284EB1"], "2462": ["8DF730F1-"], "2422": ["317035E5", "C63C55C8"], "2437": ["040E2C9D", "2E9E3916", "1A4F01E2", "BDB99066", "80DF7CD7"], "2457": ["1C2812C7"]}, {"2412": ["23087FE1", "2308E857", "31C4156A+", "31C43F2E", "23085221", "C63C3FB3"], "2422": ["040ED55D", "1D199CD5"], "2447": ["96D7A2DE", "A8E4F368", "C7A6F2A2-"], "2472": ["651172E5", "31C40A3D"], "2462": ["1F33777C", "16E36874", "1C4A0129-", "6D8FCEB6-"], "2437": ["1E58849F", "26F24594+", "7EE53D88", "1E580919", "1CF08464", "040E5692", "264D08B0-", "264D0C81", "265AAFBB", "150C8C77"], "2417": ["96D7A280+", "1A2ACAD0", "C63C266C+"], "2442": ["66B3EE61-"], "2432": ["8DF7790B+", "C63CB6E1"], "2457": ["1401CE1D", "7EE50084-",
\documentclass{scrartcl}
\usepackage{tikz}
\usetikzlibrary{graphdrawing,graphs}
\usegdlibrary{circular}
\begin{document}
\begin{tikzpicture}[simple necklace layout]
\graph { A -> B -> C -> A};
\end{tikzpicture}
\end{document}
@jplitza
jplitza / ffmap-backend.js
Created March 1, 2014 14:42
FFMap backend in NodeJS
#!/usr/bin/env nodejs
var fs = require('fs');
var _ = require('underscore');
var RRD = require('rrd').RRD;
var argv = require('optimist')
.usage('Usage: $0 -b <batvis file> -a <alias file> <destination dir>')
.options('b', {alias: 'batvis', describe: 'File containing output of batadv-vis -f jsondoc', demand: true, string: true})
.options('d', {alias: 'details', describe: 'File containing details sent by the nodes', demand: true, string: true})
.argv;
@jplitza
jplitza / newkey.php
Last active August 29, 2015 13:56
fastd add key script
<?php
require("write_key.inc.php");
?>
<!DOCTYPE html>
<html lang="de">
<head>
<meta charset="utf-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<link href="//netdna.bootstrapcdn.com/bootstrap/3.0.3/css/bootstrap.min.css" rel="stylesheet">
<title>Mesh-VPN-Schlüssel eintragen</title>
@jplitza
jplitza / autobuild.sh
Created February 23, 2014 20:35
gluon autobuild script
#!/bin/sh
set -e
# functions
usage() {
cat <<EOF
Automatically builds gluon images from the latest versions of the repositories.