Skip to content

Instantly share code, notes, and snippets.

defmodule BankAccount do
def start do
await([])
end
def await(events) do
receive do
{:check_balance, pid} -> divulge_balance(pid, events)
{:deposit, amount} -> events = deposit(amount, events)
{:withdraw, amount} -> events = withdraw(amount, events)
iex(1)> increment = &Map.update!(&1, :count, fn(x) -> x + 1 end)
#Function<6.106461118/1 in :erl_eval.expr/5>
iex(2)> increment = fn(x) -> x[:count] = x[:count] + 1 end
** (ArgumentError) dynamic access cannot be invoked inside match and guard clauses
(elixir) expanding macro: Kernel.access/2
(elixir) iex:2: :elixir_compiler.__FILE__/2
iex(2)>
augroup elixir
au!
au BufNewFile,BufRead *.ex,*.exs noremap <buffer> <leader>t :!mix test %<cr>
au BufNewFile,BufRead *_test.exs noremap <buffer> <leader>t :!mix test %<cr>
augroup END
@knewter
knewter / before
Created May 21, 2014 16:50
elixir regex inspect tests
1) test inspecting (RegexTest)
test/elixir/regex_test.exs:172
Assertion with == failed
code: "~r\"\\d+\\n\"" == inspect(sigil_r(<<"\\d+\\n">>, []))
lhs: "~r\"\\d+\\n\""
rhs: "~r\"\\\\d+\\n\""
stacktrace:
test/elixir/regex_test.exs:173
iex(12)> Hex.API.get_package("decimal")
{200,
%{"created_at" => "2014-04-21T18:22:13Z",
"meta" => %{"contributors" => ["Eric Meadows-Jönsson"],
"description" => "Arbitrary precision decimal arithmetic for Elixir.\n",
"licenses" => ["Apache 2.0"],
"links" => %{"Documentation" => "http://ericmj.github.io/decimal",
"Github" => "https://github.com/ericmj/decimal"}}, "name" => "decimal",
"releases" => [%{"created_at" => "2014-05-01T11:08:46Z",
"updated_at" => "2014-05-01T11:08:46Z",
14:35:49,559 SEVERE [gov.uspto.est.api.services.adapters.EJBExceptionMapper] (http-/127.0.0.1:8080-106) Encountered a ParseException: org.apache.http.ParseException: Invalid content type:
at org.apache.http.entity.ContentType.parse(ContentType.java:233) [httpcore-4.3.jar:4.3]
at org.apache.solr.client.solrj.impl.HttpSolrServer.request(HttpSolrServer.java:443) [solr-solrj-4.7.1.jar:4.7.1 1582953 - sarowe - 2014-03-29 00:43:32]
at org.apache.solr.client.solrj.impl.HttpSolrServer.request(HttpSolrServer.java:199) [solr-solrj-4.7.1.jar:4.7.1 1582953 - sarowe - 2014-03-29 00:43:32]
at org.apache.solr.client.solrj.request.AbstractUpdateRequest.process(AbstractUpdateRequest.java:118) [solr-solrj-4.7.1.jar:4.7.1 1582953 - sarowe - 2014-03-29 00:43:32]
at org.apache.solr.client.solrj.SolrServer.add(SolrServer.java:68) [solr-solrj-4.7.1.jar:4.7.1 1582953 - sarowe - 2014-03-29 00:43:32]
at org.apache.solr.client.solrj.SolrServer.addBeans(SolrServer.java:93) [solr-solrj-4.7
15:07:12,993 SEVERE [gov.uspto.est.api.services.adapters.EJBExceptionMapper] (http-/127.0.0.1:8080-46) Encountered a RemoteSolrException: org.apache.solr.client.solrj.impl.HttpSolrServer$RemoteSolrException: org.apache.solr.search.SyntaxError: Cannot parse 'document_type:()': Encountered " ")" ") "" at line 1, column
15.
Was expecting one of:
<NOT> ...
"+" ...
"-" ...
<BAREOPER> ...
"(" ...
"*" ...
<QUOTED> ...
INFO - 2014-05-22 15:07:07.402; org.apache.solr.core.SolrCore; [us_patent_grant_shard2_replica1] webapp=/solr path=/select params={facet=true&hl.mergeContiguous=true&distrib=false&hl=false&version=2&NOW=1400789227391&shard.url=http://127.0.1.1:8983/solr/us_patent_grant_shard2_replica1/&df=text_html&fl=id,score&f.abs
tract_html.hl.alternateField=abstract_html&facet.field=document_type&fsv=true&f.claims_html.hl.alternateField=claims_html&hl.fragsize=300&hl.requireFieldMatch=false&mm=100%25&sm=xxxsentencexxx&f.invention_title_html.hl.alternateField=invention_title_html&qf=claims_html+id+publication_reference_document_number+inventi
on_title_html+abstract_html+description_html&f.description_html.hl.alternateField=description_html&hl.fl=invention_title_html,abstract_html,description_html,claims_html&hl.fragmentsBuilder=colored&hl.fragListBuilder=simple&wt=javabin&rows=0&defType=brs&hl.highlightMultiTerm=true&pf=claim_text+invention_title+abstract
+description&hl.useFastVectorHighlighter=true&hl.snippets=10&start=
defmodule WordStats do
def letter_frequency words do
words
|> Enum.reduce(%{}, fn(word, map) ->
word
|> String.graphemes
|> Enum.reduce(map, fn(letter, map) ->
Map.update(map, letter, 1, &(&1+1))
end)
end)
:!mix test test/website_pipeline_test.exs
test/website_pipeline_test.exs:1: warning: redefining module WebsitePipeline
test/website_pipeline_test.exs:2: warning: variable 'fun' is unused
** (CompileError) test/website_pipeline_test.exs:4: function 'fun'/1 undefined
(stdlib) lists.erl:1336: :lists.foreach/2
(stdlib) erl_eval.erl:657: :erl_eval.do_apply/6
(stdlib) erl_eval.erl:121: :erl_eval.exprs/5
(elixir) src/elixir.erl:156: :elixir.erl_eval/2
(elixir) src/elixir.erl:149: :elixir.eval_forms/4
(elixir) src/elixir.erl:156: :elixir.erl_eval/2