Skip to content

Instantly share code, notes, and snippets.

@joostrijneveld
joostrijneveld / gpg2qrcodes.sh
Created May 20, 2014 19:43
Producing printable QR codes for persistent storage of GPG private keys
# Heavily depends on:
# libqrencode (fukuchi.org/works/qrencode/)
# paperkey (jabberwocky.com/software/paperkey/)
# zbar (zbar.sourceforge.net)
# Producing the QR codes:
# Split over 4 codes to ensure the data per image is not too large.
gpg --export-secret-key KEYIDGOESHERE | paperkey --output-type raw | base64 > temp
split temp -n 4 IMG
for f in IMG*; do cat $f | qrencode -o $f.png; done
@joostrijneveld
joostrijneveld / combinepdf.sh
Last active March 11, 2021 23:17
Combines PDF files and adds white pages in between to allow double-sided printing without mixing documents. Requires a blank.pdf file.
#! /bin/bash
if [ -z "$1" ]; then
echo "Specify which folder contains the PDFs"
exit 1
fi
OUTFILE=combined_$1.pdf
if command -v convert >/dev/null 2>&1; then
@joostrijneveld
joostrijneveld / autoresponder.py
Created May 9, 2015 20:58
Facebook autoresponder plugin for Poezio
from plugin import BasePlugin
class Plugin(BasePlugin):
def init(self):
self.api.add_event_handler('conversation_msg', self.on_msg)
self.api.add_event_handler('private_msg', self.on_msg)
def on_msg(self, msg, tab):
tab.command_say('[Automatic response] I stopped reading Facebook chat. Do try in some other way!')
@joostrijneveld
joostrijneveld / 3fmnow.py
Last active September 26, 2016 19:10
Scrape whatever was last played on 3FM (in the current hour)
#! /bin/env python
from bs4 import BeautifulSoup
import requests
URL = "http://www.3fm.nl/welkliedjewasdat"
r = requests.get(URL)
r.encoding = 'utf-8'
soup = BeautifulSoup(r.text, 'lxml')
@joostrijneveld
joostrijneveld / keyedit.c.patch
Created June 23, 2016 15:49
Editing GPG's keyedit.c to allow unsigned UIDs
--- a/g10/keyedit.c
+++ b/g10/keyedit.c
@@ -1877,7 +1877,7 @@ static struct
{ "nrsign", cmdNOP, 0,
N_("sign selected user IDs with a non-revocable signature")},
{ "debug", cmdDEBUG, 0, NULL},
- { "adduid", cmdADDUID, KEYEDIT_NOT_SK | KEYEDIT_NEED_SK, N_("add a user ID")},
+ { "adduid", cmdADDUID, KEYEDIT_NOT_SK, N_("add a user ID")},
{ "addphoto", cmdADDPHOTO, KEYEDIT_NOT_SK | KEYEDIT_NEED_SK,
N_("add a photo ID")},
@joostrijneveld
joostrijneveld / tboxes.cpp
Last active December 23, 2015 18:19
Computing the T-boxes that enable fast computation of AES through lookup.
#include <stdint.h>
#include <stdio.h>
using namespace std;
unsigned char s[256] =
{
0x63, 0x7C, 0x77, 0x7B, 0xF2, 0x6B, 0x6F, 0xC5, 0x30, 0x01, 0x67, 0x2B, 0xFE, 0xD7, 0xAB, 0x76,
0xCA, 0x82, 0xC9, 0x7D, 0xFA, 0x59, 0x47, 0xF0, 0xAD, 0xD4, 0xA2, 0xAF, 0x9C, 0xA4, 0x72, 0xC0,
0xB7, 0xFD, 0x93, 0x26, 0x36, 0x3F, 0xF7, 0xCC, 0x34, 0xA5, 0xE5, 0xF1, 0x71, 0xD8, 0x31, 0x15,
@joostrijneveld
joostrijneveld / courses_per_semester.py
Created August 25, 2013 14:18
Downloads the course index of a Radboud prospectus and groups courses per quarter / semester.
#! /usr/bin/env python
import argparse
import urllib2
import re
from bs4 import BeautifulSoup
def setup_args():
parser = argparse.ArgumentParser(description='Downloads the course index of a Radboud prospectus and groups courses per quarter / semester.')
parser.add_argument('courselistURL',
@joostrijneveld
joostrijneveld / split.sh
Last active December 18, 2015 09:16
Splits a set of PDFs into two folders for TAs to check
TAS=( NAME1 NAME2 )
REST=rest
for ta in ${TAS[@]}; do
mkdir -p $ta;
done
mkdir -p $REST
for f in pdfs/*.pdf
do
@joostrijneveld
joostrijneveld / 2015_R1A_B.py
Created April 25, 2015 18:25
The partial solution as listed in the GCJ contest analysis for 2015-R1A-B-small seems to contain an infinite loop
from fractions import gcd
from itertools import count
def naive_get_barber_number(N):
customer = 1;
for T in count(1):
for barber in range(B):
if T % M[barber] == 0:
# at this point N = 0 and customer > 0..
@joostrijneveld
joostrijneveld / scpscreenshots.sh
Created March 3, 2015 10:34
Shell script that watches the desktop for screenshots (OSX default format) and then copies them to a remote using scp, leaving the URL available on the clipboard.
#! /bin/bash
# change the paths on line 9 and 10 to match your specific configuration
/usr/local/bin/fswatch -0 ~/Desktop | while read -d "" event; \
do \
if [[ ${event} == ~/Desktop/Screen* ]] && [[ -e ${event} ]]; then
newname=`cat /dev/urandom | env LC_CTYPE=C tr -dc 'a-zA-Z0-9' | head -c 16`
scp "${event}" example.com:/var/www/files/screenshots/$newname.png > /dev/null
echo -n "http://files.example.com/screenshots/$newname.png" | pbcopy