Skip to content

Instantly share code, notes, and snippets.

@eiri
eiri / runme.py
Created July 26, 2015 19:29
Generic python script skeleton
#!/usr/bin/env python
# coding: utf-8
"""
Generic python script skeleton
"""
import sys, os, argparse, logging, ConfigParser
def parse_args():
@eiri
eiri / list and binary convention funs in R14B01 and R17.5.6.ipynb
Created July 7, 2015 13:18
list and binary convention funs in R14B01 and R17.5.6
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
@eiri
eiri / Effect of variable compressor on database size in CouchDB.ipynb
Last active August 29, 2015 14:23
Effect of variable compressor on database size in CouchDB
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
@eiri
eiri / proc_tree.escript
Created March 3, 2015 16:44
Walks erlang VM's process tree and prints PlantUML diagram of it on a standard output
#!/usr/bin/env escript
%% -*- erlang -*-
%%! -hidden -setcookie cookie
-mode(compile).
main(["-?"]) ->
usage();
main(Args) ->
case get_pid(Args) of
@eiri
eiri / gist:4afe8a98966f06a576b1
Created June 26, 2014 02:16
Erlang's binary:join/1
join([], _) -> []; %% or should it be <<"">> for a consistency sake?
join([H|[]], _) -> H;
join(List, Sep) when is_list(Sep) ->
join(List, list_to_binary(Sep));
join([H|T], Sep) ->
join(T, H, Sep).
join([], Acc, _) ->
Acc;
join([H|T], Acc, Sep) ->
@eiri
eiri / gist:9914ff58108e427b303e
Last active August 29, 2015 14:02
uuid v4 in erlang
uuid() ->
<<A:32, B:16, C:16, D:16, E:48>> = crypto:rand_bytes(16),
Fmt = "~8.16.0b-~4.16.0b-4~3.16.0b-~4.16.0b-~12.16.0b",
Str = io_lib:format(Fmt, [A, B, C band 16#0fff, D band 16#3fff bor 16#8000, E]),
list_to_binary(Str).
@eiri
eiri / gist:74f7c9a107d7eb858df7
Created June 10, 2014 00:26
erlang:now() to unix timestamp and back
now_to_timestamp() ->
now_to_timestamp(erlang:now()).
now_to_timestamp({Mega, Sec, _}) ->
Mega * 1000000 + Sec.
timestamp_to_now(TS) ->
{TS div 1000000, TS rem 1000000, 0}.
@eiri
eiri / gist:8552138
Last active January 4, 2016 01:59
Lager part in erlang's app.config for colored console output with info on module and line of logged message
[{lager, [
{handlers, [
{lager_console_backend, [
debug,
{lager_default_formatter, [time, " ", {module,
[module, {line, [":", line], ""}], ""}, " ", color, message, {eol, "\e[0m\r\n"}]}
]},
{lager_file_backend,
[{file, "logs/console.log"}, {level, info}, {size, 10485760}, {date, "$D0"}, {count, 1}]},
{lager_file_backend,
@eiri
eiri / README.md
Last active December 29, 2015 09:58
Random timelines with a bit a shadow.

Random timelines with a bit a shadow.