Skip to content

Instantly share code, notes, and snippets.

View olsner's full-sized avatar

Simon Brenner olsner

View GitHub Profile
@olsner
olsner / update-cscope.sh
Created October 13, 2018 11:24
Script for finding source files and feeding them to cscope
#!/bin/bash
if command -v gfind &>/dev/null; then
find() {
gfind "$@"
}
fi
(
exts='h\|c\|cc\|cmm\|cpp\|hpp\|inc\|lua\|py\|inl\|java\|m'
@olsner
olsner / tmath.py
Last active October 7, 2018 22:41
Time math in Python
#!/usr/bin/env python
# Usage: tmath [EXPR...]
# All command-line arguments are joined with space before parsing as a single
# expression.
#
# Time math syntax:
# terms are:
# - h:m
# - h:m:s
# - 8h, 8m, 8s for hour, minute and second terms
@olsner
olsner / logcmd
Created July 5, 2018 14:49
Logging wrapper that can be symlinked to replace any executable
#!/bin/sh
# Usage:
# 1. Move the original executable into the logcmd target directory, or move it
# elsewhere out of the way and add a symlink in target directory.
# 2. Replace the original executable with a link to logcmd.
#
# Now all executions should be logged in the logcmd log directory.
#
# The default target and log dirs are /usr/share/logcmd and /var/log/logcmd
# respectively. For user-local installs, the directories are instead called
@olsner
olsner / symname.txt
Created January 15, 2018 21:23
A somewhat long symbol name
Generated from ch4-mceval.scm by https://github.com/olsner/templisp, longest symbol:
_ZN7analyzeI4consI6symbolIJLc112ELc114ELc111ELc103ELc110EEES0_IS0_IS1_IJLc100ELc101ELc102ELc105ELc110ELc101EEES0_IS1_IJLc97ELc112ELc112ELc108ELc121ELc45ELc105ELc110ELc45ELc117ELc110ELc100ELc101ELc114ELc108ELc121ELc105ELc110ELc103ELc45ELc115ELc99ELc104ELc101ELc109ELc101EEES0_IS1_IJLc97ELc112ELc112ELc108ELc121EEE3nilEEES0_IS0_IS3_S0_IS0_IS1_IJLc101ELc118ELc97ELc108EEES0_IS1_IJLc101ELc120ELc112EEES0_IS1_IJLc101ELc110ELc118EEES6_EEES0_IS0_IS1_IJLc99ELc111ELc110ELc100EEES0_IS0_IS0_IS1_IJLc115ELc101ELc108ELc102ELc45ELc101ELc118ELc97ELc108ELc117ELc97ELc116ELc105ELc110ELc103ELc63EEES0_ISB_S6_EESI_ES0_IS0_IS0_IS1_IJLc118ELc97ELc114ELc105ELc97ELc98ELc108ELc101ELc63EEESI_ES0_IS0_IS1_IJLc108ELc111ELc111ELc107ELc117ELc112ELc45ELc118ELc97ELc114ELc105ELc97ELc98ELc108ELc101ELc45ELc118ELc97ELc108ELc117ELc101EEESE_ES6_EES0_IS0_IS0_IS1_IJLc113ELc117ELc111ELc116ELc101ELc100ELc63EEESI_ES0_IS0_IS1_IJLc116ELc101ELc120ELc116ELc45ELc111ELc102ELc45ELc
@olsner
olsner / wilhelm.bash
Last active January 3, 2018 19:36
Fun ways to indicate failure with PROMPT_COMMAND
# Usage: source wilhelm.bash (in bashrc or such)
# Currently relies on PROMPT_COMMAND not otherwise being used by your setup.
__wilhelm_prompt_enable() {
PROMPT_COMMAND=__wilhelm_prompt
}
if [ ! -f "$HOME/.killhelm" ]; then
trap "__wilhelm_prompt_enable" DEBUG
fi
@olsner
olsner / solver.md
Last active February 10, 2023 15:06
Solecistic Versioning

Solecistic Versioning

Some general principles:

  • Guarantees (implied or otherwise) about stability will inevitably be broken, so attempting to stick to something like semantic versioning is just a lie. Acknowledge that you have no intention or ability to ensure compliance with such guidelines, and make this fact obvious (sometimes painfully so) in your versioning scheme.
@olsner
olsner / chat.sed
Created September 15, 2016 20:41
Sketch of a simple chat server in "extended sed"
L1:6666/f {
# first line is the username for each user
1 {
h user
b
}
# regexp interrupts are format "user: message" since we have no other
# message kinds here.
I {
@olsner
olsner / bumpmalloc.cc
Created June 8, 2016 21:02
Simple bump allocator
// g++ -O3 -std=c++11 -g -fPIC -shared -o bumpmalloc.so bumpmalloc.cc
// Then LD_PRELOAD=./bumpmalloc.so.
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <sys/mman.h>
#include <unistd.h>
#include <atomic>
#define _ /*
# C++ified snprintf/printf functions.
#
# Adds "printf++" and "snprintf++" that extends printf with C++ support.
#
# The extended functions accept std::string values directly # without having to
# call string::c_str() manually. The extended snprintf++ also adds the
# ability to write directly into std::strings.
#
# When run through bash, this file compiles and runs its own test suite.
@olsner
olsner / casts.h
Last active March 12, 2018 21:09
any_cast and uniref
#include <stdio.h>
template <typename T, typename U>
T& any_cast(U&& u) {
return *(T*)&u;
}
struct uniref
{
void* ref_;