Skip to content

Instantly share code, notes, and snippets.

View alco's full-sized avatar
🇺🇦

Oleksii Sholik alco

🇺🇦
View GitHub Profile
@alco
alco / example.ex
Last active August 29, 2015 14:02
# Numbers
0b0101011
1234 ; 0x1A ; 0xbeef ; 0763
3.14 ; 5.0e21 ; 0.5e-12
100_000_000
# Characters
?a ; ?1 ; ?\n ; ?\s ; ?\c ; ? ; ?,
?\x{12} ; ?\x{abcd}
?\x34 ; ?\xf
@alco
alco / One cast
Last active August 29, 2015 14:02
=ERROR REPORT==== 4-Jun-2014::17:08:31 ===
** Generic server <0.93.0> terminating
** Last message in was {'$gen_cast',{data,<<">end< one\n>end< two\n">>}}
** When Server state == {state,nil,[],{<0.92.0>,#Ref<0.0.0.1449>}}
** Reason for termination ==
** {bad_cast,{data,<<">end< one\n>end< two\n">>}}
marking agent as done
1) test spawn streams (PorcelainTest.SimpleTest)
λ mix test
1) test the truth (TestyTest)
test/testy_test.exs:4
Assertion with == failed
code: 1 + 1 == 3
lhs: 2
rhs: 3
stacktrace:
test/testy_test.exs:5
iex(5)> Ports.open_port "cat", ["1"], "hello"
** (ArgumentError) argument error
:erlang.open_port({:spawn, "cat"}, [:stream, :binary, {:args, ["1"]}, :use_stdio, :stderr_to_stdout, :exit_status])
(elixir) lib/port.ex:10: Port.open/2
port.ex:3: Ports.open_port/
Receive simple
simple eof
sending command
sent command
Receive wrapped
sh: /Users/stdout-wrap: No such file or directory
sh: line 0: exec: /Users/stdout-wrap: cannot execute: No such file or directory
{:wtf, "wrapped", {#Port<0.3129>, {:exit_status, 126}}}
Receive wrapped
wrapped eof
λ cat test.exs
#!/usr/local/bin/elixir
λ od test.exs
0000000 020443 072457 071163 066057 061557 066141 061057 067151
0000020 062457 064554 064570 005162
0000030
@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
iex(3)> """abc
...(3)> bcd"""
...(3)> """
...(3)> """
...(3)> """
...(3)>
# attr.exs
# using module attributes as compile-time constants
defmodule M do
@constant 13
def a, do: @constant
@constant 44
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