This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Interpret the Ansible log for humans. In particular, we | |
# look for command executions and format their content | |
# | |
# - name: list files | |
# shell: "ls -lrt *e*" | |
# | |
# Might produce | |
# | |
# TASK: [1] *********************************************************** | |
# changed: [localhost] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
defmodule RomanNumeral do | |
@mapping [ | |
{1000, 'M'}, | |
{900, 'CM'}, | |
{500, 'D'}, | |
{400, 'CD'}, | |
{100, 'C'}, | |
{90, 'XC'}, | |
{50, 'L'}, | |
{40, 'XL'}, |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
[elixir/Book] svn commit -m 'prep for 0.15' [Book:158836] | |
Sending Changes.pml | |
Sending Enumeration.pml | |
Sending Introduction.pml | |
Sending Nodes.pml | |
Sending OTP-applications.pml | |
Sending OTP-servers.pml | |
Sending OTP-supervisors.pml | |
Sending Project.pml | |
Sending Protocols.pml |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
defmodule FibAgent do | |
defstruct cache: nil, highest_n: 0 | |
def start_link do | |
initial_cache = Enum.into([ {0, 0}, {1, 1}], HashDict.new) | |
state = %__MODULE__{cache: initial_cache, highest_n: 1} | |
Agent.start_link(fn -> state end, name: __MODULE__) | |
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# | |
# Given a list, return a new list with all occurrences of consecutive | |
# duplicated elements replaced by `{element, count}` | |
# | |
# compress [ 1,2,2,3,4,4,4,5,6,6] | |
# → [1, {2, 2}, 3, {4, 3}, 5, {6, 2}] | |
# | |
# This version uses the head of the result to give the effect of lookahead |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
defmodule Bitmap do | |
defstruct value: 0 | |
end | |
defimpl Access, for: Bitmap do | |
use Bitwise | |
def access(%Bitmap{value: value}, bit) do | |
if (value &&& (1 <<< bit)) == 0, do: 0, else: 1 | |
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
defmodule Bitmap do | |
defstruct value: 0 | |
defimpl Access do | |
use Bitwise | |
def access(%Bitmap{value: value}, bit) do | |
if (value &&& (1 <<< bit)) == 0, do: 0, else: 1 | |
end | |
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
defmodule Reflect do | |
use Application.Behaviour | |
def run do | |
path = :code.lib_dir(:elixir, :ebin) | |
load_modules_in(path) | |
modules = for {name,_} <- :code.all_loaded, | |
Regex.match?(~r/^[A-Z]/, atom_to_binary(name)), | |
do: name |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
defimpl Enumerable, for: Bitmap do | |
import :math, only: [log: 1] | |
def reduce(bitmap, {:cont, acc}, fun) do | |
bit_count = Enum.count(bitmap) | |
_reduce({bitmap, bit_count}, { :cont, acc }, fun) | |
end | |
defp _reduce({_bitmap, -1}, { :cont, acc }, _fun), do: { :done, acc } | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
defmodule Test do | |
def fred, do: 1 | |
end |