Skip to content

Instantly share code, notes, and snippets.

View AlexElvers's full-sized avatar

Alexander Elvers AlexElvers

  • Berlin
View GitHub Profile
@AlexElvers
AlexElvers / doveadm_pw.py
Created September 6, 2016 16:09
Create doveadm password hashes in Python
"""
This function encodes the password similar to `doveadm pw -p PASSWORD -r ROUNDS -s SCHEME`, e.g.
{SHA256-CRYPT}$5$rounds=100000$vEmVf8wqYqnBHbFL$ed0W1.B1A3vw4dzXhBQjgxh7FB/lVSsmDAQahyzHJDB
"""
import crypt
def encode_password(password: str, rounds: int = None, scheme: str = None) -> str:
"""
Encode password with random salt.
@AlexElvers
AlexElvers / virtualenv-activate.sh
Last active July 26, 2019 20:47
Search and activate virtualenv in current directory or parent directories
activate() {
local path_="$PWD"
while [[ "$path_" != "/" ]]; do
if [[ -e "$path_/Pipfile" ]]; then
echo "Pipfile found in $path_"
pipenv shell
return 0
elif [[ -e "$path_/env/bin/activate" ]]; then
echo "virtual env found in $path_"
source "$path_/env/bin/activate"
@AlexElvers
AlexElvers / handler.sh
Created March 22, 2018 12:45
Interactive shutdown popup in GNOME when pressing the power button
#!/bin/bash
# Replaces /etc/acpi/handler.sh
case "$1" in
button/power)
case "$2" in
PBTN|PWRF)
logger 'PowerButton pressed'
gnome_users=$(pgrep gnome-session | xargs ps -o %u -p | sed 1d)
while read -r user; do
@AlexElvers
AlexElvers / twittersafepng.sh
Created November 25, 2016 00:43
Make the top left pixel slightly transparent so that Twitter does not convert it into ugly JPEG
twittersafepng() {
outfile="${1/.png}_twittersafe.png"
convert "$1" -alpha on -fill '#000000fe' -draw 'matte 0,0 point' "$outfile"
echo "written to $outfile"
}

Keybase proof

I hereby claim:

  • I am alexelvers on github.
  • I am aelvers (https://keybase.io/aelvers) on keybase.
  • I have a public key whose fingerprint is 29C9 1451 2D0B 7FEB D63E 43B7 7DB1 096F FD76 DBBA

To claim this, I am signing this object: