Skip to content

Instantly share code, notes, and snippets.

# Requires Erlang/OTP 19.0. Invoke as:
#
# iex --erl "-proto_dist Elixir.Epmdless -start_epmd false -epmd_module Elixir.Epmdless_epmd_client" --name frobozz3
# A module containing the function that determines the port number
# based on a node name.
defmodule Epmdless do
def dist_port(name) when is_atom(name) do
dist_port Atom.to_string name
end
@legoscia
legoscia / gist:931322eaa70c8927821c
Created January 8, 2015 15:25
dolist-with-progress-reporter
(defmacro my-dolist-with-progress-reporter (spec message &rest body)
(declare (indent 2) (debug ((symbolp form &optional form) form body)))
(let ((list-var (make-symbol "list"))
(length-var (make-symbol "length"))
(counter-var (make-symbol "counter"))
(progress-var (make-symbol "progress")))
`(let* ((,list-var ,(nth 1 spec))
(,length-var (length ,list-var))
(,counter-var 0)
(,progress-var (make-progress-reporter ,message 0 ,length-var)))
@legoscia
legoscia / slugs.erl
Last active August 29, 2015 14:03 — forked from devinus/gist:450612
A Transliterating Erlang URL Slugifier (supports Unicode / UTF-8 input)
-module(slugs).
-export([slugify/1]).
-define(tolower(C), (C+32)).
-define(islower(C), (C >= $a andalso C =< $z)).
-define(isupper(C), (C >= $A andalso C =< $Z)).
-define(isdigit(C), (C >= $1 andalso C =< $9)).
-define(isspace(C), (
C =:= $\s orelse C =:= $\n orelse C =:= $\t orelse C =:= $\r
@legoscia
legoscia / filewrite.erl
Created June 20, 2014 15:41
Test file:write/2 runtime with varying message queue size
%%% This module tests the impact of message queue size on the runtime
%%% of file:write/2.
%%%
%%% The idea is that something somewhere needs more references in a
%%% selective receive (OTP-8623, introduced in R14A).
-module(filewrite).
-export([testit/1, testit_raw/1, testit/2]).
#!/usr/bin/env escript
-mode(compile).
epoch() ->
{Mega,Sec,Mili} = os:timestamp(),
(Mega * 1000000) + Sec + (Mili / 1000000).
measure(F) ->
Ini = epoch(),
@legoscia
legoscia / reltool.config
Last active December 11, 2015 05:58
reltool doesn't like non-numeric version numbers in directory names
%% -*- erlang -*-
{sys,
[
{lib_dirs, ["../apps"]},
{rel, "bar_rel", "1", [foo_app]},
{rel, "start_clean", "1", [kernel, stdlib]}]}.
@legoscia
legoscia / efind.sh
Created December 12, 2012 14:54 — forked from robertoaloi/efind.sh
#!/bin/sh
ROOTDIR=`which erl | sed -ne '/^ROOTDIR=/s///p'`
find $ROOTDIR -name $1.erl | awk -F / '{print $(NF-2)}'
@legoscia
legoscia / config
Created June 26, 2012 17:33
Use per-user (as opposed to per-project) rebar plugins in ~/.rebar/
%% -*- erlang -*-
%% As an example, let's make the dialyzer plugin available regardless of
%% whether the project in question uses it:
{plugins, [rebar_dialyzer_plugin]}.
%% config.script uses this new variable to find it:
{plugin_home, ["/Users/magnus/.rebar"]}.