Skip to content

📈 An Elixir implementation of the "Hits" project (a super-basic "Web Page View Counter")

License

Notifications You must be signed in to change notification settings

dwyl/hits-elixir

Repository files navigation

Hits Elixir

hits-dwyl-teal-banner

Build Status Inline docs codecov.io HitCount


Elixir implementation of: https://github.com/dwyl/hits

Why?

Because Elixir == ❤️!! see: github.com/dwyl/learn-elixir#why

What?

A basic "web counter", see: https://github.com/dwyl/hits#what

Assumptions / Prerequisites

How?

To run the app on your localhost follow these 3 easy steps:

1. Clone/Download the Code

git clone https://github.com/dwyl/hits-elixir.git && cd hits-elixir

2. Install the Dependencies

Install dependencies and create necessary directories (to store the data):

mix deps.get && mkdir -p logs/agents

3. Run the App

mix run --no-halt

That's it!

Visit: http://localhost:8080/ (in your web browser)

hits-homepage

Or visit any endpoint that includes .svg in the url, e.g: http://localhost:8080/yourname/project.svg

hits-example-badge

Refresh the page a few times and watch the count go up!

hit-count-42

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

Run the Tests

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

Research & Background Reading

We found the following links/articles/posts useful when learning how to build this mini-project:

Plug (the Elixir HTTP Library)

SHA Cryptographic Hash Functions in Elixir/Erlang

Mix Tasks

Compact sub-string syntax

iex> "1test2" == "test"
false
iex> "1test2" =~ "test"
true

Generate Random Strings in Elixir

:rand.uniform(n)

Unix Timestamp in Elixir

iex> DateTime.utc_now |> DateTime.to_unix
1486035766

iex> System.system_time(:second)
1486035766

iex> System.system_time(:millisecond)
1504975995312

About

📈 An Elixir implementation of the "Hits" project (a super-basic "Web Page View Counter")

Resources

License

Code of conduct

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published