Skip to content

Instantly share code, notes, and snippets.

View mbarkhau's full-sized avatar
💭

mbarkhau

💭
  • Cyberspace
View GitHub Profile
@mbarkhau
mbarkhau / simple_file_cache.py
Last active September 6, 2020 10:57
simple_file_cache.py
# -*- coding: utf-8 -*-
"""Store simple data between multiple executions of a script.
Python2.6+, no external dependencies.
A simple class to store small amounts data between
multiple executions of a script (for one-off scripts).
Copyright: Manuel Barkhau 2020 Dedicated to the public domain.
CC0: https://creativecommons.org/publicdomain/zero/1.0/
@mbarkhau
mbarkhau / tox_via_conda.sh
Created August 23, 2020 14:07
A script to install conda and various python interpreters to use with tox
#!/bin/bash
set -e;
# change this
PROJECT_NAME=bidict
CONDA_ROOT=$HOME/miniconda3
CONDA_BIN=${CONDA_ROOT}/bin/conda
PLATFORM=$(uname -s)
@mbarkhau
mbarkhau / notes_on_the_flying_train.txt
Last active August 9, 2020 13:38
Notes on the video "The Flying Train, Germany, 1902"
https://www.youtube.com/watch?v=EQs5VxNPhzk
0:22 Arch 34 - Kaiserstrasse, after of station "Bruch" - 51.2342321,7.0766762 - https://youtu.be/DgfRq4kEFro?t=175
The building at the left of Arch 41, before the bend onto Göthestraße is still standing
1:04: Arch 47 - Before the bend, looking up to either "Hammerstein" or the north end of "Schrödersbusch".
I don't recognize the house on the hill anywhere today.
1:17: Arch 96 - After station "Sonneborner Straße" - 51.2385451,7.1009054 - https://youtu.be/DgfRq4kEFro?t=365
To the right, the three buildings on the are still standing.
@mbarkhau
mbarkhau / bitbucket-migrate-repo.sh
Created May 24, 2020 20:57
A helper script to migrate mercurial repositories to gitlab/github
#!/bin/bash
set -e;
REPOUSER=mbarkhau
mkdir -p $HOME/workspace
cd $HOME/workspace
if ! [[ -d fast-export ]]; then
@mbarkhau
mbarkhau / demo.md
Last active January 20, 2020 15:32
Python Exception Reason PSA

I have often read the error message in a stacktrace and then reread it after I realized I was reading the code to produce the error message, rather than the error message itself. Often this will not matter, but if you are using a format string to produce the error message, I recommend putting the string generation on a separate line to the raise of the exception.

Variation 1, we have two lines with the error message/reason string, but only the last line one of them has the expanded format string (it includes 1234567890 which presumably is important).

$ python3 ../exception_format_string.py 1
Traceback (most recent call last):
  File "../exception_format_string_demo.py", line 6, in <module>
    raise Exception(f"My error message with formatting: '{arg}'")
Exception: My error message with formatting: '1234567890'
@mbarkhau
mbarkhau / perflog.py
Created October 31, 2019 16:32
perflog.py
"""Context manager for coarse grained performance measurement.
Usage:
with trace("section title"):
your_code_here()
Output:
ts: 0.104 ┌ section title
ts: 123.410 └ d: 123.000 ms
@mbarkhau
mbarkhau / bin ipy
Last active October 19, 2019 14:17
ipy with default imports
/home/mbarkhau/miniconda3/envs/py37/bin/ipython -i -c "import io; import os; import re; import sys; import enum; import json; import math; import time; import random; import decimal; import fractions; import collections; import typing as typ; import pathlib as pl; import datetime as dt; import operator as op; import functools as ft; import itertools as it; import subprocess as sp; from math import *; from statistics import *; import numpy as np; import pandas as pd;"
@mbarkhau
mbarkhau / old_keybase.md
Last active September 12, 2019 12:58
old_keybase.md

Keybase proof

I hereby claim:

  • I am mbarkhau on github.
  • I am mbarkhau (https://keybase.io/mbarkhau) on keybase.
  • I have a public key ASA611NJs8HS_uT4799-rwH5jWqv7UpokdmcJHoivnQ_QQo

To claim this, I am signing this object:

@mbarkhau
mbarkhau / keybase.md
Created September 12, 2019 12:58
keybase.md

Keybase proof

I hereby claim:

  • I am mbarkhau on github.
  • I am mbarkhau (https://keybase.io/mbarkhau) on keybase.
  • I have a public key ASDws--anHB5yrkAliIckzEtrPRKXHcRLFPcfU3-JiiqRwo

To claim this, I am signing this object:

@mbarkhau
mbarkhau / weekly-micro-journal-template.html
Created September 1, 2019 17:57
weekly-micro-journal-template.html
<html>
<head>
<style>
body {
font-family: Bitter;
font-size: 10pt;
}
body, html {
margin: 0;