Skip to content

Instantly share code, notes, and snippets.

@cloud8421
cloud8421 / README.md
Last active January 4, 2017 14:11
JSON schema based validator with automatic code and docs generation

This module requires the following dependencies:

    [{:ex_doc, "~> 0.14.3", only: :dev},
     {:poison, "~> 3.0"},
     {:ex_json_schema, "~> 0.5.2"}]

Note that ex_doc is optional as you can still use iex-based documentation.

@cloud8421
cloud8421 / rebar.lock
Created September 15, 2016 10:18
Rebar.lock diff
diff --git a/rebar.lock b/rebar.lock
index 1c484c5..ce009d3 100644
--- a/rebar.lock
+++ b/rebar.lock
@@ -3,17 +3,14 @@
{<<"cowboy_swagger">>,{pkg,<<"cowboy_swagger">>,<<"1.1.0">>},1},
{<<"cowlib">>,{pkg,<<"cowlib">>,<<"1.0.2">>},2},
{<<"goldrush">>,{pkg,<<"goldrush">>,<<"0.1.8">>},3},
- {<<"iso8601">>,{pkg,<<"inaka_iso8601">>,<<"1.1.2">>},1},
+ {<<"inaka_iso8601">>,{pkg,<<"inaka_iso8601">>,<<"1.1.2">>},1},
@cloud8421
cloud8421 / ms_test.exs
Created August 10, 2016 14:38
Maps and match specs in elixir
defmodule MsTest do
use ExUnit.Case
doctest Ms
@bob %{name: "Bob", job: "developer"}
@alice %{name: "Alice", job: "musician"}
@john %{name: "John", job: "musician"}
@ada %{name: "Ada", job: "developer"}
@alan %{name: "Alan", job: "developer"}
@table :users

A few considerations in case you need to work on performance even further (you may not even need them, but it's worth knowing).

  • Using the GenServer flow to read data may become a bottleneck (as it happens inside the GenServer process)
  • If you don't care about duplicates, you may set the table as duplicate_bag. This speeds up writes, as it doesn't have to check for dupes.

It may also be interesting to read directly from the table instead of going through the GenServer. That's possible by creating the table as public and named_table, giving it __MODULE__ as name. In addition, as the table would be mostly reads, it can be marked as read_concurrency (which optimizes reads over writes).

ets.new(__MODULE__, [:named_table, :duplicate_bag, :public, :read_concurrency])

@cloud8421
cloud8421 / README.md
Last active September 9, 2015 12:38
Docker shell helpers

This assumes a working copy of in your PATH

@cloud8421
cloud8421 / ideas.md
Last active August 29, 2015 14:19
Elixir libraries/apps ideas

Tcp client pool

A generic tcp client pool. You give it a protocol to use to decode/encode messages and it handles connection management for you, including reconnecting, closing, maintaining connections. The use case is to provide a solid infrastructure to connect to tcp services like memcached, redis, etc.

Web based observer

A deployable observer application that can target a node or self and provides the same information (or better) as the native observer gui

Real time load heatmap

A tool capable of generatic a heatmap of running processes, where color shows the inbox length for each process. Useful to find bottlenecks (can also be part of the web observer).

Pluggable Logger reporting tools

@cloud8421
cloud8421 / count
Created April 22, 2015 13:40
Count query in Ecto
# Given a Message model with a body column
from(m in Message, select: count(m.body)) |> Repo.one
@cloud8421
cloud8421 / query.sql
Created March 5, 2015 10:19
yesql problematic query
SELECT jdoc->'guid', jdoc->'name' FROM api WHERE jdoc -> 'tags' ? 'qui';
@cloud8421
cloud8421 / .psqlrc
Created March 3, 2015 10:06
psqlrc
\set ON_ERROR_ROLLBACK interactive
\set COMP_KEYWORD_CASE upper
\set HISTFILE ~/.psql/history- :DBNAME
\pset pager off
\pset null '(null)'
\x auto
\set VERBOSITY verbose
\set HISTCONTROL ignoredups
\timing
\pset linestyle unicode
@cloud8421
cloud8421 / freyr_reading_queries.erl
Created September 11, 2014 08:32
qlc to filter by hour
-module(freyr_reading_queries).
-export([all/0, by_hour/1, by_device/1]).
-include_lib("stdlib/include/qlc.hrl").
-include("freyr_reading.hrl").
all() ->
#freyr_reading{_='_'}.