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
@MonkeyIsNull
MonkeyIsNull / countries.clj
Created February 26, 2021 15:58
Country Lookup by code
(ns countries.core
(:gen-class))
(def countries {
:AF "Afghanistan",
:AX "Åland Islands",
:AL "Albania",
:DZ "Algeria",
:AS "American Samoa",
:AD "Andorra",
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 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 LlCatStore do
def loop(cats) do
receive do
{:add, cat} ->
IO.puts "adding cat #{cat}"
loop([cat | cats])
{:remove, cat} ->
IO.puts "removing cat #{cat}"
loop(remove_cat(cat, cats))
defmodule Foo do
def sleep(num) do
:timer.sleep(num)
self()
end
end
t = Task.async(fn -> Foo.sleep(15000) end)
IO.inspect Task.await(t, 20000)
defmodule Fr do
def read_file(f) do
File.read!(f)
end
def to_s(num) do
Integer.to_string(num)
end
Enum.reduce(Enum.map([1,2,3,4], fn(x) -> x*2 end), 0, fn(x,acc) -> x + acc end)
def greeter() do
fn
:droid -> IO.puts "Yikes, a droid"
"Han Solo" -> :pilot
%{:name => name, :droid => true} -> name <> "-NG"
{droid, human, stormtrooper} -> IO.puts "#{droid}'s rule!"
any -> :ok
end
end
sum = &(&1 + &2 + &3 + &4)
sum.(4,4,4,4)
defmodule Modfuncs do
def modelx(%{:name => name, :droid => true}) do
name <> "-NG"
end
def modelx(%{:name => name, :droid => false}) do
name
end
end