Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
A quickscript to install them all! (from the 2020 competition)
#lang racket/base
;; License: Apache2.0/MIT
(require quickscript
quickscript/base
quickscript/library
racket/gui/base
racket/class
racket/file
racket/list
racket/string
racket/port
net/url)
(script-help-string "Run this script to install all entries from the competition")
;;; How to use:
;;; 1) In DrRacket, create a new script via Scripts > Manage scripts > New script...
;;; For the name, type "competition2020".
;;; A new tab is open in DrRacket with a default script.
;;; 2) Copy paste this file in place of the default script and save it.
;;; 3) Click on Scripts > Manage scripts > Reload menu,
;;; then Scripts > competition-2020-scripts,
;;; then again Scripts > Manage scripts > Reload menu.
;;; Now all the scripts of the competition appear in your Script menu.
;;;
;;; You can check, edit and disable the scripts via the library:
;;; Scripts > Manage scripts > Library...
(define dir (build-path quickscript-dir "competition-2020"))
(define entries-url
"https://github.com/Quickscript-Competiton/July2020entries/wiki/Links-to-scripts.md")
(define (get-script-links)
(filter
values
(for/list ([line (in-lines (get-pure-port (string->url entries-url) #:redirections 10))])
(define m
(regexp-match (pregexp
#<<EOS
\* \[([^]]+)\]\((.+)\)
EOS
)
#;"* [breakout](https://gist.githubusercontent.com/spdegabrielle/83bc77dde1cec50067498176ed5f960e/raw)"
line))
(and m (rest m)))))
(define (href->script url-str name)
(define str (port->string (get-pure-port (string->url url-str) #:redirections 10)))
(define afile (build-path dir (string-append name ".rkt")))
(display-to-file
(string-append str "\n; From: " url-str "\n")
afile
#:exists 'replace))
(define (show-message-frame title msg #:parent [parent #f])
(define fr (new frame% [label title] [parent parent]))
(new message% [parent fr] [label msg])
(send fr show #t)
fr)
;; Returns a replacement string for the selected string `selection`
;; ("" if no text is selected), or `#f` to leave the selection as is.
(define-script competition-2020-scripts
#:label "competition-2020-scripts"
#:output-to message-box
(λ (selection #:frame frame)
(define msg-frame
(show-message-frame "Quickscript Competition 2020"
"Retrieving scripts, please wait..."
#:parent frame))
(make-directory* dir)
(add-third-party-script-directory! dir)
(define slinks (get-script-links))
(for ([sl (in-list slinks)])
(href->script (second sl) (first sl)))
(send msg-frame show #f)
(string-append
"The following scripts will be (re)installed:\n"
(string-append* (map (λ (sl) (string-append "* " (first sl) "\n")) slinks))
"You may have to reload the menu: Scripts > Manage scripts > Reload menu")))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.