Skip to content

Instantly share code, notes, and snippets.

View odo's full-sized avatar

Florian Odronitz odo

View GitHub Profile
@odo
odo / limited_buffer.ex
Created April 27, 2017 08:32
An elixir server holding a capped/limited buffer
defmodule LimitedBuffer do
use GenServer
# Client
def start_link(size, name \\ nil) do
GenServer.start_link(__MODULE__, [size, name])
end
def push(server, item) do
@odo
odo / tf_lstm.py
Created March 12, 2017 15:48 — forked from siemanko/tf_lstm.py
Simple implementation of LSTM in Tensorflow in 50 lines (+ 130 lines of data generation and comments)
"""Short and sweet LSTM implementation in Tensorflow.
Motivation:
When Tensorflow was released, adding RNNs was a bit of a hack - it required
building separate graphs for every number of timesteps and was a bit obscure
to use. Since then TF devs added things like `dynamic_rnn`, `scan` and `map_fn`.
Currently the APIs are decent, but all the tutorials that I am aware of are not
making the best use of the new APIs.
Advantages of this implementation:
* Find release at http://pkg.freebsd.org/
* create repo file:
> cat /usr/local/etc/pkg/repos/FreeBSD10Release.conf
FreeBSD10Release: {
url: "pkg+http://pkg.freebsd.org/FreeBSD:10:amd64/release/0",
mirror_type: "srv",
signature_type: "fingerprints",
fingerprints: "/usr/share/keys/pkg",
enabled: yes
@odo
odo / bind_in_pipes.ex
Last active June 1, 2016 15:40
Elixir macro to bind variables inside pipes (experimental)
defmodule BindInPipes do
defmacro bind(state, variable) do
ast = quote do
{:__block__, [], [
{:=, [], [{:var!, [context: Elixir, import: Kernel], [{unquote(variable), [], Elixir}]}, unquote(state)]},
unquote(state)
]}
end
{result, []} = Code.eval_quoted(ast, [], __ENV__)
result

How to use KCachegrind / QCachegrind to visualize Erlang traces

install qcachegrind

brew install qcachegrind

install erlgrind

Trace some Erlang

@odo
odo / ponos_session.erl
Created November 18, 2014 13:10
Example session module for ponos (https://github.com/klarna/ponos).
-module(ponos_session).
-behaviour(gen_server).
-export([start/2, init/1, handle_call/3, handle_cast/2, handle_info/2, terminate/2, code_change/3]).
-record(state, {tasks :: list(), task_state :: any() }).
%% == usage ==
%% 1> ponos_session:start([{print, "Hello"}, {wait, 1000}, {print, "World"}, print_call_count], 0).
%% "Hello"
@odo
odo / gen_server_skeleton.erl
Last active December 19, 2015 21:28
This is a template for a gen_server implementation.
-module(gen_server_skeleton).
-behaviour(gen_server).
-export([start_link/0, init/1, handle_call/3, handle_cast/2, handle_info/2, terminate/2, code_change/3]).
%% Public API
start_link() ->
gen_server:start_link(?MODULE, [], []).
@odo
odo / msg_looper.erl
Created January 30, 2013 10:29
This is a demonstration of a gen_server which receives a message, does not reply but puts it into its own mailbox again so it will reply later. This way the execution is deferred and other pending messages are processed first.
% This is a demonstration of a gen_server
% which receives a message, does not reply but
% puts it into its own mailbox again so it will reply later.
% This way the execution is deferred and other pending messages are processed first.
-module(msg_looper).
-behaviour(gen_server).
%% API
-export([start_link/0, stop/1]).
@odo
odo / dets2lets.erl
Created May 6, 2012 11:39
mock function calls to dets to call lets (https://github.com/norton/lets/)
%% @author Florian Odronitz <fo@twofloats.com>
-module(dets_to_lets).
-export([
init/0,
test/1
]).
-include("lets.hrl").