Skip to content

Instantly share code, notes, and snippets.

@greghendershott
Last active July 25, 2017 01:36
Show Gist options
  • Save greghendershott/b20effb9d9c48211e1c11d9486257918 to your computer and use it in GitHub Desktop.
Save greghendershott/b20effb9d9c48211e1c11d9486257918 to your computer and use it in GitHub Desktop.
#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")
@greghendershott
Copy link
Author

greghendershott commented May 14, 2017

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment