Skip to content

Instantly share code, notes, and snippets.

@winny-
Created July 26, 2015 22:23
Show Gist options
  • Save winny-/73a4e5504a645178a990 to your computer and use it in GitHub Desktop.
Save winny-/73a4e5504a645178a990 to your computer and use it in GitHub Desktop.
#!/usr/bin/env racket
#lang racket/base
(require racket/string)
(require racket/port)
(require racket/cmdline)
(require racket/path)
(require net/http-client)
(require net/uri-codec)
(define (sprunge s)
(let-values ([(status headers port)
(http-sendrecv "sprunge.us"
"/"
#:method #"POST"
#:data (alist->form-urlencoded (list (cons 'sprunge s)))
#:headers '("Content-Type: application/x-www-form-urlencoded"))])
(string-trim (port->string port))))
(define (parse-status-code status)
(string->number (list-ref (string-split (bytes->string/utf-8 status)) 1)))
(define (do-main)
(let ([args (current-command-line-arguments)])
(if (equal? args #())
(displayln (sprunge (port->string)))
(for ([i args])
(displayln (string-append
(sprunge (port->string (open-input-file i)))
"?"
(bytes->string/utf-8 (filename-extension (string->path i)))))))))
(module+ main (do-main))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment