Skip to content

Instantly share code, notes, and snippets.

View lapo-luchini's full-sized avatar

Lapo Luchini lapo-luchini

View GitHub Profile
@lapo-luchini
lapo-luchini / svn-grep
Created January 28, 2014 11:34
A script to grep the whole SVN history of a file.
#!/bin/sh
FILE="$1"
shift
PARAM="$@"
svn log -q "$FILE" | egrep '^r[0-9]+' | while read REV ALL; do
OUT=`svn cat -r $REV "$FILE" | egrep -n "$PARAM"`
if [ $? -eq 0 ]; then
echo "====> $REV $ALL"
echo "$OUT"
fi
@lapo-luchini
lapo-luchini / change-favicon-from-CSS.js
Last active May 4, 2021 03:07 — forked from mathiasbynens/change-favicon.js
Dynamically change favicon from CSS. (does not work on Internet Explorer and Safari)
/*! dynamically change favicon from CSS (does not work on Internet Explorer and Safari)
*
* use with:
* <link id='linkCSS' href='my.css' type='text/css' rel='stylesheet' />
* <link id='favicon' rel="shortcut icon" href="../images/favicon.png" type="image/png" />
*
* my.css can contain:
* #favicon { background-image: url(any valid URL); }
*/
@lapo-luchini
lapo-luchini / hexparse.js
Last active December 4, 2019 16:55
Decode output from a variety of hex dumps, such as BSD hexdump and Java javax.net.debug=all.
#! /usr/bin/env node
// decode output from a variety of hex dumps, such as
// - BSD hexdump / hd
// 00000000 50 4f 53 54 50 4f 53 54 50 4f 53 54 50 4f 53 54 |POSTPOSTPOSTPOST|
// - od -t x1
// 0000000 50 4f 53 54 50 4f 53 54 50 4f 53 54 50 4f 53 54
// - Java javax.net.debug=all
// 0000: 50 4F 53 54 50 4F 53 54 50 4F 53 54 50 4F 53 54 POSTPOSTPOSTPOST

Keybase proof

I hereby claim:

  • I am lapo-luchini on github.
  • I am lapo (https://keybase.io/lapo) on keybase.
  • I have a public key whose fingerprint is 1651 5D1E D58A BCB0 36C3 1F59 83B0 B8C6 CBDA 71F0

To claim this, I am signing this object:

@lapo-luchini
lapo-luchini / extractDump.awk
Created February 16, 2017 08:28
awk script to extract Java dumps from a log file (`killall -3 jsvc`)
BEGIN { dump = 0; }
/^Full thread dump/ { dump = "dump " prev ".txt"; }
dump != 0 { print $0 > dump; }
/^ PSPermGen/ { getline; print $0 > dump; dump = 0; }
{ prev = $0; }
@lapo-luchini
lapo-luchini / certage.js
Created March 29, 2017 14:54
node script to check expiration date of a list of https domains
#!/usr/bin/env node
//jshint node: true, esversion: 6, strict: global, indent: 4, immed: true, undef: true, sub: true, newcap: false
'use strict';
const fs = require('fs'),
readline = require('readline'),
https = require('https'),
now = Date.now(),
c = {
reset: '\x1b[0m',
#!/bin/sh
# first you need to set the Hyper-V virtual switch named "WSL" to "external network" (bridge mode)
cat <<EOF > /etc/resolv.conf
nameserver 192.168.1.1
nameserver 8.8.8.8
nameserver 2001:4860:4860::8888
EOF
ip addr add 192.168.1.8/24 dev eth0
route add default gw 192.168.1.1
route del default gw 172.23.160.1
@lapo-luchini
lapo-luchini / smartmon_exporter.sh
Last active February 19, 2021 16:13 — forked from hadret/smartmon.sh
smartmon.sh script adapted for FreeBSD
#!/bin/sh
# Script informed by the collectd monitoring script for smartmontools (using smartctl)
# by Samuel B. <samuel_._behan_(at)_dob_._sk> (c) 2012
# source at: http://devel.dob.sk/collectd-scripts/
# TODO: This probably needs to be a little more complex. The raw numbers can have more
# data in them than you'd think.
# http://arstechnica.com/civis/viewtopic.php?p=22062211
# can be add to /etc/crontab like this, and node_exporter will see it automatically:
@lapo-luchini
lapo-luchini / number100.js
Last active October 5, 2021 22:53
Generates flashcards to study multiplications and division of numbers up to 100. Can be imported into Anki via the File→Import option, use "Basic" type cards.
// generates flashcards to study multiplications and division of numbers up to 100
// can be imported into Anki via the File→Import option, use "Basic" type cards
let x = {};
for (let a = 2; a <= 100; ++a)
x[a] = [];
for (let a = 2; a < 100; ++a)
for (let b = a; b < 100; ++b) {
let m = a * b;
if (m > 100)
continue;
@lapo-luchini
lapo-luchini / zrepl_cert_gen.sh
Created October 5, 2021 23:37
A script to create a local CA for you zrepl installation. Uses elliptic curves and SANs to be compatible with latest go.
#!/bin/sh
if [ $# -ne 1 ]; then
echo "Usage: $0 FQDN"
exit 1
fi
cd `dirname "$0"`
if [ ! -f ca.crt ]; then
openssl ecparam -genkey -name prime256v1 -out ca.key
openssl req -x509 -new -SHA256 -nodes -days 3652 -subj "/CN=Root CA/OU=zrepl/O=YourName/C=IT" -key ca.key -out ca.crt
fi