Skip to content

Instantly share code, notes, and snippets.

@timhughes
timhughes / Makefile
Last active April 21, 2025 14:09
Python Makefile
#
# vim:ft=make
# Makefile
#
#
# For bash autocomplete add to `~/.bashrc`:
#
# complete -W "\`if [ -f Makefile ]; then grep -oE '^[a-zA-Z0-9_-]+:([^=]|$)' Makefile | sed 's/[^a-zA-Z0-9_-]*$//'; elif [ -f makefile ]; then grep -oE '^[a-zA-Z0-9_-]+:([^=]|$)' makefile | sed 's/[^a-zA-Z0-9_-]*$//'; fi \`" make
.DEFAULT_GOAL := help
@timhughes
timhughes / fastapi_websocket_redis_pubsub.py
Last active February 21, 2025 08:41
FastAPI Websocket Bidirectional Redis PubSub
"""
Usage:
Make sure that redis is running on localhost (or adjust the url)
Install uvicorn or some other asgi server https://asgi.readthedocs.io/en/latest/implementations.html
pip install -u uvicorn
Install dependencies
@timhughes
timhughes / convert_seconds.js
Created October 31, 2024 23:55
[javascript] Convert seconds to a human readable format
const sec= 3333
function convert_seconds(sec) {
const divmod = (x, y) => [Math.floor(x / y), x % y];
var d,h,m,s;
var [m, s] = divmod(sec, 60);
var [h, m] = divmod(m, 60);
var [d, h] = divmod(h, 24);
return `${d}d,${h}h,${m}m,${s}s`;
}
#!/usr/bin/env bash
# vim: set ft=sh ts=4 sw=4 tw=120 et :
#
# minici
# Copyright (C) 2015 Tim Hughes <thughes@thegoldfish.org>
#
# Distributed under terms of the MIT license.
#
# Simple test runner that watches for changes and executes all arguments
#
@timhughes
timhughes / vimrc
Last active November 1, 2023 13:12
vimrc
" vim: set ft=vim ts=4 sw=4 tw=600 et :
""""""""""" README """""""""""""""
" To use this you will need to do the following.
" Follow the instructions at https://github.com/ryanoasis/nerd-fonts#font-installation
" to get the nice fonts. My preference is https://github.com/ryanoasis/nerd-fonts/tree/master/patched-fonts/LiberationMono/complete
" With the font installed you need to select the font in your terminal emulator
"
" Simple install of nerd font is:
"
" mkdir -p ~/.local/share/fonts
@timhughes
timhughes / asdf_install_multiple_versions.md
Last active May 23, 2023 11:16
asdf install multiple versions

Add the following to your .bashrc or wherever you keep this information. See https://asdf-vm.com/guide/getting-started.html#_3-install-asdf for details if you aren't using bash

ASDF_DIR="${HOME}/.asdf"
if ! [[ -d "$ASDF_DIR" ]]; then
    git clone https://github.com/asdf-vm/asdf.git "$ASDF_DIR" --branch v0.11.3
fi
if [[ -d "$ASDF_DIR" ]]; then
    . "${ASDF_DIR}/asdf.sh"
 . "${ASDF_DIR}/completions/asdf.${shell}"
@timhughes
timhughes / bash_assertion.sh
Created September 4, 2019 09:53
simple colored bash assertions
cecho(){
RED="\033[0;31m"
GREEN='\033[0;32m'
YELLOW='\033[1;33m'
NC='\033[0m' # No Color
printf "${!1}${2} ${NC}\n"
}
assert_fail(){
@timhughes
timhughes / show_eths.sh
Created March 9, 2021 11:15
Show real network interfaces
#!/bin/bash
for f in $(find /sys/class/net -type l -not -lname '*virtual*' -printf '%p\n'); do
dev=$(basename "$f")
driver=$(readlink "$f/device/driver/module")
if [ "$driver" ]; then
driver=$(basename "$driver")
fi
addr=$(cat "$f/address")
operstate=$(cat "$f/operstate")
printf "%11s|[%s]|%10s|(%s)\n" "$dev" "$addr" "$driver" "$operstate"
@timhughes
timhughes / show_eths.sh
Created March 19, 2021 12:43
show_eths.sh
#!/bin/bash
(
for f in $(find /sys/class/net -type l -not -lname '*virtual*' -printf '%p\n'); do
dev=$(basename "$f")
driver=$(readlink "$f/device/driver/module")
if [ "$driver" ]; then
driver=$(basename "$driver")
fi
addr=$(cat "$f/address")
phys_addr=$(cat "$f/phys_port_id" 2>/dev/null|sed 's/.\{2\}/&:/g;s/.$//')
@timhughes
timhughes / python_shell_script_template.py
Created April 11, 2014 11:53
Python shell script template
#!/usr/bin/env python
"""
SYNOPSIS
TODO helloworld [-h] [-v,--verbose] [--version]
DESCRIPTION
TODO This describes how to use this script.