Thursday, February 26, 2009

The Science of Dune, Edited by Kevin R. Grazier

The Science of Dune: An Unauthorized Exploration into the Real Science behind Frank Herbert's Fictional Universe (Science of Pop Culture series)

This book is pretty bad. There are lots of editing problems. Basically every chapter says the same thing, "Um, it's cool, but not sure how it would really work." And that gets a little tedious after a while. If you are a Dune fanatic, you'll probably like it. The best chapters are the ones of the sandworms and the stillsuits.

Tuesday, February 17, 2009

Unit Contracts in PLT Web Server

The PLT Web Server now uses unit contracts throughout. Go team!

Monday, February 16, 2009

Rough Stone Rolling by Richard Bushman

Joseph Smith: Rough Stone Rolling, by Richard Bushman

I started reading this a second time on Joseph's birthday last year. I've been a bit lazy with my book reading, because I got distracted by some Conan comics. It was an awesome read.

Just one quote this time:

It was his calling, as Joseph himself put it, to "lay a foundation that will revolutionize the whole world." [p. 561]

Friday, February 13, 2009

Datalog in PLT Scheme

I've just released a PLaneT package that adds Datalog as a language in DrScheme. It is called datalog.plt.

Documentation is available online. In particular, check out the tutorial!

Friday, February 6, 2009

Introducing... Stuffers

The PLT Web Server stateless servlet language allows continuations to be serialized. This subtle features can produce entirely RESTful Web applications that use send/suspend, because continuations can be given to clients, rather than kept on the server.

Before today, the serialization process was not customizable. There was a single default. But now, you can write your own stuffers using the Stuffer API and instruct the server to use them in your servlet code.

Currently there are stuffers for:

  • GZip-ing
  • Base64 encoding
  • MD5 content-addressed filesystem storage

In the future, I will be adding support for encrypting and signing, in addition to content-addressed database storage through SQLite, CouchDB, and BerkeleyDB.

Simple Server setup abstraction in the PLT Web Server

The PLT Web Server provides serve/servlet to start a server specifically for a single servlet and immediately launch a browser to it. This is how the Instant Servlet language works.

One of the frustrating things about this interface is that you can't change what dispatchers the simple servers use, so if you want to build a dispatcher for a single servlet or start a server and launch a browser, you must copy the code. Both of these subtasks are now abstracted into helper functions:

  • dispatch/servlet: Builds a dispatcher to run a servlet .
  • serve/launch/wait: Starts a Web Server instance and launches a browser to one of its URLs.

Wednesday, February 4, 2009

Digest Authentication in the PLT Scheme Web Server

The PLT Scheme Web Server now has built-in support for Digest Authentication.

It is provided by the web-server/http/digest-auth module (and through the web-server/http wrapper that is included in all servlets.)

Here's an example:

  #lang web-server/insta
  (require scheme/pretty)
  
  (define private-key "private-key")
  (define opaque "opaque")
  
  (define (start req)
    (match (request->digest-credentials req)
      [#f
       (make-response/basic
        401 #"Unauthorized" (current-seconds)
        TEXT/HTML-MIME-TYPE
        (list (make-digest-auth-header
               (format "Digest Auth Test: ~a" (gensym))
               private-key opaque)))]
      [alist
       (define check
         (make-check-digest-credentials
          (password->digest-HA1
           (lambda (username realm) "pass"))))
       (define pass?
         (check "GET" alist))
       `(html (head (title "Digest Auth Test"))
              (body
               (h1 ,(if pass? "Pass!" "No Pass!"))
               (pre ,(pretty-format alist))))]))

Tuesday, February 3, 2009

Cookies in the PLT Web Server

It has always been possible to use cookies in PLT Web Server applications, but a lot of the work was not done for you.

Now it is!

The PLT Web Server now provides two modules as part of web-server/http for cookies: web-server/http/cookie for installing cookies and web-server/http/cookie-parse for extracting them.

Here's a simple example:

#lang web-server/insta
(require net/url)

(define (start req)
  (define cookies (request-cookies req))
  (define id-cookie
    (findf (lambda (c)
             (string=? "id" (client-cookie-name c)))
           cookies))
  (define who
    (if id-cookie
        (client-cookie-value id-cookie)
        #f))
  (define new-req
    (send/suspend
     (lambda (k-url)
       `(html (head (title "Hello!"))
              (body (h1 "Hello " ,(if who who ""))
                    (form ([action ,k-url])
                          (input ([name "who"]))))))))
  (define binds
    (request-bindings/raw new-req))
  (match (bindings-assq #"who" binds)
    [(? binding:form? b)
     (define new-who 
       (bytes->string/utf-8 (binding:form-value b)))
     (redirect-to (url->string (request-uri req))
      see-other
      #:headers
      (list
       (cookie->header (make-cookie "id" new-who))))]
    [else
     (redirect-to
      (url->string (request-uri req))
      see-other)]))

This addition is based on code written for the PLaneT server by Jacob Matthews and the existing net/cookie client-side cookie library.