Skip to content

Instantly share code, notes, and snippets.

Avatar

Christopher Arndt SpotlightKid

View GitHub Profile
@SpotlightKid
SpotlightKid / test.sh
Last active Sep 4, 2022
Making a POST request with url or form-encoded params with MicroPython
View test.sh
$ 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'}
@SpotlightKid
SpotlightKid / getcomments.py
Last active Aug 24, 2022
Parse Python source code from file and get/print source code comments.
View getcomments.py
# -*- coding: utf-8 -*-
"""Parse Python source code from file and get/print source code comments."""
__all__ = ('get_comments', 'get_comment_blocks')
import tokenize
from io import StringIO
@SpotlightKid
SpotlightKid / debounce.py
Last active Aug 8, 2022
Debounced switch using pin and timer IRQs on MicroPython
View debounce.py
#
# 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 / notes.rst
Last active Jun 29, 2022
Building your Kivy App for Android
View notes.rst

Building your Kivy App for Android

Requirements

You need:

  • A reasonably modern Android device with a USB port
  • A micro USB cable
@SpotlightKid
SpotlightKid / getdocstrings.py
Created Sep 1, 2014
Parse Python source code and get or print docstrings.
View getdocstrings.py
# -*- coding: utf-8 -*-
"""Parse Python source code and get or print docstrings."""
__all__ = ('get_docstrings', 'print_docstrings')
import ast
from itertools import groupby
from os.path import basename, splitext
@SpotlightKid
SpotlightKid / github_download.py
Created Aug 6, 2014
Github file viewer / general URL download script for Pythonista
View github_download.py
"""Prompt user for URL and filename and download the remote resource to a file.
If the clipboard contains a HTTP(S) or FTP(S) URL, the URL input dialog is
pre-filled with it.
The suggested local filename is extracted from the URL, if possible.
If a github file viewer URL is given, it is transformed into the matching
raw file access URL, which makes it easier to download files on github you
are viewing in your browser. Just copy the URL to the clipboard, change to
@SpotlightKid
SpotlightKid / parse_srcinfo.py
Last active Apr 1, 2022
Get info from a PKGBUILD file by calling makepkg --printsrcinfo and parsing the output
View parse_srcinfo.py
#!/usr/bin/env python3
import json
import sys
from subprocess import CalledProcessError, run
ARRAY_FIELDS = (
"arch",
"arch",
"b2sums",
@SpotlightKid
SpotlightKid / aescrypt.py
Created Sep 3, 2014
Encrypt/decrypt files with symmetric AES cipher-block chaining (CBC) mode.
View aescrypt.py
#!/usr/bin/env python
# -*- coding: utf-8 -*-
"""Encrypt/decrypt files with symmetric AES cipher-block chaining (CBC) mode.
Usage:
File Encryption:
aescrypt.py [-f] infile [outfile]
@SpotlightKid
SpotlightKid / open-in-firefox.sh
Last active Dec 27, 2021
Open URL from Termux command line in Firefox Android browser
View open-in-firefox.sh
#!/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 / alsa-query.c
Created Apr 29, 2019
Print hardware capabilities of ALSA device
View alsa-query.c
/*
* alsa-query.c - print hardware capabilities of ALSA device
*
* compile with: gcc -o alsa-query alsa-query.c -lasound
*/
#include <stdio.h>
#include <alsa/asoundlib.h>
#define ARRAY_SIZE(a) (sizeof(a) / sizeof *(a))