View Source Freecodecamp exercises using Elixir
Solving exercises from Freecodecamp.org using Elixir programming language. Includes benchmarks and tests for every functions.
Folders that are interesting to read can be found at:
elixir-installation
Elixir installation
Either use Docker, this Docker automated install script curl -sSL https://get.docker.com/ | sh
, or use asdf
.
using-docker
Using Docker
using docker_start
shell script (use wsl on windows or git bash, otherwise this works both ?mac? and linux), or see the file if you want to use docker commands instead.
# I haven't tried this both on windows and mac, YMMV
source docker_start
Why source docker_start
instead of chmod +x ./docker_start
? read run bash script doesn't work alias command.
Getting dependencies
mix deps.get --only test
Launch REPL
iex -S mix
Stopping Elixir container, remove alias created by shell script
# where "elixir" is the name of the container
docker container stop elixir
# temporary alias are not persisted across different sessions
# but if you want to remove them
unalias elixir iex mix elixirc
create-pre-commit-hook
Create Pre-commit Hook
mix precommit
test
Test
mix test
Coverage
mix text --cover
Selective tests
# i.e. you want to test only "Basic Algorithms"
mix selective_test basic_algo
# or more, separated by spaces
mix selective_test basic_algo intermediate_algo
# basic_algo = Basic Algorithm Scripting
# intermediate_algo = Intermediate Algorithm Scripting
# algo_projects = Algorithm Projects
generate-html-docs
Generate HTML
Docs
# running this generates docs in "doc/" directory
mix docs
benchmarks-using-benchee
Benchmarks (using Benchee)
If you want to benchmark a specific function:
# NOTE: file path is at
# freecodecamp_elixir/benchmarks/basic_algo.exs
# Example: change the function name from
# "mutation" to "repeat_string"
# BasicAlgo.run("mutation", HTML)
# or uncomment lines to use that instead
BasicAlgo.run("repeat_string", HTML)
# you can use the default formatter (console)
BasicAlgo.run("repeat_string", Console)
mix run benchmarks/basic_algo.exs