Skip to content

Instantly share code, notes, and snippets.

Peter Marreck pmarreck

  • formerly desk.com, thredup.com and lifebooker.com. currently a contractor
  • Long Island, NY
  • Sign in to view email
Block or report user

Report or block pmarreck

Hide content and notifications from this user.

Learn more about blocking users

Contact Support about this user’s behavior.

Learn more about reporting abuse

Report abuse
View GitHub Profile
@pmarreck
pmarreck / collaboration_fixation.rb
Created Feb 6, 2014
A discussion about "when is it necessary to test which combinations of collaborators?", in Ruby code.
View collaboration_fixation.rb
require 'test/unit'
def f1(a=0)
1 + a
end
def f2(a=0)
2 + a
end
@pmarreck
pmarreck / gist:e0c9c4e506cb46094b01
Created Aug 8, 2014
Public verification of onename.io bitcoin username.
View gist:e0c9c4e506cb46094b01
Verifying myself: My Bitcoin username is +pmarreck. https://onename.io/pmarreck
@pmarreck
pmarreck / kryptokit_pgp_public_key.txt
Created Aug 18, 2014
My KryptoKit public key (import this to send messages to me via KryptoKit)
View kryptokit_pgp_public_key.txt
-----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
@pmarreck
pmarreck / sparkline.exs
Created Jan 15, 2015
How to unit-test a small Elixir library inline, without any project management cruft (at least in the early stages)
View sparkline.exs
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"
@pmarreck
pmarreck / hash_get.rb
Last active Aug 29, 2015
Deep-index a Ruby hash
View hash_get.rb
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
@pmarreck
pmarreck / mandelbrot.erl
Last active Aug 29, 2015
A better [EDIT: prettier but WAY SLOWER!?!?!] Mandelbrot erlang algorithm for the Computer Language Benchmarks Game site?
View mandelbrot.erl
% 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/
@pmarreck
pmarreck / default_args_fun.exs
Last active Aug 29, 2015
so this compiled. interesting...
View default_args_fun.exs
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
@pmarreck
pmarreck / pooled_concurrency_demo.exs
Last active Aug 29, 2015
Elixir attempt at pooled concurrency demo
View pooled_concurrency_demo.exs
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
@pmarreck
pmarreck / fizzbuzz.exs
Last active Aug 29, 2015
My version of FizzBuzz in Elixir
View fizzbuzz.exs
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)
View better_way_to_do_this.exs
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")
You can’t perform that action at this time.