Skip to content

Instantly share code, notes, and snippets.

#!/usr/bin/env python
import os, re, sys
from os import path
from pathlib import Path
from datetime import datetime, timedelta
from prompt_toolkit import prompt # bundled with iPython
from prompt_toolkit.completion import WordCompleter
svenk / spin-the-bottle.php
Last active Dec 31, 2020
"Spin the bottle" with Zoom using the Zoom Webhook API
View spin-the-bottle.php
<meta charset="utf-8">
<title>Genie in a Bottle</title>
<meta author="SvenK">
<meta date="31.12.2020">
# First of all, this is supposed only to work for a specific
# room. Fix the room id here:
svenk / index.php
Created Feb 10, 2020
Share secrets public over the web
View index.php
// Enforce HTTPS
if($_SERVER["HTTPS"] != "on") { header("Location: https://" . $_SERVER["HTTP_HOST"] . $_SERVER["REQUEST_URI"]); exit(); }
<!doctype html>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width,initial-scale=1">
<body style="padding:5%; font-family: sans-serif">
<h1>Some secret</h1>
svenk /
Created Jan 29, 2020
Scribd JPG scraping
#!/usr/bin/env python3
# Scraping non-downloadable books/documents
# by downloading them as JPG files
# Public Domain.
import requests, json, sys
# Attention, token changes regularly... You should copy all ~10 minutes from Firebug
View syntax highlighting in mathematica notebook print (PDF or so).nb
(* Allow for nicer print output *)
PrintingStyleEnvironment -> "Printout", ShowSyntaxStyles -> True]
svenk / Gendernsternchen und Markdown in Python3
Last active Nov 12, 2019
Gendernsternchen und Markdown
View Gendernsternchen und Markdown in Python3
Das Gendersternchen funktioniert nicht gut zusammen mit Markdown. Folgender
Regexp liefert ein Preprocessing, was es ermöglicht, ohne einen anderen
Markdown-Dialekt zu wählen (Regulärer Ausdruck in Python):
> for x in ["Gender*nnen","foo *bar* baz", "foo *bar*baz", "Und *das* ist wirklich Mensch*nnen *und* toll."]:
> print(re.sub(r"(^|\s)(\w+)\*([^.\s]*\w+)($|\s)", r"\1\2\*\3\4", x))
foo *bar* baz
foo *bar*baz
svenk / vprintf.cpp
Created Jul 3, 2019
Convenient C's printf in C++
View vprintf.cpp
// this is a buffer-overflow-safe version of sprintf
// source:
// if you need something more mature, consider
// the advantage of this snippet is that it can be really easily added to smallish
// codes/libraries. Usage is like C's vprintf et al. but with a C++ std::string as a result.
std::string vformat (const char *fmt, va_list ap) {
// Allocate a buffer on the stack that's big enough for us almost
// all the time. Be prepared to allocate dynamically if it doesn't fit.
size_t size = 1024;
char stackbuf[1024];
svenk /
Last active Feb 27, 2019
Email inboxes (mbox) to CSV
#!/usr/bin/env python3
# A python3 script to read an mbox file (extension to Maildir is trivial thanks to
# mailbox module) and writes out certain headers as CSV file.
# On large mbox files (say 5GB) it is slow because... it's Python.
# The script deals with some cornercases (encoding, newlines, ...) which I found in
# 100K emails. Otherwise, the builtin python mail libraries provide robustness.
# It processes roughly 110K (5GB mbox) mails in 2:35mins on my laptop and produces
# a 19MB CSV file.
svenk /
Created Sep 10, 2018
Python: Display scientific number with 10 power something (suitable for LaTeX) instead of the "e" suffix
import re
sci = lambda d: re.sub(r'e\+?(-?)?0?(\d+)', r" x 10^{\1\2}" ,"%.2e"%d)
### Examples:
In [34]: sci(1)
Out[34]: '1.00 x 10^{0}'
svenk / resolver.c
Created Nov 21, 2017
View resolver.c
* A Firefox Quantum ViewSourceWith replacement for Windows.
* When compiled, this behaves like an editor, i.e. you call
* it with a file as an argument. It tries to extract then
* the real file to open.
* Todo:
* 1) Read editor path from INI file with GetPrivateProfileString
* 2) hide the console when opening the real notepad