Skip to content

Instantly share code, notes, and snippets.

@aaronjeline
Created February 22, 2021 04:57
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save aaronjeline/0c1cfa8fd083b3ae19cbf7e5f6cb0e0c to your computer and use it in GitHub Desktop.
Save aaronjeline/0c1cfa8fd083b3ae19cbf7e5f6cb0e0c to your computer and use it in GitHub Desktop.
Generate a random paper from papers-we-love
#lang racket
;; Usage information
;; Clone "https://github.com/papers-we-love/papers-we-love"
;; Use the download script under "scripts"
;; Create a file called "interests.txt" containing a list of
;; topics that you are interested in
;; Fill in the variable pdf-viewer with the path to your
;; pdf application (or #f if you don't want it to automatically oepn
(define pdf-viewer "/usr/bin/open")
(define (main)
(system "git pull")
(define path (random-topic-and-paper))
(launch path)
(display (format "Paper: ~a\n" (path->string path))))
(define (launch path)
(when pdf-viewer
(subprocess #f #f #f
pdf-viewer
path)))
(define (random-topic-and-paper)
(let [(topic (random-topic))]
(build-path (symbol->string topic)
(random-paper topic))))
(define (random-topic)
(random-element (load-interests)))
(define (load-interests)
(with-input-from-file "interests.txt" read))
(define (random-paper topic)
(random-element (directory-list (format "./~a" topic))))
(define (random-element lst)
(let [(r (random 0 (length lst)))]
(list-ref lst r)))
(main)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment