This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#! /usr/bin/env python3 | |
# | |
# ConfigFile.py - Jani Tammi <[email protected]> | |
# | |
# NOTE: You obviously still need the proper privileges. | |
# You cannot run this as a regular user and set | |
# owner to be root and expect the .create() to | |
# actually manage that. | |
# THIS WAS WRITTEN PRIMARILY FOR INSTALLATION | |
# SCRIPTS THAT EXECUTE AS ROOT !! |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#! /usr/bin/env python3 | |
# | |
# with_identity.py - Jani Tammi <[email protected]> | |
# | |
# Convenient way to assume another user identity for limited work. | |
# Created for installation scripts that run as root. | |
# | |
import os | |
import pwd | |
import grp |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#! /usr/bin/env python3 | |
# | |
# A class to compute the mean, SAMPLE variance, and SAMPLE standard deviation | |
# of a stream of data. | |
# | |
# RunningStatistics.py - 2018, Jani Tammi <[email protected]> | |
# 0.1.0 Initial version. | |
# | |
# Makes use of a method to calculate running variance | |
# by B. P. Welford, 1962, |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#! /usr/bin/env python3 | |
# Snippet for cleaning out configuration file list-values (import configparser). | |
# For reading/processing configuration file values, performance is not an issue. | |
# The key = value can sometimes look something like: | |
# | |
# files = , data.db ,script.py, ,, data.db ,,, | |
# | |
# NOTE: Neither of these can deal with quotations (" or ') and thus cannot process | |
# list items that need to have the separator (,) in them. | |
# |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#! /usr/bin/env python3 | |
# 2019-12-28 Jani Tammi | |
# | |
# Slightly improved DefaultDotDict, using '*' as default value. | |
# NOTE: DefaultDotDict.get('foobar') does NOT return value for key '*'. | |
# You still get to define your own default value. | |
# | |
class DefaultDotDict(dict): |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class DefaultDict(dict): | |
"""Returns DefaultDict.default value for missing key, or raises KeyError if default has not been set.""" | |
def __missing__(self, key): | |
if getattr(self, 'default', None): | |
return self.default | |
raise KeyError( | |
f"Key '{key}' does not exist and default has not been set!" | |
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#! /usr/bin/env python2 | |
# | |
# ROS 1 "Kinetic Kame" server | |
# EOL date at April 2021, but this version uses Python 2.7 | |
# | |
# Demo code for Jupyter access, need accesspoints and all the | |
# associated data packet handling. | |
# | |
from BaseHTTPServer import BaseHTTPRequestHandler, HTTPServer | |
import json |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env python3 | |
# | |
# Simple command line yes/no prompter. | |
# 2020-04-24 Jani Tammi <[email protected]> | |
# | |
# default = None | "y" | "n" If and how ENTER is interpreted. | |
# echo = False | True Will the prompt line be appended with selection. | |
# | |
def getch(): |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* | |
* TEMPer.c - Simple TEMPer USB temperature meter reader | |
* Adapted from https://gist.github.com/artms/5356eafcd1244c6fabc0f735e5de7096 | |
* Credit: Arturas Moskvinas | |
* | |
* Adapted to C by Jani Tammi <[email protected]>, 2020-10-11 | |
* | |
*/ | |
#include <stdio.h> | |
#include <stdint.h> |