Skip to content

Instantly share code, notes, and snippets.

@soranoba
soranoba / README.md
Last active September 18, 2019 17:19
How to access array index with bbmustache (v1.8.0). There are no plans to support official this.

This patch is provided with the same license as bbmustache.
If you patch bbmustache, you don't need to worry about the license.

@soranoba
soranoba / get_stacktrace.erl
Created May 4, 2018 06:46
migration OTP21
-ifdef('GET_STACKTRACE_AVAILABLE').
-define(CATCH_MATCH(__R), __R).
-define(GET_STACKTRACE(), erlang:get_stacktrace()).
-else.
-define(CATCH_MATCH(__R), __R:__StackTrace).
-define(GET_STACKTRACE(), __StackTrace).
-endif.
@soranoba
soranoba / aaa_srv.erl
Last active June 19, 2016 07:34
A -> B -> C
-behaviour(gen_server).
init(_) ->
{ok, #state{member = undefined}}.
handle_call(_, _, #state{member = undefined} = State) -> {noreply, State}.
handle_cast({sync, Pids}, State) -> {noreply, #state{member = Pids}}.
@soranoba
soranoba / s.erl
Last active February 26, 2016 17:05
split_iolist
1> c(s).
{ok,s}
2> s:s(1, [<<"abc">>, "def", ["ghi"] | <<"jkl">>]).
{<<"a">>,[<<"bc">>,"def",["ghi"]|<<"jkl">>]}
3> s:s(2, [<<"abc">>, "def", ["ghi"] | <<"jkl">>]).
{<<"ab">>,[<<"c">>,"def",["ghi"]|<<"jkl">>]}
4> s:s(3, [<<"abc">>, "def", ["ghi"] | <<"jkl">>]).
{<<"abc">>,["def",["ghi"]|<<"jkl">>]}
5> s:s(4, [<<"abc">>, "def", ["ghi"] | <<"jkl">>]).
{[<<"abc">>,100],["ef",["ghi"]|<<"jkl">>]}
@soranoba
soranoba / spam_behaviour.erl
Created February 17, 2016 16:42
spam_behaviour
-module(spam_behaviour).
-optional_callbacks([b/0]).
-callback a() -> ok.
-callback b() -> ok.
@soranoba
soranoba / mojombo-bench.erl
Last active August 29, 2015 14:15
mustache bench.erl
-module(bench).
-compile(export_all).
run() ->
lists:sum([begin {T, _} = timer:tc(?MODULE, render, []), T end || _ <- lists:seq(1, 1000)]).
render() ->
Ctx = dict:from_list([{name, "Chris"}, {value, 10000}, {taxed_value, 10000 - (10000 * 0.4)}, {in_ca, true}]),
mustache:render("Hello {{name}} You have just won {{value}} dollars! {{#in_ca}} Well, {{taxed_value}} dollars, after taxes. {{/in_ca}}", Ctx).