Skip to content

Instantly share code, notes, and snippets.

@jackfirth
Created September 11, 2019 18:10
Show Gist options
  • Select an option

  • Save jackfirth/184c373a5ca9c3b35ac1544528079492 to your computer and use it in GitHub Desktop.

Select an option

Save jackfirth/184c373a5ca9c3b35ac1544528079492 to your computer and use it in GitHub Desktop.
#lang racket
(require net/url
rebellion/base/immutable-string
rebellion/binary/immutable-bytes
rebellion/collection/entry
rebellion/collection/list
rebellion/collection/multidict
rebellion/collection/multiset
rebellion/type/tuple)
(define/contract (get-pkgs-all-bytes)
(-> immutable-bytes?)
(bytes->immutable-bytes
(call/input-url (string->url "https://pkgs.racket-lang.org/pkgs-all")
(λ (resource) (get-pure-port resource #:redirections 5))
port->bytes)))
(define/contract (get-pkgs-all)
(-> hash?)
(with-input-from-bytes (get-pkgs-all-bytes) read))
(define/contract (get-dependency-graph)
(-> multidict?)
(for*/multidict ([(name details) (in-hash (get-pkgs-all))]
[dep (in-list (hash-ref details 'dependencies))])
(define dep-name
(if (string? dep)
dep
(list-first dep)))
(entry (string->immutable-string name)
(string->immutable-string dep-name))))
(define/contract (get-rebellion-clients)
(-> (set/c immutable-string?))
(define all (get-pkgs-all))
(for*/set ([(name details) (in-hash (get-pkgs-all))]
#:when (depends-on? details "rebellion"))
(string->immutable-string name)))
(define/contract (depends-on? details pkg)
(-> hash? immutable-string? boolean?)
(for/or ([dep (in-list (hash-ref details 'dependencies))])
(equal? dep pkg)))
(module+ main
(define dep-graph (get-dependency-graph))
(define dep-counts (multiset-frequencies (multidict-keys dep-graph)))
(define reverse-dep-counts
(multiset-frequencies (multidict-values dep-graph)))
(define-tuple-type frequency (element count))
(define dep-counts-list
(for/list ([(dep count) (in-immutable-hash dep-counts)])
(frequency dep count)))
(define reverse-dep-counts-list
(for/list ([(dep count) (in-immutable-hash reverse-dep-counts)])
(frequency dep count)))
(for ([freq (in-list (sort dep-counts-list > #:key frequency-count))]
[_ (in-range 00)])
(printf "~a: ~a dependencies\n"
(frequency-element freq)
(frequency-count freq)))
(newline)
(for ([freq (in-list (sort reverse-dep-counts-list > #:key frequency-count))]
[_ (in-range 50)])
(printf "~a: ~a clients\n"
(frequency-element freq)
(frequency-count freq))))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment