Skip to content

Instantly share code, notes, and snippets.

View alco's full-sized avatar
🇺🇦

Oleksii Sholik alco

🇺🇦
View GitHub Profile
bin = "HELLO"
spawn(fn ->
raise ArgumentError, message: "Unsupported or invalid status #{bin}"
end)
iex(1)> bin = "HELLO"
"HELLO"
iex(2)> raise ArgumentError, message: 'Unsupported or invalid status #{bin}'
** (ArgumentError) Unsupported or invalid status HELLO
iex(1)> raise 'foo'
** (ArgumentError) argument error
:erlang.apply('foo', :exception, [[]])
λ iex -S mix
iex(1)> Dbg.trace(self(), :call)
{:ok, [{:matched, :nonode@nohost, 1}]}
iex(2)> Dbg.call(Mix.Task, :stack)
{:ok, [{:matched, :nonode@nohost, 20}, {:saved, 1}]}
iex(3)> args = []
[]
iex(4)> Mix.Task.run("run", ["test/fixtures/help_cmd.exs"|args])
:noop
iex(5)>
iex(1)> OptionParser.parse(["--hello", "world"])
{[hello: "world"], [], []}
iex(2)> OptionParser.parse(["--hello", "world"], switches: [hello: [:string]])
{[hello: "world"], [], []}
iex(3)> OptionParser.parse(["--hello", "world"], switches: [hello: [:string, :optional]])
{[hello: nil], ["world"], []}
iex(4)> OptionParser.parse(["--hello=world"], switches: [hello: [:string, :optional]])
λ iex my.ex
Erlang/OTP 17 [erts-6.0] [source] [64-bit] [smp:8:8] [async-threads:10] [hipe] [kernel-poll:false] [dtrace]
Interactive Elixir (0.13.3-dev) - press Ctrl+C to exit (type h() ENTER for help)
iex(1)> use My
nil
iex(2)> 3&&4
81.0
defmodule Beamie.Store.RiakHTTP do
def put(bucket, key, value) do
IO.puts "storing value #{inspect value} with key #{key} in bucket '#{bucket}'"
put_req(bucket, key, value)
end
def get(bucket, key) do
IO.puts "retrieving value for key #{key} from bucket '#{bucket}'"
get_req(bucket, key)
end
# attr.exs
# using module attributes as compile-time constants
defmodule M do
@constant 13
def a, do: @constant
@constant 44
iex(3)> """abc
...(3)> bcd"""
...(3)> """
...(3)> """
...(3)> """
...(3)>
@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