Elixir implementation of: https://github.com/dwyl/hits
Because Elixir == ❤️!! see: github.com/dwyl/learn-elixir#why
A basic "web counter", see: https://github.com/dwyl/hits#what
- Elixir installed: https://github.com/dwyl/learn-elixir#how
- Basic knowledge/understanding of Elixir syntax: https://elixir-lang.org/crash-course.html
To run the app on your localhost follow these 3 easy steps:
git clone https://github.com/dwyl/hits-elixir.git && cd hits-elixir
Install dependencies and create necessary directories (to store the data):
mix deps.get && mkdir -p logs/agents
mix run --no-halt
That's it!
Visit: http://localhost:8080/ (in your web browser)
Or visit any endpoint that includes .svg
in the url,
e.g: http://localhost:8080/yourname/project.svg
Refresh the page a few times and watch the count go up!
note: I've increased the "zoom" in chrome to 500% for effect.
Now, take your time to peruse the code in /test
and /lib
,
and ask any questions by opening GitHub Issues:
https://github.com/dwyl/hits-elixir/issues
You
mix test
If you want to run the tests with coverage, copy-paste the following command into your terminal:
mix cover
If you want to view the coverage in a web browser:
mix cover && open cover/excoveralls.html
We found the following links/articles/posts useful when learning how to build this mini-project:
- Plug Docs: https://hexdocs.pm/plug/readme.html (the official Plug docs)
- Plug Conn (connection struct specific) Docs: https://hexdocs.pm/plug/Plug.Conn.html (the are feature-complete but no practical/usage examples!)
- Understanding Plug (Phoenix Blog): https://hexdocs.pm/phoenix/plug.html
- Elixir School Plug: https://elixirschool.com/en/lessons/specifics/plug/
- Getting started with Plug in Elixir: https://www.brianstorti.com/getting-started-with-plug-elixir (has a good/simple example of "Plug.Builder")
- Elixir Plug unveiled: https://medium.com/@kansi/elixir-plug-unveiled-bf354e364641
- Building a web framework from scratch in Elixir: https://codewords.recurse.com/issues/five/building-a-web-framework-from-scratch-in-elixir
- Testing Plugs: https://robots.thoughtbot.com/testing-elixir-plugs
- Cryptographic hash functions in Elixir by @djm: https://www.djm.org.uk/posts/cryptographic-hash-functions-elixir-generating-hex-digests-md5-sha1-sha2/
- How to create your own Mix Tasks: https://joeyates.info/2015/07/25/create-a-mix-task-for-an-elixir-project/
iex> "1test2" == "test"
false
iex> "1test2" =~ "test"
true
:rand.uniform(n)
iex> DateTime.utc_now |> DateTime.to_unix
1486035766
iex> System.system_time(:second)
1486035766
iex> System.system_time(:millisecond)
1504975995312