Skip to content

Instantly share code, notes, and snippets.

from typing import Any, Dict, List, Mapping, Union
# Values for JSON that aren't nested
JSON_v = Union[str, int, float, bool, None]
# If MyPy ever permits recursive definitions, just uncomment this:
# JSON = Union[List['JSON'], Mapping[str, 'JSON'], JSON_v]
# Until then, here's a multi-layer way to represent any (reasonable) JSON we
# might send or receive. It terminates at JSON_4, so the maximum depth of
@nwf
nwf / sphinx_toctreeish.py
Created July 15, 2020 23:04
Sphinx Toctree workaround
import re
from typing import List
from docutils import nodes
from docutils.nodes import Node
from docutils.statemachine import StringList, ViewList
import sphinx
from sphinx import addnodes
from sphinx.directives.other import TocTree
@lukicdarkoo
lukicdarkoo / configure.sh
Last active November 22, 2023 04:37
Raspberry Pi: AP + client mode
#!/bin/sh
# The script configures simultaneous AP and Managed Mode Wifi on Raspberry Pi Zero W (should also work on Raspberry Pi 3)
# Usage: curl https://gist.githubusercontent.com/lukicdarkoo/6b92d182d37d0a10400060d8344f86e4/raw | sh -s WifiSSID WifiPass APSSID APPass
# Licence: GPLv3
# Author: Darko Lukic <lukicdarkoo@gmail.com>
# Special thanks to: https://albeec13.github.io/2017/09/26/raspberry-pi-zero-w-simultaneous-ap-and-managed-mode-wifi/
MAC_ADDRESS="$(cat /sys/class/net/wlan0/address)"
CLIENT_SSID="${1}"
CLIENT_PASSPHRASE="${2}"
@EdwardBetts
EdwardBetts / pprint_color.py
Last active March 19, 2024 18:17
Python pprint with color syntax highlighting for the console
from pprint import pformat
from typing import Any
from pygments import highlight
from pygments.formatters import Terminal256Formatter
from pygments.lexers import PythonLexer
def pprint_color(obj: Any) -> None:
"""Pretty-print in color."""
@dferg
dferg / howto-tomato-install-extras.markdown
Last active December 30, 2021 07:57
HOWTO: Install extra kernel modules on Shibby TomatoUSB

Introduction

This howto describes installing the extra kernel modules for the Tomato open-source router firmware. We will install them in the /opt/extras area.

Requirements

  • Router running Shibby's fork of TomatoUSB
  • entware installed to a USB stick mounted at /opt

This Howto Was Tested With

@dferg
dferg / howto-tomato-install-entware.markdown
Last active January 22, 2024 04:40
HOWTO: Install entware on Shibby TomatoUSB

Introduction

This howto describes installing entware for the Tomato open-source router firmware.

Requirements

  • USB stick - 1G or more in size
  • USB-capable router running TomatoUSB.

This Howto Was Tested With

@niclashoyer
niclashoyer / cpconfig.sh
Last active January 19, 2018 00:06
Replace environment variables in configuration files with optional default using perl regular expressions.
#!/bin/bash
#
# Replaces ${var:def} expressions in text files with environment variables with
# an optional default.
#
# Assuming VAR1 contains the value "foo" nad VAR2 is undefined, the following
# expressions will evaluate as given on the right side:
#
# ${VAR1} ~> foo
# ${VAR2:bar} ~> bar
@damphat
damphat / apt-rdepends-tree
Last active December 16, 2023 01:38
debian dependency tree
#! /bin/bash
# Description: show dependency tree
# Author: damphat
if [ $# != 1 ]; then
echo 'Usage: apt-rdepends-tree <package>'
echo 'Required packages: apt-rdepends'
exit 1
fi

A good commit message looks like this:

Header line: explaining the commit in one line

Body of commit message is a few lines of text, explaining things
in more detail, possibly giving some background about the issue
being fixed, etc etc.

The body of the commit message can be several paragraphs, and
please do proper word-wrap and keep columns shorter than about