Skip to content

Instantly share code, notes, and snippets.

@multun
multun / wow.c
Last active December 12, 2017 14:37
An array iterator in C
#include <stddef.h>
#include <stdio.h>
#define ARR_SIZE(...) (sizeof(__VA_ARGS__) / sizeof((__VA_ARGS__)[0]))
#define FOREACH_ARR(Type, IName, ...) \
for (struct \
{ \
size_t i; \
@multun
multun / config_parser.py
Last active January 30, 2023 11:13
Parse arguments augmented with a YAML config file
import sys
import yaml
import argparse
class ConfigParser():
def __init__(self, *pargs, **kwpargs):
self.options = []
self.pargs = pargs
self.kwpargs = kwpargs
@multun
multun / libhook.sh
Last active April 8, 2020 18:24
bash space safe cleanup hooks
__cleanup_hook_i=0
__cleanup_hook () {
for ((i=__cleanup_hook_i - 1; i >= 0; i--)); do
eval "\"\${__cleanup_hook_action_${i}[@]}\""
done
}
trap __cleanup_hook EXIT
@multun
multun / allocation_checker.c
Last active November 9, 2018 18:12
Poor man's embed-ish allocation tracker
#include <stdint.h>
#include <stdlib.h>
#include <assert.h>
// random hash implementation from the internet
#define rot(x, k) (((x) << (k)) | ((x) >> (32 - (k))))
#define mix(a, b, c) \
{ \
@multun
multun / workspace.sh
Last active April 20, 2020 21:35
A shell workspace management library
## A workspace manager
: ${WS_CONFIG_DIR:=~/.config/ws}
ws_l () {
for ws_file in "${WS_CONFIG_DIR}"/*.ws; do
local ws_name="$(basename "$ws_file")"
ws_name="${ws_name%.ws}"
printf "%-10s\t%s\n" "$ws_name" "$(cat "${ws_file}")"
done
@multun
multun / shell.md
Last active January 11, 2020 08:55
implémenter un shell, douilles et architecture

Le document a été migré ici

@multun
multun / malloc.md
Last active October 18, 2019 23:30
malloc.md

Introduction

Il y a beaucoup, mais alors beaucoup de manières d'implémenter un allocateur mémoire. Trop pour les lister ici sans y passer vraiment beaucoup de temps. Ainsi, seuls les aspects généraux seront évoqués.

Debug son malloc

Si vous lisez ce message, c'est que votre malloc ne marche pas. Terrible, non ? Que faire !

Généralités

@multun
multun / message_json_parser.py
Created December 26, 2018 22:51
Pretty-print a facebook message.json, fixing up broken encoding
import sys
import json
from datetime import datetime
def fixup_str(text):
return text.encode('latin1').decode('utf8')
def fixup_list(l):
@multun
multun / gist:ff5f938080caa8c13d650cae6f87cb5f
Created June 1, 2019 19:17
Iptables filter non-root traffic
*nat
:PREROUTING ACCEPT [0:0]
:INPUT ACCEPT [0:0]
:OUTPUT ACCEPT [0:0]
:POSTROUTING ACCEPT [0:0]
COMMIT
*filter
:INPUT ACCEPT [0:0]
:FORWARD ACCEPT [0:0]
:OUTPUT ACCEPT [0:0]
@multun
multun / emacs-base.el
Created September 9, 2019 19:00
emacs-base.el
(setq c-default-style "bsd"
c-basic-offset 4)
(setq-default indent-tabs-mode nil)
(require 'whitespace)
(setq require-final-newline t)
(setq whitespace-style '(face empty tabs trailing lines-tail))
(global-whitespace-mode t)