Skip to content

Instantly share code, notes, and snippets.

View eskil's full-sized avatar

Eskil Heyn Olsen eskil

View GitHub Profile
@eskil
eskil / gist:29cf9783fa8c116bf1f96488f3447376
Created November 21, 2025 15:54
git recent alias that shows recent branch activity, uses fzf to switch
[alias]
recent = "!f(){ refbranch=${1:-origin/master}; count=${2:-20}; rawlist=$(git for-each-ref --sort=-committerdate --format='%(refname:short)|%(HEAD)%(color:yellow)%(refname:short)|%(color:bold green)%(committerdate:relative)|%(color:blue)%(subject)|%(color:magenta)%(authorname)%(color:reset)' --color=always --count=\"$count\" refs/heads | while IFS='|' read -r branch color_branch date msg author; do clean_branch=$(echo \"$branch\" | tr -d '*'); ahead=$(git rev-list --count \"$refbranch..$clean_branch\" 2>/dev/null || echo 0); behind=$(git rev-list --count \"$clean_branch..$refbranch\" 2>/dev/null || echo 0); printf \"%s|%s|%s|%s|%.70s|%s\n\" \"$ahead\" \"$behind\" \"$color_branch\" \"$date\" \"$msg\" \"$author\"; done); displaylist=$( (printf \"%s\n\" \"$rawlist\" | column -ts'|') ); selected=$(printf \"%b\" \"$displaylist\" | fzf --ansi --with-nth=1.. --delimiter='|' --prompt='Recent Branches › ' --reverse --color='pointer:161,marker:168'); [ -z \"$selected\" ] && exit 0; branch=$(printf \"$selected\"
@eskil
eskil / task_async_stream_supervisor.ex
Created February 17, 2021 22:36
Example of how to do retryable Task.Supervisor.async_stream since it doesn't do retries for you
require Integer
require Logger
defmodule Processor do
def process(state) do
:timer.sleep(1000)
result = :os.system_time(:millisecond)
Logger.info("process(#{state}) -> #{result}")
case Integer.is_even(result) do
true ->
#!/usr/bin/env escript
%% -*- erlang -*-
%%! -smp enable -sname bvi_group
%% escript ./bvi_group.erl
% Magic compiler directive to make reduce/1 be visible in main/1.
-mode(compile).
%% This is a variant of the debt reduce interview question that works
PROGRAM VPMDECO
C===============================================================================
C Varying Permeability Model (VPM) Decompression Program in FORTRAN
C
C Author: Erik C. Baker
C
C "DISTRIBUTE FREELY - CREDIT THE AUTHORS"
C
C This program extends the 1986 VPM algorithm (Yount & Hoffman) to include
C mixed gas, repetitive, and altitude diving. Developments to the algorithm
struct dive_table_grammar : boost::spirit::grammar<dive_table_grammar> {
dive_table_grammar (TablesCollection &t) : tablescollection (t) { }
template<typename Scanner>
struct definition {
definition (const dive_table_grammar &dt)
: si1 (minutes (0)), tablescollection (dt.tablescollection)
{
using namespace boost::spirit;
m_depth_rule
@eskil
eskil / gist:10614c61b9dd5823ed17da316f9cb834
Created May 13, 2016 21:12
.cfg parse in boost spirit
//#define BOOST_SPIRIT_DEBUG
#include <boost/spirit.hpp>
#include <boost/spirit/actor.hpp>
#include <string>
#include <map>
#include <algorithm>
using namespace std;
using namespace boost::spirit;
#include "statemachines.h"
#include <fstream>
//*********************************************************************************************
namespace simple_test {
/*
#define TRY_CLASS_PTR_STATES 0
#define TRY_CLASS_STATES 0
/* -*- mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
//
// (C) Eskil Heyn Olsen 2009
//
#include <iostream>
#include <vector>
#include <utility>
#include <iterator>
#include <sstream>
#include <iostream>
#include <string>
#include <vector>
template<typename InIt, typename Tdelim, typename Tj>
Tj& join (InIt first, InIt last, const Tdelim &d, Tj &j) {
if (first == last)
return j;
InIt next = first;
//#define BOOST_SPIRIT_DEBUG
#include <boost/spirit.hpp>
#include <boost/spirit/actor.hpp>
#include <string>
#include <map>
#include <stdexcept>
#include <algorithm>
using namespace std;
using namespace boost::spirit;