See how a minor change to your commit message style can make you a better programmer.
Format: <type>(<scope>): <subject>
<scope>
is optional
%% @doc A binary tree implementation in Erlang. | |
%% A binary tree stores keys and values. | |
-module(binary_tree). | |
-export([init/0, init/1, insert/3, lookup/2]). | |
-define(EMPTY_NODE, {node, 'empty'}). | |
%% @doc Initialize an empty binary tree node. | |
%% This is how the root of the tree should be established. | |
%% |
-module(rbtree). | |
-export([insert/3, find/2]). | |
% Node structure: { Key, Value, Color, Smaller, Bigger } | |
find(_, nil) -> | |
not_found; | |
find(Key, { Key, Value, _, _, _ }) -> | |
{ found, { Key, Value } }; |
defmodule EmailValidator do | |
# ensure that the email looks valid | |
def validate_email(email) when is_binary(email) do | |
case Regex.run(~r/^[A-Za-z0-9._%+-]+@[A-Za-z0-9.-]+\.[A-Za-z]{2,4}$/, email) do | |
nil -> | |
{:error, "Invalid email"} | |
[email] -> | |
try do | |
Regex.run(~r/(\w+)@([\w.]+)/, email) |> validate_email |
# You will need fswatch installed (available in homebrew and friends) | |
# The command below will run tests and wait until fswatch writes something. | |
# The --stale flag will only run stale entries, it requires Elixir v1.3. | |
# fswatch lib/ test/ | mix test --stale --listen-on-stdin | |
fswatch -0 --latency=0.01 --one-per-batch lib test | mix test --stale test/ |
L1 cache reference ......................... 0.5 ns
Branch mispredict ............................ 5 ns
L2 cache reference ........................... 7 ns
Mutex lock/unlock ........................... 25 ns
Main memory reference ...................... 100 ns
Compress 1K bytes with Zippy ............. 3,000 ns = 3 µs
Send 2K bytes over 1 Gbps network ....... 20,000 ns = 20 µs
SSD random read ........................ 150,000 ns = 150 µs
Read 1 MB sequentially from memory ..... 250,000 ns = 250 µs
(by @andrestaltz)
If you prefer to watch video tutorials with live-coding, then check out this series I recorded with the same contents as in this article: Egghead.io - Introduction to Reactive Programming.