Last active
July 25, 2017 01:36
-
-
Save greghendershott/b20effb9d9c48211e1c11d9486257918 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#lang racket/base | |
(require net/url | |
racket/match) | |
(define pkgs | |
(let ([pkgs (call/input-url (string->url "https://pkgs.racket-lang.org/pkgs-all") | |
get-pure-port | |
read)]) | |
(for/fold ([pkgs pkgs]) | |
([(name ht) (in-hash pkgs)]) | |
(define deps (for/list ([x (in-list (hash-ref ht 'dependencies))]) | |
(match x ;just the name -- ignore versions | |
[(? string? s) s] | |
[(cons (? string? s) _) s]))) | |
(values | |
(for/fold ([pkgs pkgs]) | |
([dep (in-list deps)]) | |
(values | |
(hash-update pkgs | |
dep | |
(λ (ht) (hash-update ht | |
'users | |
(λ (xs) (cons name xs)) | |
(list))) | |
(hasheq)))))))) | |
(define (users name) | |
(sort (hash-ref (hash-ref pkgs name (hash)) | |
'users (list)) | |
string<=?)) | |
(define users-count (compose length users)) | |
(define (top-n-most-users [n 25]) ;Integer -> (Pairof Symbol Integer) | |
(for/list ([name (in-list (sort (hash-keys pkgs) > #:key users-count))] | |
[_ n]) | |
(cons name (users-count name)))) | |
;; Example: | |
;; | |
;; (top-n-most-users) | |
;; (users "math-lib") |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
In early revisions I'd overlooked the existence of a
pkgs-all
path.Derp.
This version is vastly simpler -- it's quick to download the entire package catalog in a single HTTP request.