Skip to content

Instantly share code, notes, and snippets.

@okeuday
okeuday / gist:6614126
Last active December 23, 2015 09:19
cowboy patch for barrel usage from Aug 17 11:40, changes from https://github.com/refuge/cowboy
diff --git a/Makefile b/Makefile
index 79c2b6c..28cb135 100644
--- a/Makefile
+++ b/Makefile
@@ -10,9 +10,9 @@ PLT_APPS = crypto public_key ssl
# Dependencies.
-DEPS = ranch
+DEPS = barrel
%%%------------------------------------------------------------------------
%%% @doc
%%% ==Abstract Code Insertion==
%%% A method to get the abstract code representation directly from the
%%% binary beam module representation.
%%%
%%% Other methods could be used, but they are not as efficient.
%%% A more obvious method is to use "-compile(debug_info).", but
%%% this approach does not work in practice (despite the documentation)
%%% and would cause the generated code to be inefficient if it did work.
@okeuday
okeuday / gist:6832394
Created October 4, 2013 20:42
uuid run
TEST uuid_creation
N == 100000 (10 runs)
erlang:make_ref/0 get: 7161.7 us ( 1.0)
v1 erlang get: 79289.2 us ( 11.1)
v1 os get: 72063.8 us ( 10.1)
v3 get: 78722.5 us ( 11.0)
v3 compat get: 73597.6 us ( 10.3)
v4 crypto strong get: 218098.7 us ( 30.5)
v4 crypto weak get: 219091.8 us ( 30.6)
v4 random bigint get: 197156.6 us ( 27.5)
@okeuday
okeuday / decompile.erl
Created January 21, 2014 20:19
decompile.erl
-module(decompile).
-export([file/1]).
file(ModuleName) when is_atom(ModuleName) ->
case code:which(ModuleName) of
BeamFilePath when is_list(BeamFilePath) ->
file(BeamFilePath);
Error when is_atom(Error) ->
Error
end;
@okeuday
okeuday / gist:5b111960e2904eed244d
Created May 30, 2014 00:43
Why is test1 shorter?
test1(A) ->
if
A =:= true ->
ok;
A =:= false ->
error
end.
test2(A) ->
case A of
true ->
@okeuday
okeuday / abstract_code.erl
Created July 28, 2014 22:03
Getting abstract code in erlang
%%% -*- coding: utf-8; Mode: erlang; tab-width: 4; c-basic-offset: 4; indent-tabs-mode: nil -*-
%%% ex: set softtabstop=4 tabstop=4 shiftwidth=4 expandtab fileencoding=utf-8:
%%%
%%%------------------------------------------------------------------------
%%% @doc
%%% ==Abstract Code Insertion==
%%% A method to get the abstract code representation directly from the
%%% binary beam module representation.
%%%
%%% Other methods could be used, but they are not as efficient.
@okeuday
okeuday / streams.erl
Last active August 29, 2015 14:05
streams module
-module(streams).
-author('[email protected]').
%%
%% Author: Torbjorn Tornkvist
%% http://forum.trapexit.org/viewtopic.php?p=22424#22424
%%
%% Date: 27 Nov 1995
%%
%% Try this:
%%
@okeuday
okeuday / immediate_gc.erl
Created September 23, 2014 05:08
Immediate Garbage Collection in Erlang (as harsh as possible)
%-*-Mode:erlang;coding:utf-8;tab-width:4;c-basic-offset:4;indent-tabs-mode:()-*-
% ex: set ft=erlang fenc=utf-8 sts=4 ts=4 sw=4 et:
%%%
%%%------------------------------------------------------------------------
%%% @doc
%%% ==Enforce immediate garbage collection on a function==
%%% @end
%%%
%%% BSD LICENSE
%%%
@okeuday
okeuday / package.exs
Created October 13, 2014 20:28
hex.pm package file
defmodule ErlangSyslog.Mixfile do
use Mix.Project
def project do
[app: :syslog,
version: "1.0.3",
description: description,
package: package,
deps: deps]
end
...
Path = [_ | _] = os:getenv("TEST_DIR"),
ReleaseConfig = filename:join([Path, "..", "rel", "files", "app.config"]),
{ok, _} = reltool_util:config_load(ReleaseConfig),
...
ok = reltool_util:application_start(?APPLICATION,
[{listen_ip, {127,0,0,1}},
{listen_port, ?PORT}], infinity),
...