Skip to content

Instantly share code, notes, and snippets.

@tilboerner
tilboerner / flatten_nested_dict.py
Created July 14, 2020 18:10
Python: flatten nested dict
def flatten(dd: dict, *, separator: str = '_') -> dict:
"""
Flatten nested dicts deeply.
Nested keys must be `str` and will be concatenated with a separator.
Example:
>>> flatten({'flat': 1, 'a': {'nested': {'key': 2}}})
{'flat': 1, 'a_nested_key': 2}
Note:
De-nesting can lead to new key collisions and data loss:
>>> flatten({'a': {'b': 111}, 'a_b': 2})
@tilboerner
tilboerner / taoup.py
Last active January 31, 2017 16:54
The Tao of Unix Programming
#! /usr/bin/python3
""" The tao of unix programming, Python-adapted from github:globalcitizen/taoup
Quotes via:
https://raw.githubusercontent.com/globalcitizen/taoup/master/taoup
"""
import itertools
import os
import random
@tilboerner
tilboerner / albumart.py
Last active August 29, 2015 14:19
Get CherryMusic album art filenames for directories
#!/usr/bin/env python
# -*- coding: utf-8 -*-
"""{script} [-r] [-f DIR] [-h|--help] [STARTDIR]
Get CherryMusic album art filenames for subdirectories.
-r recursive lookup in subdirectories
-f DIR find and print only this directory's art name
-h or --help print this text and exit
"""
@tilboerner
tilboerner / mail.php
Last active April 3, 2017 10:54
A validated PHP contact form, using https://github.com/PHPMailer/PHPMailer
<?php
//
// A validated PHP contact form
// http://blog.surmodernite.de/2013/12/a-validated-php-contact-form
//
// The MIT License (MIT)
// Copyright (c) 2013 tilman.boerner@gmx.net
// Permission is hereby granted, free of charge, to any person obtaining a copy
@tilboerner
tilboerner / test_module.py
Last active December 23, 2015 04:09
test module stub for cherrymusic
#!/usr/bin/python3
# -*- coding: utf-8 -*-
#
# CherryMusic - a standalone music server
# Copyright (c) 2012-2014 Tom Wallroth & Tilman Boerner
#
# Project page:
# http://fomori.org/cherrymusic/
# Sources on github:
# http://github.com/devsnd/cherrymusic/
@tilboerner
tilboerner / .gitconfig
Last active January 17, 2017 03:14
useful git aliases and config
[user]
name="NAME HERE"
email="E-MAIL HERE"
[alias]
co = checkout
dt = difftool
cm = commit
cma = "commit -a"
s = status