Skip to content

Instantly share code, notes, and snippets.

View mbarkhau's full-sized avatar
💭

mbarkhau

💭
  • Cyberspace
View GitHub Profile
@mbarkhau
mbarkhau / picodash_export_url_download.py
Last active September 7, 2021 17:47 — forked from krisrak/picodash_export_url_download.py
Python script to download urls in a csv file
#!/usr/bin/python
import os
import sys
import csv
import urllib
try:
filename = sys.argv[1]
url_name = sys.argv[2]
@mbarkhau
mbarkhau / mad_bitcoin_energy_savings.md
Created September 5, 2021 19:50
MAD Bitcoin Energy Savings

MAD Bitcoin Energy Savings

Imagine you're a bitcoin miner. You have a huge power bill, you have your capital that is depreciating like a glass of milk in the sunshine, but as long as the price per bitcoin is high and the local government isn't driving you out of the country, things are pretty good. I mean, figuratively speaking, you're printing money.

But think about this for a minute. It's not as if the bitcoin network would work any worse if you and 99% of the mining capacity would turn

@mbarkhau
mbarkhau / gnote_export.sh
Created July 15, 2021 11:39
gnote_export.sh
#!/bin/bash
# sudo apt-get install xml-twig-tools
_source="$HOME/.local/share/gnote"
_dest="$HOME/gnote_export/"
rm -rf "$_dest"
mkdir -p "$_dest"
#_file="simple_desktop_creator.desktop"
#_focus=$_dest$_file
@mbarkhau
mbarkhau / sublime_devbuild.py
Last active June 22, 2021 22:34
sublime_devbuild.py
#!/usr/bin/env python3
"""A sublime-text build script, to do the right thing?.
This script takes the currently open file as a
reference point and uses it to determine which commands
to run. This means that you don't have to select a build
commands when switching between projects, the fact that
you have a different file open is enough to indicate
which build you want to run.
@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