Skip to content

Instantly share code, notes, and snippets.

View MonkeyIsNull's full-sized avatar
:shipit:
Collating

Adam Guyot MonkeyIsNull

:shipit:
Collating
View GitHub Profile
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)
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
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]
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
@MonkeyIsNull
MonkeyIsNull / cart.ex
Created June 15, 2015 21:00
Cart Example
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
@MonkeyIsNull
MonkeyIsNull / catstore.ex
Created May 29, 2015 02:51
OTP CatStore
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
@MonkeyIsNull
MonkeyIsNull / catstore.ex
Last active November 4, 2015 02:20
Catstore
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
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])
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"
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"