Skip to content

Instantly share code, notes, and snippets.

@andreburgaud
andreburgaud / node.js
Last active November 18, 2019 15:32
Bash and JS script allowing to start Node with defined options (i.e. harmony) and custom command and properties.
#!/usr/bin/env node.sh
// Published under the MIT License - https://opensource.org/licenses/MIT
// Installation:
// 1 - Copy both node.sh and node.js in a directory included in your system PATH
// 2 - Ensure that both scripts are executable (chmod +x node.js node.sh)
// Usage:
// 1 - Invoke node.js in a terminal to start the shell
// 2 - Type .help to list the REPL commands available
@andreburgaud
andreburgaud / watch_aqueduct.sh
Created April 8, 2018 04:17
Shell script to watch and reload Aqueduct https://aqueduct.io/ on MacOS (requires fswatch https://github.com/emcrisostomo/fswatch).
#! /bin/sh
# MIT License (https://opensource.org/licenses/MIT)
# Script to watch and reload Aqueduct (https://aqueduct.io/) on Mac OS.
# Requires fswatch (https://github.com/emcrisostomo/fswatch): brew install fswatch
# The server will automatically reload upon modification of dart files in lib directory
# To start development server: execute this script in an Aqueduct project folder.
# To quit: type CTRL+C in the terminal used to run the script.
@andreburgaud
andreburgaud / hh.erl
Created July 4, 2017 02:57
FutureLearn - Functional Programming in Erlang 3.5 - Higher-order functions in practice
-module(hh).
-export([
doubleAll/1,doubleAllHH/1,
evens/1,evensHH/1,
product/1,productHH/1,
zip/2,zipT/2,zipHH/2,
zip_with/3,zip_withHH/3
]).
-include_lib("eunit/include/eunit.hrl").
@andreburgaud
andreburgaud / text.erl
Created July 2, 2017 06:22
FutureLearn - Functional Programming in Erlang 2.25 - Text Processing
-module(text).
-export([get_file_contents/1,print_text/2,process/2]).
-include_lib("eunit/include/eunit.hrl").
%% -----------------------------------------------------------------------------
%% Text Processing exercise from Functional Programming in Erlang 2.25
%% -----------------------------------------------------------------------------
%% Compiled and tested with Erlang/OTP 20.0
%% -----------------------------------------------------------------------------
%% To execute tests in the Erlang shell:
@andreburgaud
andreburgaud / consolidations.erl
Created June 29, 2017 04:10
FutureLearn - Functional Programming in Erlang 2.18 - Consolidation: functions over lists
-module(consolidation).
-export([test_join/0,test_member/0,test_concat/0,
test_isort/0,test_msort/0,test_qsort/0,
test_perms/0,
concat/1,perms/1,
isort/1,msort/1,qsort/1,
insert/2,join/2,member/2]).
%% -----------------------------------------------------------------------------
%% join
@andreburgaud
andreburgaud / pal.erl
Last active June 28, 2017 19:21
FutureLearn - Functional Programming in Erlang 2.15 - Palindrome
-module(pal).
-export([test/0,alpha_nums/1,palindrome/1]).
%% alph_nums filter outs punctuation or non printable characters.
alpha_nums([]) -> [];
alpha_nums([X|Xs]) when X >= $A andalso X =< $z ->
[X|alpha_nums(Xs)];
alpha_nums([X|Xs]) when X >= $0 andalso X =< $9 ->
[X|alpha_nums(Xs)];
alpha_nums([_|Xs]) ->
@andreburgaud
andreburgaud / nub.erl
Created June 28, 2017 16:11
FutureLearn - Functional Programming in Erlang 2.12 - The 'nub' function
-module(nub).
-export([all_tests/0,nub/1,nub2/1]).
%% Helper to add element to list with no duplicate elements.
add(X, []) -> [X];
add(X, [Y|Uniqs]) when X == Y -> [Y|Uniqs];
add(X, [Y|Uniqs]) -> [Y|add(X, Uniqs)].
%% Helper to create a list of unique elements.
uniqs([],Uniqs) -> Uniqs;
@andreburgaud
andreburgaud / take.erl
Created June 28, 2017 15:16
FutureLearn - Functional Programming in Erlang 2.11 - Where do I begin?
-module(more_lists).
-export([reverse/1,take/2,take2/2,test_take/0,test_take2/0]).
%% Take with direct recursion
-spec take(integer(), [T]) -> [T].
take(_, []) -> []; % handles case where N > length(Xs)
take(0, _) -> [];
take(N, [X|Xs]) when N > 0 -> [X | take(N-1, Xs)].
test_take() ->
@andreburgaud
andreburgaud / transform.erl
Last active June 28, 2017 05:17
FutureLearn - Functional Programming in Erlang 2.9 - Constructing lists with recursive functions
-module(transform).
-export([double/1,evens/1,median/1,modes/1,sort/1,counters/2]).
%% ----------------------------------------------------------------------------
%% Double
double([]) -> [];
double([X|Xs]) -> [2*X | double(Xs)].
%% ----------------------------------------------------------------------------
%% Evens
@andreburgaud
andreburgaud / product.erl
Created June 27, 2017 04:14
FutureLearn - Functional Programming in Erlang 2.6 - Functions over lists
-module(product).
-export([all_tests/0,test_sum/0,test_prod/0,test_maximum/0,sum/1,sumT/1,prod/1,
prodT/1,maximum/1,maximumT/1]).
%% sum implementation with direct recursion (per the video)
sum([]) -> 0;
sum([X|Xs]) -> X + sum(Xs).
%% sum implementation with tail recursion (per the video)
sumT(Xs) -> sumT(Xs, 0).