Skip to content

Instantly share code, notes, and snippets.

@mortie
mortie / cfdns.sh
Created September 13, 2022 19:22
Cloudflare dynamic DNS
#!/bin/sh
set -eu
token='<your API token>'
zone='<your DNS zone ID>'
record='<your DNS record ID>'
ip_url='ifconfig.co'
call() {
@mortie
mortie / sst
Created August 5, 2022 21:24
sst: Reliable SSH connections using tmux
#!/bin/sh
# SST: SSH, but reliable, using tmux.
# When you lose connection, the connection will be re-tried, and you will get back where you
# left off.
# An aggressive heartbeat setting is used to detect network issues much more reliably than
# SSH's default settings would.
#
# Usage:
# sst <host>: Create a temporary tmux session, which will be killed when it hasn't
@mortie
mortie / tarex.c
Created July 20, 2022 16:32
Fast tar archive extractor
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <sys/stat.h>
#include <sys/types.h>
#include <fcntl.h>
#include <unistd.h>
#include <errno.h>
char zeroblock[512];
@mortie
mortie / jcof.md
Last active July 10, 2022 22:24
JCOF: JSON-like Compact Object Format

JCOF: JSON-like Compact Object Format

A more efficient way to represent JSON-style objects.

About

JCOF tries to be a slot-in replacement for JSON, with most of the same semantics, but with a much more compact representation of objects. The main way it does this is to introduce a string table at the beginning of the object, and then replace all strings with indexes into that string table. It also employs a few extra tricks to make objects as small as possible, without losing the most

#!/usr/bin/env python3
from pathlib import Path
import time
import sys
dirpath = sys.argv[1]
def fsize(f):
try:
@mortie
mortie / Makefile
Last active November 23, 2021 14:23
Probably fairly reasonable Makefile
SRCS = src/main.cc
PKGS :=
WARNINGS := -Wall -Wextra -Wpedantic
INCLUDES := -Isrc
FLAGS := $(WARNINGS) $(INCLUDES)
CXXFLAGS += $(FLAGS) -std=c++17
CFLAGS += $(FLAGS)
LDFLAGS +=
@mortie
mortie / music.py
Last active February 23, 2021 22:58
Horrible Music
#!/usr/bin/env python3
import simpleaudio as sa
import numpy as np
import sys
import wave
kick = wave.open("kick.wav")
class Mixer:
def __init__(self, wav, secs):

No it's not valid ISO8601

ISO8601 has multiple valid representations

that is true, for example

Basic format: YYYYMMDD Example: 19850412
Extended format: YYYY-MM-DD Example: 1985-04-12 
@mortie
mortie / conventions.md
Last active August 17, 2020 20:06
C++ Coding Conventions

C++ Coding Conventions

Names

  • Structs/classes: PascalCase
  • Struct member variables: camelCase
  • Class member variables: camelCase_ (decorated)
  • All non-member variables (including function arguments): camelCase
  • Member functions and free functions: camelCase
  • Header files: file.h