Skip to content

Instantly share code, notes, and snippets.

@eiri
eiri / gist.erl
Last active August 29, 2015 14:27
Extract rebared escript into zip file
{ok, F} = escript:extract("cfcheck", []).
file:write_file("c.zip", proplists:get_value(archive, F)).
@eiri
eiri / lists.js
Created August 19, 2015 02:09
Cycle a list, emit two elements per one item.
var items = _.chain(this.state.docs)
.slice(0, 10)
.map(function(doc, idx) {
return [
React.createElement(ListDivider, {
key: 'div' + idx,
inset: false
}),
React.createElement(ListItem, {
key: 'item' + idx,
@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}.