Show HN: Codestat.dev – Stats from 2M open-source repositories (codestat.dev)

63 points by slimsag ↗ HN
Hi HN! This is a little site I put together while learning the Elm language as part of a hackathon at my work, I thought you might enjoy it.

Be sure to click the `(source)` buttons next to the graphs: you can edit them interactively & write your own queries against the entire data set. The syntax isn't well documented yet, but you can probably get the general idea pretty quickly based on the examples there.

If you like it, have questions, etc. let me know! If folks think this is cool, maybe I can get it turned into a legit project. :)

8 comments

[ 2.9 ms ] story [ 29.2 ms ] thread
(comment deleted)
(comment deleted)
Interesting! Why are the numbers/bar chart values bouncing around? Is it making the same query from everyone's browser when you load the page?
Checked the network logs - it seems to perform an API query [0] which returns a stream of data, that's then computed upon on-the-fly in the browser.

[0]: https://sourcegraph.com/.api/compute/stream?q=context%3A%40r...

That's right, it streams every search result match back to your browser and the Elm code on the frontend then calculates the stats live.

So the reason they bounce around is because new results are streaming in, and it's updating the chart live based on those.

After a little bit it will stop & have found all results

Details about the query syntax you can play with at https://codestat.dev/explorer

Basic format is:

    content:output((REGEXP) -> $1)
For example, this query will find all `License: <word>` instances in code/text files across all 2 million repos. It selects (`-> $1`) the first regexp capture group `(\w+)`:

    content:output(License: (\w+)\n -> $1) count:all
There are some options you can add, like `count:all` (get all results it can find, will timeout after 60s), `repo:github\.com/myorg/` (regexp filter to just your repos)

Can use this for code mining, too: to find out what the most common delimiter passed to `strings.Split` in Go is, for example:

    lang:go content:output(strings\.Split\(.*, (.*)\) -> $1) count:all
So great to see you on the front page, Stephen! Super cool work! Curious - my first time reading elm, is CSS an anti-pattern? I notice the styles are all inlined
Ha! Long time no see :) I'm no Elm expert, but I would say from what I've seen that mixing-and-matching (JS+Elm, CSS+Elm) as you see fit is totally fine, adopting Elm can be super incremental.

When it comes to changing CSS dynamically, it's quite nice to have that in Elm code too rather than say a CSS class you toggle.

The thing I'm using here is elm-ui, it takes a more opinionated approach and basically eliminates a lot of the CSS oddities: instead of numerous flex, margin etc. CSS properties you just get simple alignLeft, centerX, etc. attributes in a row/column layout. Quite nice. There's a talk[0] about it.

[0] https://www.youtube.com/watch?v=Ie-gqwSHQr0&t=2s