Wednesday, July 12, 2017

Continuation parsers and encoders

I finally got around to writing about my hack project of last year. It was an exploration of what can be done with continuation parsers and encoders in order to implement a very fast single-copy asynchronous Thrift implementation.

Continuation parsers and encoders try to decode (read)/encode (write) their data directly from/to a network buffer. When the buffer has been fully read/written, it asks for more network buffers to continue.

For more information see the thrift-stream repository on GitHub.

Tuesday, April 18, 2017

Bash history backup

I like my bash history, and I proudly have this in my .bash_profile:

# Increase bash history size, append instead of overwrite history on exit export HISTSIZE=10000000 export HISTCONTROL=erasedups shopt -s histappend

However, after reading about Historian I realised I have no backup. Instead of installing Historian, I decided to take a simpler approach. Here it is:

#!/bin/bash set -euo pipefail IFS=$'\n\t' # # Makes a daily backup of your .bash_history, keeps the last 2 backups. # BACKUPDIR="${HOME}/.bash_history_backup" mkdir -p "${BACKUPDIR}" cp ${HOME}/.bash_history "${BACKUPDIR}/bash_history_$(date +%Y%m%d)" for h in $(ls -1r "${BACKUPDIR}"/bash_history_* | tail -n +3); do rm $h; done

Put the above contents in a file somewhere, e.g. in ~/bin/bash_history_backup.sh and activate it with:

ln -s ~/bin/bash_history_backup.sh /etc/cron.daily/
or add the following line with the more cumbersome route through crontab -e:
0 0 * * * $HOME/bin/bash_history_backup.sh

Update 2017-04-22: The script actually works now :)

Update 2017-04-23: The script actually actually works now :)