Skip to content

Instantly share code, notes, and snippets.

View dduugg's full-sized avatar

Douglas Eichelberger dduugg

  • San Francisco, CA
View GitHub Profile
@dduugg
dduugg / keybase.md
Last active September 26, 2021 23:22

Keybase proof

I hereby claim:

  • I am dduugg on github.
  • I am dduugg (https://keybase.io/dduugg) on keybase.
  • I have a public key whose fingerprint is 5591 01CD 013D 85A0 7588 37D1 2A13 5E13 7D22 0ADA

To claim this, I am signing this object:

@dduugg
dduugg / rps.erl
Created May 26, 2020 20:34
Strategies exercises
-module(rps).
-export([const/1, cycle/1, echo/1, enum/1,
hindsight_strat/1, least_freq/1, most_freq/1,
no_repeat/1, play/1, play_two/3, rand/1, rand_strat/1,
rock/1, test/0, tournament/2, val/1]).
%
% play one strategy against another, for N moves.
%
@dduugg
dduugg / hof2.erl
Created May 24, 2020 19:30
Functions as results in practice
-module(hof2).
-export([composition/1, iteration/1, test/0, twice/2]).
composition(Fs) ->
fun (X) -> lists:foldr(fun (F, Y) -> F(Y) end, X, Fs)
end.
composition_test() ->
F = composition([fun (X) -> X * 2 end,
@dduugg
dduugg / hof.erl
Created May 24, 2020 01:19
Higher-order functions in practice
-module(hof).
-export([doubleAll/1, evens/1, product/1, test/0]).
doubleAll(Xs) -> lists:map(fun (X) -> 2 * X end, Xs).
doubleAll_test() ->
[] = doubleAll([]),
[2] = doubleAll([1]),
[0, 6] = doubleAll([0, 3]),
@dduugg
dduugg / billing.erl
Created May 18, 2020 20:21
Programming challenge: Supermarket billing
-module(billing).
% use print_bill/1 for the defualt items/1 list, or supply your
% own using print_bill/2 and the remove_item/1 and
% upate_item/1 APIs
-export([items/0, print_bill/1, print_bill/2,
remove_item/2, test/0, update_item/2]).
items() ->
[{4719, "Fish Fingers", 121}, {5643, "Nappies", 1010},
@dduugg
dduugg / text.erl
Created May 15, 2020 22:54
Functional Programming in Erlang - Programming challenge: Text processing
-module(text).
-export([get_file_contents/1, process/2, process/3,
show_file_contents/1, test/0]).
% Used to read a file into a list of lines.
% Example files available in:
% gettysburg-address.txt (short)
% dickens-christmas.txt (long)
@dduugg
dduugg / morelists.erl
Last active May 24, 2020 22:56
Functional Programming in Erlang: 2.27
-module(morelists).
-export([concat/1, concat_test/0, insertion_sort/1,
join/2, join_test/0, member/2, member_test/0,
merge_sort/1, perms/1, perms_test/0, quicksort/1,
sort_tests/0, test/0]).
join([], Y) -> Y;
join([X | Xs], Y) -> [X | join(Xs, Y)].
@dduugg
dduugg / n-queens-solutions.md
Created December 29, 2014 02:30
N-Queens solutions in MCPL and JavaScript

Solutions to the N-Queens Problem

MCPL implementation, published by Martin Richards:

GET "mcpl.h"

STATIC count, all

FUN try
: ?, =all, ? => count++
@dduugg
dduugg / terminal_output
Created April 5, 2014 23:23
numpy failed to build on 10.9.2
$ HOMEBREW_MAKE_JOBS=1 brew install -v numpy 2>&1
Error: value must be enumerable
Please report this bug:
https://github.com/Homebrew/homebrew/wiki/troubleshooting
/System/Library/Frameworks/Ruby.framework/Versions/1.8/usr/lib/ruby/1.8/set.rb:281:in `|'
/usr/local/Library/Homebrew/options.rb:87:in `|'
/usr/local/Library/Homebrew/formula_installer.rb:320:in `effective_build_options_for'
/usr/local/Library/Homebrew/formula_installer.rb:296:in `expand_dependencies'
/usr/local/Library/Homebrew/dependency.rb:102:in `action'
/usr/local/Library/Homebrew/dependency.rb:100:in `catch'