Skip to content

Instantly share code, notes, and snippets.

@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`;
}
@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 / service_state.py
Created August 10, 2021 13:36
python systemd dbus example
#! /usr/bin/env python3
import pydbus
import logging
unit_name='sshd.service'
sysbus = pydbus.SystemBus()
systemd = sysbus.get('.systemd1')
unit = sysbus.get('.systemd1', systemd.GetUnit(unit_name))
@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 / bar.py
Created March 19, 2021 22:17
multiple clas inheritance of ABCs with asyncio
from abc import ABC, abstractmethod
import asyncio
import inspect
class MyABC(ABC):
def __new__(cls, *arg, **kwargs):
# get all coros of A
parent_coros = inspect.getmembers(MyABC, predicate=inspect.iscoroutinefunction)
@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 / asyncio_ws_server.py
Last active March 15, 2021 09:39
Asyncio Websocket server which exits cleanly
#! /usr/bin/env python3
# -*- coding: utf-8 -*-
# vim:fenc=utf-8
#
import asyncio
import datetime
import json
import logging
from typing import Dict
@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 / gist:ea9c8a2f0be4e384bb0480f0989ca0ec
Created February 2, 2021 01:17
list ports opened in processes namespace
cat /proc/721/net/tcp |awk 'NR>1 {print $2}' | while read line ; do printf "%d.%d.%d.%d:%d\n" "0x${line:6:2}" "0x${line:4:2}" "0x${line:2:2}" "0x${line:0:2}" "0x${line:9:4}" ; done
@timhughes
timhughes / podman-docker-compat.md
Last active November 2, 2021 01:03
Docker service for Podman

Replacing docker with Podman

This is all done as a user.

Add insecure registry if you need to use something internal

cat <<EOF> ~/.config/containers/registries.conf
unqualified-search-registries = ["registry.fedoraproject.org", "registry.access.redhat.com", "registry.centos.org", "docker.io"]

[[registry]]