Skip to content

Instantly share code, notes, and snippets.

View nickovs's full-sized avatar

Nicko van Someren nickovs

  • Absolute Software
  • Boulder, CO, USA
View GitHub Profile
@nickovs
nickovs / pathprefix.py
Created April 4, 2018 00:45
Easier handling of file paths in Python
# A Python (3) class for more compact path handling.
#
# If you find yourself calling os.path.join() with the same first parameter
# over and over again it can get rather tedious. Instead you can now go:
#
# path = PathPrefix("/some/path")
# file1 = path / "file1"
# sub_file = path / "subdir" / "file2"
class PathPrefix(str):
@nickovs
nickovs / aws-session.py
Created November 28, 2018 23:47
Easy sessions credentials for Amazon Web Services when multi-factor authentication is required.
#!/usr/bin/env python3
"""Fetch and print temporary session credentials with MFA
To use this tool first put the ARN of your MFA access token into a
file called .aws_token_id in your home directory and ensure that the
tool is on your path. Then execute the command:
eval `aws-session`
You will be promoted to enter your current MFA token value. After this
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
@nickovs
nickovs / Hypercircumsphere.ipynb
Last active February 18, 2021 15:47
Compute the N-dimentional (hyper-)circumsphere
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
@nickovs
nickovs / make_git_layer.sh
Created March 13, 2023 16:41
A script to build an AWS Lambda overlay layer that installs `git` and all its dependencies.
#!/bin/bash
# Build an AWS Lambda zip file containing git and its dependencies
cat <<\EOF > tmp_build.sh
#!/bin/bash
# Comment this out if you want to see all the actions.
quiet=-q
# List of main executables from /usr/bin to copy into layer
@nickovs
nickovs / badger_orion.py
Created May 28, 2022 19:30
A simple script for receiving water meter readings from a Badger ORION water meter using an Software Defined Radio (SDR).
#!/usr/bin/env python3
# A simply tool for receiving water meter readings from a Badger ORION water meter.
# Device radio details can be found at https://fccid.io/GIF2006B
# Requires rtl_433 to be installed. See https://github.com/merbanan/rtl_433
import sys
import json
import subprocess
@nickovs
nickovs / stepper.py
Last active November 14, 2023 22:07
A stepper motor driver for MicroPython
# stepper.py
# A micropython driver for 4-phase, unipolar stepper motors such as
# the 28BYJ-48
# Relesed to the Public Domain by Nicko van Someren, 2020
# The constructor for the Stepper class takes as arguments the four
# pins for driving the motor phases, in phase order, and optionally a
# timer. The pins can be passed as pin numbers or machine.Pin objects
@nickovs
nickovs / zbar_lambda_build.sh
Last active December 27, 2023 19:02
A script for building a version of the Zbar library suitable for running in an AWS Lambda instance
#!/bin/bash
# Clear out old images
[ -d "lib" ] && rm -r lib
cat <<EOF > tmp_recipe.sh
# This is the actual container-side recipe
yum groupinstall -y "Development Tools"
cd /root
@nickovs
nickovs / get_public_ip.py
Created January 17, 2024 18:35
A tool for fetching your current public IPv4 address
#!/usr/bin/env python3
from random import shuffle
from sys import exit, stderr
from urllib.request import urlopen
from urllib.error import URLError
urls = [
"ifconfig.me",
@nickovs
nickovs / pico_touch.py
Created February 26, 2024 14:21
RP2040 / Pi Pico touch interface using just one resistor
# Simple Pi Pico/RP2040 touch interface
# This implements a capacitive touch interface using two GPIO pins and just one external resistor.
# It work by using the user's body as a capacitor to ground; the output GPIO pin goes through the
# resistor to the touch point, which is connected directly to the input GPIO pin. A PIO program
# periodically toggels the output pin and then counts the number of cycles until the input pin
# changes level. The time constant for the response is proportional to both the fixed resistor
# value and the capacitance at the touch point, which varies depending on if the user is touching
# or not. With the default setting a 2.2 megaohm resistor works well.