Skip to content

Instantly share code, notes, and snippets.

@dirkakrid
dirkakrid / multilogging.py
Created October 27, 2016 06:08 — forked from Zaharid/multilogging.py
Proper way to manage logging for multiple processes.
# -*- coding: utf-8 -*-
"""
Created on Fri Jun 26 13:16:22 2015
@author: zah
"""
import multiprocessing
import logging
@dirkakrid
dirkakrid / remconsole.py
Created October 28, 2016 05:31 — forked from schlamar/remconsole.py
Fork of `rfoo.utils.rconsole` to run with other RPC implementations.
"""
remconsole.py
A Python console you can embed in a program and attach to remotely.
To spawn a Python console in a script do the following in any scope
of any module:
import remconsole
remconsole.spawn_server()
@dirkakrid
dirkakrid / processify.py
Created October 28, 2016 05:33 — forked from schlamar/processify.py
processify
import os
import sys
import traceback
from functools import wraps
from multiprocessing import Process, Queue
def processify(func):
'''Decorator to run a function as a process.
Be sure that every argument and the return value
@dirkakrid
dirkakrid / mplog.py
Created October 28, 2016 05:39 — forked from myaut/mplog.py
Multiprocess grep in Python
from multiprocessing import Pool
from itertools import chain
import re
import sys
PROC_COUNT = 8
LINES_PER_PROC = 40
if len(sys.argv) != 3:
@dirkakrid
dirkakrid / tree.md
Created October 29, 2016 15:38 — forked from hrldcpr/tree.md
one-line tree in python

One-line Tree in Python

Using Python's built-in defaultdict we can easily define a tree data structure:

def tree(): return defaultdict(tree)

That's it!

from microbit import *
networkID = 0 # Change the channel variable in the radio.configure to this
def selectNetwork(): # Call this function before calling anything else
global networkID
currentID = networkID
while True:
if button_a.is_pressed() and button_b.is_pressed():
networkID = currentID
# `ref: https://fangpenlin.com/posts/2012/08/26/good-logging-practice-in-python/
import logging
logger = logging.getLogger(__name__)
logger.setLevel(logging.INFO)
# create a file handler
handler = logging.FileHandler('hello.log')
@dirkakrid
dirkakrid / beautiful_idiomatic_python.md
Created October 29, 2016 16:51 — forked from JeffPaine/beautiful_idiomatic_python.md
Transforming Code into Beautiful, Idiomatic Python: notes from Raymond Hettinger's talk at pycon US 2013. The code examples and direct quotes are all from Raymond's talk. I've reproduced them here for my own edification and the hopes that others will find them as handy as I have!

Transforming Code into Beautiful, Idiomatic Python

Notes from Raymond Hettinger's talk at pycon US 2013 video, slides.

The code examples and direct quotes are all from Raymond's talk. I've reproduced them here for my own edification and the hopes that others will find them as handy as I have!

Looping over a range of numbers

for i in [0, 1, 2, 3, 4, 5]:
@dirkakrid
dirkakrid / nspawn-container
Created October 29, 2016 16:53 — forked from mopemope/nspawn-container
nspawn-container
#!/bin/bash
TOOLBOX_DOCKER_IMAGE=$1
TOOLBOX_USER=root
machinename=$(echo "${USER}-${TOOLBOX_DOCKER_IMAGE}" | sed -r 's/[^a-zA-Z0-9_.-]/_/g')
machinepath="/var/lib/toolbox/${machinename}"
if [ ! -d ${machinepath} ] || systemctl is-failed ${machinename} ; then
sudo mkdir -p "${machinepath}"
@dirkakrid
dirkakrid / !OpenELEC Container README.md
Created October 29, 2016 17:03 — forked from hobbsAU/!OpenELEC Container README.md
OpenElec systemd-nspawn Container

Description

OpenELEC runs Kodi, an award-winning free and open source (GPL) software media player and entertainment hub for digital media. For more info see http://kodi.tv . The base system has been designed and built from the ground up to be as efficient as possible – consuming only tiny disk and memory footprints and providing cutting edge hardware support to deliver a set-top box experience.

In order to run software above the base OpenELEC distribution with minimal impact to the OpenELEC base, one alternative is to use a container.

I have chosen to use systemd-nspawn instead of chroot. There are really no downsides as long as you can configure the required kernel config options and have a basic working knowledge of systemd.

Installation