Skip to content

Instantly share code, notes, and snippets.

@tierpod
tierpod / lightdm-custom-settings.conf
Last active August 29, 2015 14:01
Lightdm custom settings
[SeatDefaults]
allow-guest=false
# user=root, run on greeter start
greeter-setup-script=/usr/bin/numlockx on
# user=user, run on session start
# session-setup-script=/usr/local/bin/resolution.sh
#greeter-hide-users=true
#greeter-show-manual-login=true
@tierpod
tierpod / markdown.coder
Created August 19, 2014 13:30
AkelPad markdown syntax highlight (coder plugin)
;----------------------------------------------;
; Coder plugin syntax file ;
;----------------------------------------------;
;Author: wisgest
;===============
;Colors
; Color need to be in #RRGGBB format.
; If color equal to zero, then color ignored.
@tierpod
tierpod / docopt-normalize.py
Last active August 29, 2015 14:26
python docopt arguments normalize: lowercase, remove '-'
'''
args: {'--append': True, 'FILE1': 'test', 'normal': 'normal'}
cfg: {'append': True, 'file1': 'test', 'normal': 'normal'}
'''
# simple way
cfg = {}
for arg in args:
cfg[arg.lower().replace('-','')] = args[arg]
@tierpod
tierpod / transfer-files.md
Last active January 19, 2016 07:58
Transfer a huge number of files over ssh

rsync

#!/bin/sh

RSYNC='ionice -c 3 nice -n 17 rsync'

$RSYNC --inplace --bwlimit=2000 -Wvr [-pgo] [--progress] --log-file=/tmp/rsync.log \
    --rsync-path="$RSYNC" src dest
@tierpod
tierpod / systemd-notify-wrapper.py
Last active December 8, 2017 09:50
Example for wrapper around ExecStart= for success/failed service notifications
#!/usr/bin/python3
# try this for long-running processes:
#
# $ cat example.service
# ...
# Type=simple
# ExecStart=systemd-notify-wrapper.py "/opt/scripts/long-running.sh -a -b FLAG" "%n"
# ...
#
# send "successful complete" notification if exit code valid
logger.Print("fetch metatile data to buffer")
var buf bytes.Buffer
err = mt.FetchEncodeTo(url, &buf)
if err != nil {
logger.Fatal(err)
}
logger.Print("write buffer to cache")
err = c.Write(t, &buf)
if err != nil {
@tierpod
tierpod / json-to-class.py
Created February 7, 2018 14:10
json to python class example
#!/usr/bin/env python
# -*- coding: utf-8 -*-
import json
import os.path
def md5sum():
return "test"
class File(object):
@tierpod
tierpod / setupLog.go
Created November 28, 2018 11:48
Configure logger in go with logutils
func setupLog(debug, datetime bool) {
filter := &logutils.LevelFilter{
Levels: []logutils.LogLevel{"DEBUG", "INFO", "WARN", "ERROR"},
MinLevel: logutils.LogLevel("INFO"),
Writer: os.Stdout,
}
if debug {
filter.MinLevel = logutils.LogLevel("DEBUG")
}
@tierpod
tierpod / systemd-nspawn-add-machine.sh
Created June 6, 2019 05:40
Example: add systemd-nspawn machine, install packages, add user
#!/bin/bash
# Add systemd-nspawn machine, install base packages, create builder user
set -eu
if [ $# -ne 1 ]; then
echo "usage: $0 MACHINE"
exit 1
fi
@tierpod
tierpod / scrape.py
Created March 16, 2022 10:58
Example: use python asynio + aiohttp + limits for scaping urls
#!/usr/bin/env python3
# Usage: scrape.py urls.txt
# Based on: https://pawelmhm.github.io/asyncio/python/aiohttp/2016/04/22/asyncio-aiohttp.html
import sys
import asyncio
import aiohttp