Skip to content

Instantly share code, notes, and snippets.

View alco's full-sized avatar
🇺🇦

Oleksii Sholik alco

🇺🇦
View GitHub Profile
@alco
alco / gist:7785628
Last active December 30, 2015 05:49 — forked from Andy-Richards/gist:7785272
defmodule A do
defmacro __before_compile__(_env) do
funs = Enum.map([:a, :b], fn(name) ->
quote do
def unquote(name)(), do: unquote(name)
end
end)
quote do
unquote_splicing(funs)
@alco
alco / bag.ex
Last active August 29, 2015 14:01 — forked from knewter/word_stats_test.exs
defmodule Bag do
defstruct store: %{}
def new do
%Bag{}
end
def put(%Bag{store: store}, thing) do
%Bag{store: Map.update(store, thing, 1, &( &1 + 1))}
end
@alco
alco / exercise.exs
Last active August 29, 2015 14:02 — forked from josevalim/exercise.exs
@proto_version "1.0"
def process_options(opts) do
ret = Enum.reduce(opts, [], fn
{:in, _}, ret -> ["-in"|ret]
{:err, :out}, ret -> ["-err", "out"|ret]
{:err, :err}, ret -> ["-err", "err"|ret]
{:dir, dir}, ret -> ["-dir", dir|ret]
_ -> ret
end)
defmodule Chat.Client do
def join(server) do
client_send server, :join
end
def say(server, message) do
client_send server, { :say, message }
end
def leave(server) do
<!DOCTYPE html>
<html>
<head>
<style type="text/css">
@import url("http://github.com/simplegeo/polymaps/raw/v2.4.0/examples/example.css");
html, body {height: 100%;}
svg {display: block;}
.layer circle {fill: #f00;stroke: #000;stroke-width: 2px;}
</style>