Skip to content

Instantly share code, notes, and snippets.

View zuiderkwast's full-sized avatar

Viktor Söderqvist zuiderkwast

View GitHub Profile
@zuiderkwast
zuiderkwast / md
Created February 26, 2025 09:29
Read markdown files like man pages in the terminal
# A bash function that can be put in the alias file or in .bashrc
md ()
{
( printf "%s\n" "---" "title: $1" "section: 7" "header: $(ls $PWD/$1)" "date: $(stat --printf=%y $1 | cut -f1 -d' ')" "---";
cat "$1" ) | pandoc -s -f markdown -t man | man -l -
}
@zuiderkwast
zuiderkwast / callgraph.escript
Last active September 30, 2020 16:05
Erlang module callgraph using dot/graphviz
#!/usr/bin/env escript
%% -*- erlang -*-
%% -----------------------------------------------------------------------------
%%
%% Generates a callgraph in graphviz format.
%%
%% Only calls within a single module are visualized. The exported
%% functions are represented by a filled node.
%%
@zuiderkwast
zuiderkwast / erlang_util.erl
Last active December 13, 2018 23:36
Various general purpose functions for lists and such things
-module(erlang_util).
-spec forall_but_last(fun ((A) -> any()), nonempty_list(A)) -> A.
forall_but_last(_Fun, [Last]) -> Last;
forall_but_last(Fun, [X|Xs]) -> Fun(X), forall_but_last(Xs).
%% [Xs, Ys, ...] -> [[X, Y, ...] || X <- Xs, Y <- Ys, ...]
-spec pick_from_each([[]]) -> [[]].
pick_from_each([]) -> [[]];
pick_from_each([Xs|Xss]) ->
@zuiderkwast
zuiderkwast / take_n_bytes.erl
Last active June 27, 2018 20:51
Take N bytes of iodata, avoiding copying (Erlang)
-module(take_n_bytes).
-export([take_n_bytes/2]).
%% @doc Take N bytes, avoiding copying.
-spec take_n_bytes(integer(), iolist()) ->
{Chunk :: iolist(), Rest :: iolist()}.
take_n_bytes(0, Rest) ->
{[], Rest};
take_n_bytes(N, Bin) when is_binary(Bin) ->
@zuiderkwast
zuiderkwast / vasttrafik_cli
Last active April 13, 2018 15:35
vasttrafik_cli
#!/usr/bin/perl
# This script shows bus and ferry departures from two hard-coded locations.
use strict;
use warnings;
use Encode 'encode';
print_stop('Lindholmspiren (Göteborg)');
print "-" x 50, "\n";
@zuiderkwast
zuiderkwast / addtask
Created February 6, 2018 10:11
Add Redmine task to an existing user story
#!/usr/bin/perl
#-------------------------------------------------------
# Add scrum tasks to a user story from the command line
# Viktor Söderqvist, 2017-04-24
#-------------------------------------------------------
use strict;
use warnings;
@zuiderkwast
zuiderkwast / aggregate-coverage
Created February 6, 2018 10:03
Combine multiple Erlang coverage reports in HTML format into one

DESCRIPTION

Aggregate multiple Erlang cover reports in HTML format into one.

Input cover report file names are given as command line arguments. The result is written to stdout.

@zuiderkwast
zuiderkwast / .aliases
Last active February 6, 2018 10:11
Some aliases
# Current git branch
alias b='git branch | grep "^*" | sed "s/^\* *//"'