Skip to content

Instantly share code, notes, and snippets.

@hektor
hektor / README-python-service-on-systemd-activated-socket.md
Created December 10, 2023 14:01 — forked from drmalex07/README-python-service-on-systemd-activated-socket.md
An example network service with systemd-activated socket in Python. #systemd #python #socket #socket-activation

README

The example below creates a TCP server listening on a stream (i.e. SOCK_STREAM) socket. A similar approach can be followed to create a UDP server on a datagram (i.e. SOCK_DGRAM) socket. See man systemd.socket for details.

An example server

Create an simple echo server at /opt/foo/serve.py.

@hektor
hektor / Makefile
Created May 12, 2022 08:23
`nasm` assembly Makefile
SRCS := $(wildcard *.asm)
OBJS = $(SRCS:.asm=.o)
BINS = $(OBJS:.o=)
all: $(BINS)
%: %.o
ld -s -o $@ $@.o
%.o:%.asm
/*
* Minimal FIFO queue
*/
export const queue = (q = []) => {
const enqueue = x => q.push(x)
const dequeue = () => q.shift()
const peek = () => q[0]
const isEmpty = () => q.length === 0
/*
* Minimal graph adjacency list representation (unweighted)
*
* @example usage:
*
* const G = graph({
* a: ['b'],
* b: ['a', 'c'],
* c: ['b'],
* })
@hektor
hektor / repo.sh
Last active January 21, 2020 18:00
Quick repo w/ gitignore
# Spin up a quick repo
hub init
hub create <repo name>
npm init -y
npx gitignore -types
npx gitignore <gitignore type>
@hektor
hektor / base.css
Last active September 18, 2022 15:35
CSS - base
hr {
display: block;
height: 1px;
border: 0;
border-top: 1px solid #ccc;
margin: 1em 0;
padding: 0;
}
audio,
@hektor
hektor / normalize.css
Last active August 22, 2020 12:34
CSS - normalize
html {
line-height: 1.15;
-webkit-text-size-adjust: 100%;
}
*,
*::before,
*::after {
box-sizing: border-box;
}
@hektor
hektor / arithmetic.js
Last active December 26, 2019 17:57
ES6 - Arithmetic operator functions
const add = (...args) => args.reduce((a,b) => a + b)
const sub = (...args) => args.reduce((a,b) => a - b)
const mul = (...args) => args.reduce((a,b) => a * b)
const div = (...args) => args.reduce((a,b) => a / b)
const avg = (...args) => args.reduce((a,b) => a + b) / args.length
const rem = (...args) => args.reduce((a,b) => a % b)
const pow = (...args) => args.reduce((a,b) => a ** b)
@hektor
hektor / webApi.js
Last active January 21, 2020 18:01
ES6 - useful Web API snippets
window.addEventListener('visibilityChange', () => {
document.hidden ? console.log('hidden') : console.log('shown');
})
window.addEventListener('devicelight', e => { console.log(e.value) })