Created
November 22, 2009 02:19
-
-
Save offby1/240386 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
;; contact my little url server. | |
(defun browse-url-remotely (&optional url new-window) | |
(interactive) | |
(let* ((url (or url (thing-at-point 'url))) | |
(url-server (open-network-stream "url-server" nil "localhost" 7654))) | |
(process-send-string url-server (format "%s\n" url)) | |
(delete-process url-server))) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#! /usr/bin/env mzscheme | |
#| Hey Emacs, this is -*-scheme-*- code! | |
#$Id: url-server.ss 5793 2008-11-29 21:15:18Z erich $ | |
|# | |
#lang scheme | |
;; as consolers says: "a /bin/sh while loop over netcat wouldve | |
;; sufficed!" | |
(require (lib "url.ss" "net") | |
(lib "thread.ss") | |
(lib "sendurl.ss" "net") | |
(lib "uri-codec.ss" "net") | |
(lib "19.ss" "srfi")) | |
(current-alist-separator-mode 'amp) | |
(fprintf (current-error-port) | |
"~aURL server started at ~a; ready for action!~%" | |
(banner) | |
(date->string (current-date) "~Y-~m-~dT~X~z")) | |
(run-server | |
7654 | |
(lambda (ip op) | |
(for ((line (in-lines ip))) | |
(let* ((u (string->url line)) | |
(scheme (url-scheme u))) | |
(printf "~a: " (date->string (current-date) "~Y-~m-~dT~X~z")) | |
(if (and scheme | |
(regexp-match #rx"^(http|https|ftp)$" scheme)) | |
;; ooh, I know how to handle this. | |
(begin | |
(printf "~a~%" line) | |
(send-url (url->string u) #f) | |
) | |
;; hmm. Perhaps, if the scheme is #f, we should just glue | |
;; "http:" to the front and try again. | |
(printf "Ain't gonna open ~s 'cuz it doesn't look like an http URL~%" | |
line)) | |
(flush-output)))) | |
#f ;; conn-timeout | |
raise | |
) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment