Skip to content

Instantly share code, notes, and snippets.

defmodule PersonPrinter do
def say_hello(Person[first_name: first, last_name: "Dudington"]) do
"hey it's my brother, #{first}!"
end
def say_hello(Person[first_name: first]) do
"hello, #{first}"
end
def say_hello(person=Person[last_name: "Dudington"]) do
10-19 15:31:43.541 6001-6001/com.isotope11.rccontroller E/AndroidRuntime﹕ FATAL EXCEPTION: main
java.lang.NoClassDefFoundError: org.jruby.util.JRubyFile
at org.jruby.RubyInstanceConfig.<init>(RubyInstanceConfig.java:84)
at org.jruby.embed.internal.AbstractLocalContextProvider.<init>(AbstractLocalContextProvider.java:42)
at org.jruby.embed.internal.SingletonLocalContextProvider.<init>(SingletonLocalContextProvider.java:88)
at org.jruby.embed.ScriptingContainer.getProviderInstance(ScriptingContainer.java:246)
at org.jruby.embed.ScriptingContainer.<init>(ScriptingContainer.java:226)
at org.jruby.embed.ScriptingContainer.<init>(ScriptingContainer.java:183)
at com.isotope11.rccontroller.MainActivity.setupJRuby(MainActivity.java:136)
at com.isotope11.rccontroller.MainActivity.onCreate(MainActivity.java:34)
$ dialyzer ec_math.erl
Checking whether the PLT /home/jadams/.dialyzer_plt is up-to-date...
dialyzer: Not a regular file: /usr/lib/erlang/lib/erts-5.10.2/ebin/erl_prim_loader.beam
iex(1)> :application.start(:gproc)
:ok
iex(2)> :application.start(:gproc)
{:error, {:already_started, :gproc}}
iex(3)> :gproc.reg({:n, :l, 'foo'}, 'bar')
true
iex(4)> :gproc.get_value({:n, :l, 'foo'})
'bar'
iex(5)> :gproc.get_value({:n, :l, 'foos'})
** (ArgumentError) argument error
iex(2)> :application.start(:gproc)
:ok
iex(3)> :gproc.reg(:foo, :bar)
** (ArgumentError) argument error
src/gproc.erl:922: :gproc.reg(:foo, :bar)
erl_eval.erl:569: :erl_eval.do_apply/6
src/elixir.erl:138: :elixir.eval_forms/3
--(jadams@jibbajabba)-(190/pts/7)-(2229/25-Aug-13)--
--($:~/erlang/chromechat)(master)ruby-2.0.0-p0--
$ git push jadams master
Counting objects: 5, done.
Delta compression using up to 4 threads.
Compressing objects: 100% (3/3), done.
Writing objects: 100% (3/3), 279 bytes, done.
Total 3 (delta 2), reused 0 (delta 0)
-----> Building chromechat ...
remote: WARNING: IPv4 forwarding is disabled.
@knewter
knewter / gist:6328807
Created August 24, 2013 15:39
Elixir anonymous function recursion
calculate_bill = fn
{:item, price} -> price
[h|t] -> calculate_bill.(h) + calculate_bill.(t)
end
calculate_bill.([{:item, 20}, {:item, 10}])
calculate_bill.({:item, 35})
# It should also work with a list of more than two elements:
calculate_bill.([{:item, 20}, {:item, 10}, {:item, 35}])
11> chatserver:join(Pid, "knewter").
** exception exit: {noproc,{gen_server,call,[<0.46.0>,{join,"knewter"}]}}
in function gen_server:call/2 (gen_server.erl, line 180)
Eshell V5.10.2 (abort with ^G)
1> c(chatserver).
chatserver.erl:2: Warning: undefined callback function handle_cast/2 (behaviour 'gen_server')
chatserver.erl:18: Warning: variable 'From' is unused
chatserver.erl:18: Warning: variable 'State' is unused
chatserver.erl:18: Warning: variable 'Username' is unused
chatserver.erl:20: Warning: variable 'From' is unused
chatserver.erl:22: Warning: variable 'From' is unused
chatserver.erl:22: Warning: variable 'S' is unused
chatserver.erl:29: Warning: variable 'State' is unused
--(jadams@aye-seven)-(33/pts/22)-(1747/19-Jun-13)--
--($:~/ruby/celluloid-io)(simultaneous-read-write-debug)jruby-1.7.2@celluloid_io--
$ bundle exec rspec spec/celluloid/io/ssl_socket_spec.rb:84
[Coveralls] Set up the SimpleCov formatter.
[Coveralls] Using SimpleCov's default settings.
/home/jadams/.rvm/gems/jruby-1.7.2@celluloid_io/gems/simplecov-0.7.1/lib/simplecov.rb:34 warning: tracing (e.g. set_trace_func) will not capture all events without --debug flag
Run options: include {:locations=>{"./spec/celluloid/io/ssl_socket_spec.rb"=>[84]}}
Celluloid::IO::SSLSocket
inside Celluloid::IO