Skip to content

Instantly share code, notes, and snippets.

View jelmervdl's full-sized avatar

Jelmer jelmervdl

View GitHub Profile
@jelmervdl
jelmervdl / getters-and-setters.cpp
Created January 18, 2022 12:35
getters and setters for nested structs
#include <utility>
#include <iostream>
template <typename Retval, typename T>
auto make_ref(Retval T::*prop) {
return [=](T &obj) -> Retval& { return obj.*prop; };
}
template <typename Retval, typename T, typename... Args>
auto make_ref(Retval T::*prop, Args... args) {
@jelmervdl
jelmervdl / progress.sh
Created September 23, 2021 09:57
Print read progress of pids with open files
#!/bin/bash
find-open-files() {
find /proc/$1/fd/ -maxdepth 1 -lname '/*' -not -lname '/dev/*' -printf "%f\n"
}
format-file() {
readlink -f /proc/$1/fd/$2
}
@jelmervdl
jelmervdl / linecount.sh
Created April 23, 2021 10:31
Interactive line counter
#!/bin/bash
N=0
echo $N
tail -qfn+0 $@ | while read line; do
N=$((N+1))
echo -e "\e[1A\e[K${N}"
done
#!/usr/bin/env python3
import site
site.addsitedir('env/src/tmxutil')
import sys
import re
from datetime import datetime
from tmxutil import make_reader, TMXWriter
from collections import defaultdict
from logging import getLogger, ERROR
@jelmervdl
jelmervdl / natsort.py
Created February 8, 2018 12:43
Natural sorting in python (i.e. treat numbers as numbers)
items = [
'a.5.b.1',
'a.1.b.4',
'a.1.b.14',
]
def natcast(item):
if item.isdigit():
return int(item)
else:
var PDOKGeocoder = L.Class.extend({
options: {
suggestUrl: 'https://geodata.nationaalgeoregister.nl/locatieserver/v3/suggest',
lookupUrl: 'https://geodata.nationaalgeoregister.nl/locatieserver/v3/lookup',
geocodingQueryParams: {
wt: 'json'
}
},
initialize: function(options) {
@jelmervdl
jelmervdl / led-sf-00297.conf
Last active January 21, 2018 17:21
LIRC remote configuration for Aldi RGB-LED Flex Band Set light strip (LED-SF-00297) http://woodsgood.ca/projects/2015/02/13/rgb-led-strip-controllers-ir-codes/
begin remote
name LED-SF-00297
flags SPACE_ENC|CONST_LENGTH
eps 20
aeps 200
bits 32
header 9000 4500
one 560 1690
zero 560 560
@jelmervdl
jelmervdl / array_path.php
Created October 17, 2017 10:16
Traverse a nested PHP array/object structure using a path
<?php
function array_path($array, $path, $default_value = null)
{
// Construct the path
if (!preg_match('/^(?P<head>\w+)(?P<rest>(\[\w+\]|->\w+)*)$/', $path, $match))
throw new InvalidArgumentException("The path '$path' is malformed");
$steps = [['index' => $match['head']]];
@jelmervdl
jelmervdl / parser.py
Created August 23, 2017 11:49
Small (and inefficient) parser in Python that can deal with ambiguity
from pprint import pprint
class l(object):
__slots__ = ('word',)
def __init__(self, word):
self.word = word
def __repr__(self):
return 'l({})'.format(self.word)
@jelmervdl
jelmervdl / convert.sh
Created July 31, 2017 11:32
iPhone ringtone
ffmpeg -i "$INPUT" -ac 1 -ab 128000 -acodec aac -f mp4 "$OUTPUT"