This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
require 'test/unit' | |
def f1(a=0) | |
1 + a | |
end | |
def f2(a=0) | |
2 + a | |
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Verifying myself: My Bitcoin username is +pmarreck. https://onename.io/pmarreck |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
-----BEGIN PGP PUBLIC KEY BLOCK----- | |
Version: KryptoKit v0.24 | |
Comment: http://kryptokit.com | |
xsBNBFN8xLMBCACQtRCK6AWhR9mGpoHUXJi8/gK/asXPQ1H2fbTFdBjPpJFE | |
RrlYO44jgfM8HoUxYVHiRwy4K3d08DigqrHlPdrGB3jdLcUFtDDrjyjBOlhM | |
UkPGMnw3JRC1CyAXIFw7RC9s8t4guXW/Iz6O8s/7JkGFNMliH/4OstDo3TB1 | |
jNlo9yAOkdFX9wSHBXyPDnp9zxk2UqJzvs66MAorvv8+8NRboCXNQbJ8nJaN | |
AUsSX0bmwpB1XvMhAOdbZiSc8bMOU4CBZS69itgtedMF5OjckI2EoX6S7xhg | |
0gBikvW8InCOJ3xyeTZTMOkOA5K4/ssbUrwAjlbUiWYo2c4nZMuiCbLjABEB |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
defmodule Sparkline do | |
def draw(str) do | |
values = str |> String.split(~r/[, ]+/) | |
|> Enum.map(&(elem(Float.parse(&1), 0))) | |
{min, max} = {Enum.min(values), Enum.max(values)} | |
Enum.map(values, &(round((&1 - min) / (max - min) * 7 + 0x2581))) | |
end | |
end | |
# run this inline suite with "elixir #{__ENV__.file} test" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class Hash | |
def get(*keys) | |
keys.inject(self){|h, k| h[k] if h} | |
end | |
end | |
h = {:a=>{:b=>{:c=>"d"}}} | |
puts h.get(:a).inspect | |
puts h.get(:a, :b).inspect | |
puts h.get(:a, :b, :c).inspect |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
% I found the following code in the benchmark game here: | |
% http://benchmarksgame.alioth.debian.org/u64q/program.php?test=mandelbrot&lang=hipe#sourcecode | |
% As you can see where the algorithm is defined below, I replaced it with a more functional, | |
% tail-call-optimized (I think?), pattern-matching guard-clause-using version. | |
% It's very pretty. | |
% The problem is it's THIRTY PERCENT SLOWER! WHY?? | |
% Thanks to @radioxid on irc.freenode.net/#erlang for getting me to actually benchmark the change. | |
% The Computer Language Benchmarks Game | |
% http://benchmarksgame.alioth.debian.org/ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def concurrent_factorial(n) when is_integer(n) and n > 0 do | |
concurrent_factorial(1..n) | |
end | |
def concurrent_factorial(range, worker_pool_by_nodenames \\ worker_pool_by_nodenames) | |
def concurrent_factorial(%Range{first: start, last: finish}, worker_pool_by_nodenames) do | |
pmap(split_range_of_numbers(start..finish), fn(range) -> range |> Enum.reduce(&(&1*&2)) end, worker_pool_by_nodenames) |> | |
# one more reduction... | |
Enum.reduce(&(&1*&2)) | |
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
defmodule ConcurrencyDemo do | |
def num_procs(erlang \\ :erlang) do | |
erlang.system_info(:logical_processors) | |
end | |
def query_node(nodename, func, node \\ Node) do | |
me = self | |
pid = node.spawn(nodename, fn -> (send me, { self, func.() }) end) | |
receive do {^pid, result} -> result end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
defmodule FizzBuzz do | |
def fizzbuzz(n) when is_integer(n), do: fizzbuzz(n, {rem(n,3), rem(n,5)}) | |
def fizzbuzz(_, {0,0}), do: :fizzbuzz | |
def fizzbuzz(_, {0,_}), do: :fizz | |
def fizzbuzz(_, {_,0}), do: :buzz | |
def fizzbuzz(n, {_,_}), do: n | |
def run(i \\ 100), do: (1..i) |> Enum.map(&fizzbuzz/1) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
test "single digits" do | |
%{zero: 0, one: 1, two: 2, three: 3, four: 4, five: 5, six: 6, seven: 7, eight: 8, nine: 9} | |
|> | |
Enum.each(fn {word, num} -> | |
IO.puts "asserting #{word} == #{num}" | |
assert to_string(word) == NumbersToWords.parse(num) | |
end) | |
end | |
# I keep getting an argument error as it ends up trying to do :erlang.integer_to_binary("8") |
OlderNewer