{"id":26340979,"url":"https://github.com/jmp/retro_counter","last_synced_at":"2025-03-16T04:21:58.891Z","repository":{"id":281504642,"uuid":"935521781","full_name":"jmp/retro_counter","owner":"jmp","description":"A simple retro-style visitor counter for websites written in Elixir.","archived":false,"fork":false,"pushed_at":"2025-03-09T14:36:38.000Z","size":43,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-03-09T15:28:55.640Z","etag":null,"topics":["bandit","elixir","plug","server","visitor-counter"],"latest_commit_sha":null,"homepage":"","language":"Elixir","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/jmp.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2025-02-19T15:26:23.000Z","updated_at":"2025-03-09T14:36:42.000Z","dependencies_parsed_at":"2025-03-09T15:39:29.912Z","dependency_job_id":null,"html_url":"https://github.com/jmp/retro_counter","commit_stats":null,"previous_names":["jmp/retro_counter"],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jmp%2Fretro_counter","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jmp%2Fretro_counter/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jmp%2Fretro_counter/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jmp%2Fretro_counter/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/jmp","download_url":"https://codeload.github.com/jmp/retro_counter/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":243823842,"owners_count":20353744,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["bandit","elixir","plug","server","visitor-counter"],"created_at":"2025-03-16T04:21:58.402Z","updated_at":"2025-03-16T04:21:58.883Z","avatar_url":"https://github.com/jmp.png","language":"Elixir","funding_links":[],"categories":[],"sub_categories":[],"readme":"# RetroCounter\n\nThis is a simple retro-style visitor counter for websites.\n\nIt started as stupid idea. Who has visitor counters on their websites these days?\nBut it seemed like a small enough project to learn Elixir, so I decided why not.\n\nThe original idea was to store the current visitor count in a flat text file.\nWhen a person visits the site, we would read the count from the file, increment\nit by one, then write the new count back into the file.\n\nThere is one obvious problem with this approach. The file may get corrupted with\nsimultaneous reads and writes.\n\nThen I realized Elixir has super powers. I can use a [GenServer][genserver] to hold the count\nin memory all the time. It also means I have a single process at the time writing to the file.\nAs an extra bonus, you can defer writing by some delay (e.g. 30 seconds) to make sure we don't\nwrite to the file on every counter increment.\n\nMaybe this approach also has some downsides, but it was very simple to do in Elixir,\nand relatively easy to test as well. Especially given that I had zero experience with\nExUnit before.\n\nAnyway, this has been an fun learning experience and maybe it'll be interesting for\nsomebody else as well. So, here you go.\n\n## Run using Mix\n\nFirst, install the dependencies:\n\n    mix deps.get\n\nThen run:\n\n    mix run --no-halt\n\nAccess the counter at http://localhost:4000/count.svg.\n\n## Configuration\n\nYou can configure the server with environment variables:\n\n| Environment variable        | Default value | Description                                      |\n| --------------------------- | ------------- | ------------------------------------------------ |\n| `RETRO_COUNTER_PORT`        | `4000`        | Port for the HTTP server.                        |\n| `RETRO_COUNTER_PATH`        | `count.txt`   | Path to where the current count will be stored.  |\n| `RETRO_COUNTER_WRITE_DELAY` | `30000`       | Number of milliseconds to defer writing to file. |\n\n## Run tests\n\n    mix test\n\n[genserver]: https://hexdocs.pm/elixir/GenServer.html\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fjmp%2Fretro_counter","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fjmp%2Fretro_counter","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fjmp%2Fretro_counter/lists"}