Skip to content

Instantly share code, notes, and snippets.

-module(mailbox).
-export([start_receiver/0, start_receiver_stop/0, start_selective_receiver/0, receiver/0, receiver_stop/0, selective_receiver/0]).
start_receiver() ->
spawn(?MODULE, receiver, []).
start_receiver_stop() ->
spawn(?MODULE, receiver_stop, []).
start_selective_receiver() ->
-module(palindrome_server).
-export([start_server/0,
start_servers/1,
start_balancer/1,
stop_server/1,
stop_servers/1,
stop_balancer/1,
check/2,
balancer/1,
server/0,
-module(rps).
-export([play/1,
echo/1,
play_two/3,
rock/1,
no_repeat/1,
least_freq/1,
most_freq/1,
const/1,
-module(hof2).
-export([add/1, times/1, compose/2, list_compose/1, twice/1, iterate/1]).
add(X) ->
fun(Y) -> X+Y end.
times(X) ->
fun(Y) ->
X*Y end.
-module(hof).
-export([doubleAll/1, evens/1, product/1, zip/2, zip_with/3, zip_with_hof/3, zip_hof/2]).
doubleAll(L) ->
lists:map(fun(X) -> 2*X end, L).
evens(L) ->
lists:filter(fun(X) -> X rem 2 == 0 end, L).
-module(supermarket).
-export([test_database/0, find_item/2, update_item/2, remove_item/2, shop/2, shop/3, bill/3]).
-type database() :: [entry()].
-type entry() :: {barcode(), item(), price()}.
-type barcode() :: integer().
-type item() :: string().
-type price() :: integer().
-type bill() :: [{string(), integer()}].
The heat bloomed in December
as the carnival season
kicked into gear.
Nearly helpless with sun and glare, I avoided Rio's brilliant
sidewalks
and glittering beaches,
panting in dark corners
and waiting out the inverted southern summer.
-module(index).
-export([get_file_contents/1,show_file_contents/1, to_index_list/1, strip/1, nopunc/1]).
% Used to read a file into a list of lines.
% Example files available in:
% gettysburg-address.txt (short)
% dickens-christmas.txt (long)
% Get the contents of a text file into a list of lines.
-module(list4).
-export([join/2, concat/1, member/2, mergesort/1, quicksort/1, insertsort/1, perms/1]).
join(X, Y) -> lists:reverse(lists:reverse(X), Y).
concat([]) -> [];
concat([X|Xs]) -> join(X, concat(Xs)).
member(_, []) -> false;
-module(list3).
-export([take/2, nub/1, palindrome/1]).
-spec take(integer(), [T]) -> [T].
take(0, _) ->
[];
take(_, []) ->
[];
take(N, [X|Xs]) when N > 0 ->