Christopher’s posterous

Mostly programming things 
Filed under

code

 

HexClock (Part 2)

Click here to download:
hexclock_visual.jar (592 KB)

This is the second installment of my Clojure ( http://clojure.org )
hex clock postings. I think I covered most of the discussion in the
last one. This post is just for my other design. This version
represents the time visually, as a series of colored squares. The MSB
is in the upper left and represents a half day. Read it just like the
(English) newspaper, left to right top to bottom. The LSB is in the
lower right and changes every 1.3 seconds. This makes it easy to
orient the clock.

Filed under  //   clojure   code   hexclock   java  

Comments [0]

Gists

Nice:
 

Filed under  //   clojure   code   gist   github   lisp   programming  

Comments [0]

EmacsWiki: Paredit Cheatsheet

Wow! Paredit, where have you been all my life? http://mumble.net/~campbell/emacs/paredit.el

Filed under  //   code   emacs   lisp   paredit   programming  

Comments [0]

Good Lisp Commenting Style

Check out this website I found at cc.gatech.edu

Tips on commenting lisp code. I fall into Camp 2, well I try to anyway, my code usually isn't that clear and so I shade into Camp 3.

Filed under  //   code   comment   lisp   programming  

Comments [0]

XTerm Colors

I usually like to use xterm (fast, always available, etc.) but one
issue that's pretty persistent is that the colors, with blue in
particular, are too dark. When I google on this, I'm able to find
instructions on how to change *what* color is being used but not how
to modify what that color is. As an example of what's easy to find:

 
XTerm*Background: green 

This will do as expected and set the background of the XTerm to green,
but it won't help you at all to define what shade that green is. The
setting that I really want is this:
 
XTerm*color4: blue 

Any of the 8 colors (color0 through color7) can be changed like this,
but usually the offender is the above. I think the following looks
pretty good:
 
XTerm*color4: CornflowerBlue 

Here's a great listing of the available colors:
http://mkaz.com/ref/xterm_colors.html

Filed under  //   code   linux   tips   xterm  

Comments [0]

Clojure Translations (part one?)

This is a simple translation of some Java code into Clojure
(http://clojure.org/). I've tried to make the code idiomatic Clojure
(as far as I know it). I'm looking at the NIO libraries and the
SocketChannel in particular for doing some more intelligent two-way
network code.
 

 
; translation of the java code at:                                              
; http://java.sun.com/j2se/1.4.2/docs/guide/nio/example/TimeServer.java         
; (original copyright can be found there)                                       

(ns com.sencjw.time-server
  (:import (java.net Socket ServerSocket InetSocketAddress InetAddress)
           (java.nio ByteBuffer CharBuffer)
           (java.nio.channels ServerSocketChannel)
           (java.nio.charset Charset CharsetEncoder)
           (java.util Date)))

(set! *warn-on-reflection* true)

(defn serv
  "Starts a time server on a high (8013 default) port"
  ([] (serv 8013))
  ([port]
     (let [charset (.. Charset (forName "US-ASCII"))
           encoder (.newEncoder charset)
           buff (.. ByteBuffer (allocateDirect 1024))
           ssc (ServerSocketChannel/open)               ; create ServSockChan   
           addr (InetSocketAddress. port)
           _ (.bind (.socket ssc) addr)
           sc (.accept ssc)                             ; accept the connection
           now (str (Date.))]
       (try
        (.write sc (.encode encoder (CharBuffer/wrap (str now "\r\n"))))
        (println (str (.. sc (socket) (getInetAddress)) ": " now))
        (.close sc)
        (finally (.close sc))))))

(serv)

Filed under  //   clojure   code   java   lisp   translation  

Comments [0]

Laziness is amazing

I'm really just starting to grasp what you can do with laziness (I would say I'm "on my way" but there was a hiccup the other day where I wanted to produce a lazy sequence of files for processing (so that I could map over them, or maybe use 'seque') as the files appeared in the directory; if you know how to do this, please share!). But so far the experience has been really good. I've started to notice situations where it would be genuinely useful, but there's also just the cool factor (and that goes pretty far for me):

(def integers (iterate inc 1))
(take 5 integers); gives: (1 2 3 4 5)

Fun.

*edit: I forgot to mention, this example is from the excellent Programming Clojure

Filed under  //   clojure   code   lazy   lisp  

Comments [0]