Skip to content

Instantly share code, notes, and snippets.

View certainty's full-sized avatar
🏠
Working from home

David Krentzlin certainty

🏠
Working from home
View GitHub Profile

Keybase proof

I hereby claim:

  • I am certainty on github.
  • I am certainty (https://keybase.io/certainty) on keybase.
  • I have a public key ASCq6xh_z_pB3CICyCr0iHbpGHRBE2jYfnfAQFTwZg2hGAo

To claim this, I am signing this object:

@certainty
certainty / clng.exs
Last active July 23, 2016 14:10
sign_distribution
defmodule Challenge do
def sign_distribution(numbers) do
numbers
|> Enum.reduce({%{neg: 0, pos: 0, zero: 0}, 0}, &update_frequencies/2)
|> calculate_percentage
end
defp update_frequencies(number, {frequencies, total}) do
{Map.update!(frequencies, sign(number), &(&1 + 1)), total + 1}
end
@certainty
certainty / compare.ex
Last active April 15, 2016 19:35
constant_time_compare
defmodule Compare do
use Bitwise
@type bytes :: [char]
@spec constant_time(bytes, bytes) :: boolean
def constant_time(x, y) when length(x) != length(y), do: false
def constant_time(x, y), do: do_constant_time(x, y, 0)
defp do_constant_time([], _, acc), do: acc == 0
defp do_constant_time([x|xs], [y|ys], acc), do: do_constant_time(xs, ys, bor(acc, bxor(x,y)))
$ mix deps.compile
==> fs (compile)
==> ranch (compile)
==> poolboy (compile)
==> cowlib (compile)
Uncaught error in rebar_core: {'EXIT',
{{badmatch,{error,eexist}},
[{rebar_deps,update_deps_code_path,2,[]},
{rebar_deps,preprocess,2,[]},
{rebar_core,acc_modules,5,[]},
require "proxy"
# get the name of the manager
# let's say it's pacman in our case
pacman = PkgManagerProxy.new("pacman")
pacman.install("tmux")
@certainty
certainty / controller.rb
Created October 1, 2015 07:43
first iteration
def create
if CreateCampaignAccessCodeGroup.(@campaign)
redirect_to campaign_access_code_groups_path, notice: _("Group and codes were successfully created.")
else
render :new
end
end
def cons(a,b)
->(accessor) { accessor.(a,b) }
end
def car(cell)
cell.(->(a,_) { a })
end
def cdr(cell)
cell.(->(_,b) { b })
def leap_year?(year)
year.modulo(400).zero? || year.modulo(4).zero? && !year.modulo(100).zero?
end
def leap_years(range = 1..Float::INFINITY)
range.lazy.select(&method(:leap_year?))
end
# Examples
leap_years.take(20).to_a
@certainty
certainty / tmux.conf
Created September 3, 2015 05:49
tmux.conf
set -g history-limit 1000000
set-option -g status-utf8 on
set-window-option -g automatic-rename off
set-window-option -g monitor-activity on
set-option -g base-index 1
setw -g aggressive-resize on
set-option -g visual-bell off
set -g default-terminal "screen-256color"
set -g status-utf8 on
quickcheck
my-reverse
✔ is reversable
✔ preserves length
✔ works like the builtin
is verifier
✔ (verify "single line" (is "single line"))
✘ handles differences in strings nicely [ID: 1]