Skip to content

Instantly share code, notes, and snippets.

View michaeldperez's full-sized avatar

Michael Pérez michaeldperez

View GitHub Profile
@michaeldperez
michaeldperez / bits.erl
Created February 26, 2017 20:10
shapes.erl file for Functional Programming in Erlang
-module(bits).
-export([bits/1]).
% Bits with an arity of 1 calls bits/2 with arguments Number and a preset Sum of 0.
bits(Number) ->
bits(Number, 0).
% When Number is 0, all bits have been calculated so return the sum.
% Actually, I'm taking for granted the fact that 0 rem 2 == 0 so really I'm returning Sum + 0.
bits(0, Sum) ->
@michaeldperez
michaeldperez / index.erl
Created March 6, 2017 03:13
Accepts a file path and creates an index.
% Does not properly formate index
% Does not remove duplicates
-module(index).
-export([get_file_contents/1,
show_file_contents/1,
map_to_words/1,
index/1]).
% Used to read a file into a list of lines.
@michaeldperez
michaeldperez / frequency2.erl
Last active April 8, 2017 02:00
Frequency Server for Concurrent Programming in Erlang
-module(frequency2).
-export([start/0,allocate/0,deallocate/1,stop/0]).
-export([init/0]).
%% These are the start functions used to create and
%% initialize the server.
start() ->
register(frequency2,
spawn(frequency2, init, [])).
@michaeldperez
michaeldperez / superv.erl
Created April 16, 2017 01:33
Supervisor module for a frequency server
-module(superv).
-export([start/1, init/1]).
%% Starts the supervisor
%% Server has form {Module, Function, Args}
start(Server) ->
register(?MODULE,
spawn(?MODULE, init, [Server])).
%% Initializes the supervision process
@michaeldperez
michaeldperez / palin.erl
Created August 11, 2017 00:39
Determines if a string is a palindrome
-module(palin).
-export([palindrome_check/1]).
rem_punct(String) ->
lists:filter(fun (Ch) ->
not(lists:member(Ch, "\"\'\t\n "))
end, String).
to_small(String) -> lists:map(fun(Ch) ->
case ($A =< Ch andalso Ch =< $Z) of
@michaeldperez
michaeldperez / mailbox.erl
Created August 16, 2017 03:12
Illustration of how Erlang's mailbox works.
-module(mailbox).
-export([receiver/0, receiver_ordered/0]).
receiver() ->
receive
stop -> io:format("Stopped.~n");
Msg -> io:format("Message received: ~s~n", [Msg]),
receiver()
end.
@michaeldperez
michaeldperez / frequency2.erl
Created August 22, 2017 04:07
frequency server
-module(frequency2).
-export([start/0,allocate/0,deallocate/1,stop/0]).
-export([init/0]).
start() ->
register(frequency2,
spawn(frequency2, init, [])).
init() ->
Frequencies = {get_frequencies(), []},

Keybase proof

I hereby claim:

  • I am michaeldperez on github.
  • I am michaeldperez (https://keybase.io/michaeldperez) on keybase.
  • I have a public key ASCjwJ42XS4MOxgvFEoiAFgTAFq5RKJVHOjPN257-sP95Qo

To claim this, I am signing this object: