Skip to content

Instantly share code, notes, and snippets.

View SpotlightKid's full-sized avatar

Christopher Arndt SpotlightKid

View GitHub Profile
@SpotlightKid
SpotlightKid / debounce.py
Last active January 23, 2023 17:51
Debounced switch using pin and timer IRQs on MicroPython
#
# inspired by: https://forum.micropython.org/viewtopic.php?t=1938#p10931
#
import micropython
try:
from machine import Timer
timer_init = lambda t, p, cb: t.init(period=p, callback=cb)
except ImportError:
from pyb import Timer
@SpotlightKid
SpotlightKid / pipe.py
Last active December 12, 2017 00:44
Handy utility function to get output of shell command piping input to stdin (requires Python 3.5+).
>>> pipe('md5sum', 'This is a test')
--> 'ce114e4501d2f4e2dcea3e17b546f339 -\n'
>>> pipe('md5sum', b'This is a test')
--> b'ce114e4501d2f4e2dcea3e17b546f339 -\n'
>>> pipe(['gzip', '-c'], b'This is a test')
b'\x1f\x8b\x08\x00\xd6\x91\x13Z\x00\x03\x0b\xc9\xc8,V\x00\xa2D\x85\x92\xd4\xe2\x12\x002\x9fz\xc0\x0e\x00\x00\x00'
>>> pipe('bash', 'ls').splitlines()
@SpotlightKid
SpotlightKid / get_aliases.py
Created November 21, 2017 02:32
Get a list of BASH alias definitions (requires Python 3.5+)
from subprocess import PIPE, run, STDOUT
def get_aliases():
aliases = []
for line in run(["bash", '-i'], input='alias', stdout=PIPE, stderr=PIPE,
env={'PS1': ''}, encoding='utf-8').stdout.splitlines():
name, cmd = line.split('=', 1)
aliases.append((name[6:], cmd[1:-1]))
return aliases
@SpotlightKid
SpotlightKid / open-in-firefox.sh
Last active February 13, 2024 10:38
Open URL from Termux command line in Firefox Android browser
#!/bin/bash
#
# open-in-firefox.sh - open URL from Termux command line in Firefox Android browser
#
# Works with file:// URLs too, unlike with termux-open{-url}.
#
exec am start --user 0 -a android.intent.action.VIEW -n org.mozilla.firefox/.App -d "$1" >/dev/null
@SpotlightKid
SpotlightKid / test.sh
Last active October 9, 2023 21:31
Making a POST request with url or form-encoded params with MicroPython
$ micropython uget.py key1=value1 key2=value2 key2=value3
{'url': 'http://httpbin.org/get?key2=value3&key1=value1', 'headers': {'Host': 'httpbin.org', 'Connection': 'close'}, 'args': {'key2': 'value3', 'key1': 'value1'}, 'origin': 'XXX.XXX.XXX.XXX'}
$ micropython upost.py foo=bar spamm=42
{'files': {}, 'headers': {'Host': 'httpbin.org', 'Content-Length': '16', 'Content-Type': 'application/x-www-form-urlencoded', 'Connection': 'close'}, 'args': {}, 'form': {'spamm': '42', 'foo': 'bar'}, 'origin': 'XXX.XXX.XXX.XXX', 'data': '', 'json': None, 'url': 'http://httpbin.org/post'}
#!/usr/bin/env python
# -*- coding: utf-8 -*-
import os
import requests
import time
from io import BytesIO
from os.path import join
from selenium import webdriver
@SpotlightKid
SpotlightKid / extscreenmanager.py
Last active October 24, 2017 19:28 — forked from rnixx/gist:2aab5e13e17c1582b6dd
Extended Screen Manager for kivy with better convenience for switching between screens.
# -*- coding: utf-8 -*-
"""Extended Screen Manager for kivy with better convenience for switching between screens."""
from six import string_types, iteritems
from kivy.logger import Logger
from kivy.uix.screenmanager import ScreenManager
from kivy.uix.screenmanager import ScreenManagerException
from kivy.uix.screenmanager import Screen
@SpotlightKid
SpotlightKid / notes.rst
Last active June 29, 2022 04:28
Building your Kivy App for Android

Building your Kivy App for Android

Requirements

You need:

  • A reasonably modern Android device with a USB port
  • A micro USB cable
@SpotlightKid
SpotlightKid / recvrpn.py
Last active November 23, 2017 10:49
Decode received MIDI RPN messages
import time
from collections import defaultdict
import rtmidi
from rtmidi.midiconstants import *
from rtmidi.midiutil import open_midiinput
class RPNDecoder:
def __init__(self, channel=1):
@SpotlightKid
SpotlightKid / ImageFrame.py
Last active December 20, 2018 11:06
Remote-controllable digital image frame for iOS/Pythonista
#!python2
# -*- coding: utf-8 -*-
"""Remote-controllable digital image frame with built-in web server."""
import logging
import os
import re
import sys
import threading
import time