Sunday, September 26, 2010
Mediterranean cruise
My Mediterranean 12-night cruise on the Brilliance Of The Seas. See my Photo Album and Video . My favourite destinations were Pompeii, Venice, and Pisa. I was really impressed by the Leaning Tower, and the overall beauty of Venice. I gained 2.5 lbs in weight during the cruise. They certainly feed you well! I tried a Caesar Salad and sushi for the first time, amongst many dishes. Can't say I cared much for the sushi, though.
Saturday, September 11, 2010
Hacker News | The Single Most Important Secret to Success
Hacker News | The Single Most Important Secret to Success
| |||
| |||
|
Sunday, September 5, 2010
DrRacket: a dirt-simple exception handler
Exception-handling in Racket is very powerful - but a little overwhelming to me. Suppose you want to do some very very simple exception handling: try something, but if it fails, return an error-value. The way you do this is by using with-handlers:
There's a lot of goo here, which can be tidied up with some macrology. I give this simple macro, and a couple of examples below:
(with-handlers ([exn:fail? (lambda (exn) put-specified-default-here)]) try-something-here)
There's a lot of goo here, which can be tidied up with some macrology. I give this simple macro, and a couple of examples below:
(define-syntax catch-errors (syntax-rules () ((_ error-value body ...) (with-handlers ([exn:fail? (lambda (exn) error-value)]) body ...)))) (catch-errors "Oops" (/ 1 0)) ; "Oops" (catch-errors "Oops" (/ 6 3)) ; 2 (catch-errors "Oops" (/ 6 3) (/ 16 2)) ; 8
Twitter account
I created a Twitter account recently. It will probably mostly just link back to this blog - for now, anyway.
Saturday, September 4, 2010
YT: Brian Tracy Fear of Failure
In a Youtube video, Brain Tracy recommends the following:
At the top of a clean sheet of paper, write the question "What am I afraid of?". Make a list, and select the one you feel holds you back the most. With your biggest fear in mind, write your answer to these three questions:
At the top of a clean sheet of paper, write the question "What am I afraid of?". Make a list, and select the one you feel holds you back the most. With your biggest fear in mind, write your answer to these three questions:
- How does this fear hold me back?
- How does it help me, or how does it help me in the past?
- What would be the payoff for eliminating this fear altogether?
Friday, September 3, 2010
DrRacket: a first attempt at a web server
This is my first attempt at a web server using DrRacket. It is supposed to calculate VAT given an input of Net or VAT. It doesn't actually do any calculations, but it does respond to buttons and suchlike.
#lang racket
(require web-server/formlets
web-server/servlet
web-server/servlet-env)
(define init-input-string (λ(val)
(to-string
(required
(text-input #:value
(string->bytes/locale
val))))))
#|
(define vat-page%
(class object%
(super-new)
(init-field (rate "17.5") (amount "0"))
(define vat-formlet
(formlet
(div "Amount: " ,{input-string . => . amount}
(p "")
"VAT Rate: " ,{(init-input-string "17.5") . => . rate}
(p "Still in form. Hello Brooks."))
#t))
(define (button-clicked request)
;(define-values (amount rate)
(formlet-process vat-formlet request)
(print "insert-post-handle")
(print amount)
(render (redirect/get)) )
(define/public (render request)
`(html (head (title "My Calculator"))
(body
(h1 "Simple VAT calculator")
(form ([action ,(make-url button-clicked)])
,@(formlet-display vat-formlet)
(input [(type "submit") (value "Calculate")]))
(p ,amount)
(p ,rate))))))
(define (render-vat-page-new request)
(define vat-page (make-object vat-page%))
(define (response-generator make-url)
(send vat-page render make-url))
(send/suspend/dispatch response-generator))
(serve/servlet render-vat-page-new #:port 80 #:listen-ip #f)
|#
(define vat-formlet
(formlet
(div "Amount: " ,{input-string . => . amount}
(p "")
"VAT Rate: " ,{(init-input-string "17.5") . => . rate}
(p "Still in form. Hello Brooks."))
(values amount rate)))
(define (render-vat-page amount rate request)
(local [(define (response-generator make-url)
`(html (head (title "My Calculator"))
(body
(h1 "Simple VAT calculator")
(form ([action
,(make-url button-clicked)])
,@(formlet-display vat-formlet)
(input [(type "submit") (value "Calculate")]))
(p ,amount)
(p ,rate))))
(define (button-clicked request)
(define-values (amount rate)
(formlet-process vat-formlet request))
(print "insert-post-handle")
(print amount)
(render-vat-page amount rate (redirect/get)))]
(send/suspend/dispatch response-generator)))
(serve/servlet (λ(request) (render-vat-page "0.0" "17.5" request)) #:port 80 #:listen-ip #f)
Subscribe to:
Posts (Atom)