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 Rdd do | |
def top() do | |
threads = Reddhl.pull("elixir") | |
{ Reddhl.url(threads, 1), Reddhl.title(threads, 1) } | |
end | |
def top_five do | |
threads = Reddhl.pull("elixir") | |
Enum.map(0..4, fn(x) -> { Reddhl.url(threads, x), Reddhl.title(threads, x) } 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 Dt do | |
# Create a list with six star wars characters | |
swc = ["c3po", "r2d2", "bb8", "han", "luke", "leia"] | |
# Get the third item out of the list | |
IO.puts "3rd => " <> Enum.at(swc,2) | |
# Create another list with three characters | |
bad_guys = [:boba_fett, :vader, {:jabba, :hutt}] | |
# Create a third list that contains both previous lists |
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
File.read!("/etc/passwd") |> | |
String.split("\n") |> | |
Enum.map(&(String.split(&1, ":"))) |> | |
Enum.map(&(Enum.at(&1,3))) |> | |
Enum.filter(&(!is_nil(&1))) |> | |
Enum.map(&(String.to_integer(&1))) |> | |
Enum.sort(&(&1 > &2)) |> | |
Enum.take(5) | |
[239, 238, 237, 236, 235] |
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
A software development process that relies on the repetition | |
of a very short development cycle: first the developer writes | |
an (initially failing) automated test case that defines a | |
desired improvement or new function, then produces the minimum | |
amount of code to pass that test, and finally refactors the new | |
code to acceptable standards |
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 Cart do | |
def start() do | |
{:ok, cart} = Agent.start(fn -> ["Seconds - by Bryan Lee O'Malley"] end) | |
cart | |
end | |
def print_cart(items) do | |
Enum.each(items, fn item -> IO.puts "Item: #{item}" 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 Catstore.Server do | |
use GenServer | |
## really simple API | |
def new_store(cats) do | |
{:ok, store} = GenServer.start_link(Catstore.Server, cats) | |
store | |
end | |
def add(store, cat) do |
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 Catstore do | |
def start() do | |
{:ok, store} = Agent.start(fn -> ["Biggles"] end) | |
store | |
end | |
def pr_cats(cats) do | |
Enum.each(cats, fn cat -> IO.puts cat 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 Taskrun do | |
def run(num) do | |
IO.puts "running sleep task: #{num}" | |
:timer.sleep(num) | |
num | |
end | |
def launch(num) do | |
Task.async(Taskrun, :run, [num]) |
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 FileripperTest do | |
use ExUnit.Case, async: true | |
@test_files_path "fixtures/test" | |
setup do | |
File.mkdir_p(@test_files_path) | |
on_exit fn -> | |
IO.puts "End of test case" |
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 FileripperTest do | |
use ExUnit.Case, async: true | |
@test_files_path "fixtures/test" | |
setup_all do | |
File.mkdir_p(@test_files_path) | |
on_exit fn -> | |
IO.puts "At the very end" |