Skip to content

Instantly share code, notes, and snippets.

View emaphis's full-sized avatar

Ed Maphis emaphis

  • Painesville, Ohio
View GitHub Profile
@emaphis
emaphis / frequency1.erl
Created August 11, 2017 21:03
Frequency server - concurrent programming in Erlang 1.13.
%%% @doc frequency server step one
%%% allocate limited frequencies to mobile phone users.
%%% Server version 0
%%% Module 1.13 - modifying the frequency server.
-module(frequency1).
-export([start/0, init/0]).
%% to start.....
%% Freq = spawn(frequency, init, []).
@emaphis
emaphis / mailbox.erl
Last active August 10, 2017 06:07
Erlang mailbox practice
%%% @doc mailbox processing.
-module(mailbox).
-export([tester/1, receiver1/0, receiver2/0, tester2/1, receiver3/0]).
%%% @doc a function to test receiver processes, send 4 messages
%%% in quick succession.
tester(Pid) ->
Pid ! one,
Pid ! two,
@emaphis
emaphis / palin.erl
Last active August 10, 2017 00:30
Erlang Palindrome Server
%%% @doc Palindrome server
%%% Part1 of exercise
-module(palin).
-export([server/1]).
%% @doc the palindrome server.
server(From) ->
receive
{check, Str} ->
case palindrome_check(Str) of
@emaphis
emaphis / rps2.erl
Created March 13, 2017 22:31
Rock/Paper/Sicsors strategies
-module(rps2).
-export([play/1,echo/1,play_two/3,val/1,tournament/2]).
%% strategies
-export([rock/1, no_repeat/1, const/1, paper/1, rand/1, scissors/1, random_choice/1]).
-include_lib("eunit/include/eunit.hrl").
%% data specs
@emaphis
emaphis / rps2.erl
Created March 13, 2017 22:29
Rock/Paper/Scissors strategies.
-module(rps2).
-export([play/1,echo/1,play_two/3,val/1,tournament/2]).
%% strategies
-export([rock/1, no_repeat/1, const/1, paper/1, rand/1, scissors/1, random_choice/1]).
-include_lib("eunit/include/eunit.hrl").
%% data specs
@emaphis
emaphis / partial.erl
Created March 9, 2017 22:55
Functions as return values - 3.11 - Fuctional Programming in Erlang
%% Funtions as results homework - 3.11
-module(partial).
-export([comp/2,
comp_all_r/1, comp_all/1,
twice/1, quad/1,
iteration/2]).
-include_lib("eunit/include/eunit.hrl").
@emaphis
emaphis / rps.erl
Created March 8, 2017 14:12
Modeling a rock paper scissors tournament -- 3.8
%% Modeling a rock paper scissors tournament -- 3.8
-module(rps).
-export([beat/1, lose/1, result/2, score/1, tournament/2]).
-include_lib("eunit/include/eunit.hrl").
-type rps() :: rock | paper | scissors | error.
-type result() :: win | lose | draw.
@emaphis
emaphis / practice.erl
Created March 8, 2017 03:54
Higher-order function practice -- 3.5 - Functional programming with Erlang
%% higher-order function practice -- 3.5
-module(practice).
-export([doubleAll/1, evens/1, product/1, zip/2]).
-export([doubleAll_h/1, evens_h/1, product_h/1]).
-export([zip_with/3, zip_with2/3, zip2/2]).
-include_lib("eunit/include/eunit.hrl").
@emaphis
emaphis / market.erl
Created March 7, 2017 16:33
Erlang bill printing program - Fuctional Programming in Erlang -- 2.25
%% market project - 2.25
-module(market).
-include_lib("eunit/include/eunit.hrl").
-export([return_db/0, return_sales/0, find_product/2, sales_list/2,
count_sherries/1, print_bill/1, run/0]).
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%% To run the demo:
@emaphis
emaphis / index.erl
Created March 5, 2017 01:58
Functional programming in Erlang -- index program.
-module(index).
-export([get_file_contents/1,show_file_contents/1]).
-export([index_file/1,print_index/1]).
-export([partition_test/0]).
%% The main prorgram.
%% Run:
%% index:index_file("gettysburg-address.txt").
%% to produce a list of word indexes.