Created
October 20, 2009 16:23
-
-
Save hchbaw/214388 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
(defun get-scores () | |
(let ((h (make-hash-table :test 'eql))) | |
(mapatoms (lambda (sym) | |
(let ((s (symbol-name sym))) | |
(unless (equal s "") | |
(if (gethash (aref s 0) h) | |
(incf (gethash (aref s 0) h)) | |
(puthash (aref s 0) 1 h)))))) | |
(let (xs) | |
(maphash (lambda (k v) | |
(push (cons k v) xs)) | |
h) | |
(sort* xs '> :key 'cdr)))) | |
(progn | |
(defun* write-scores (xs &optional (path "/pub/dropbox/tmp/a.html")) | |
(macrolet ((with-my-saving-buffer (path &body body) | |
`(with-current-buffer (find-file-noselect ,path) | |
(erase-buffer) | |
(progn ,@body) | |
(save-buffer)))) | |
(let ((max (reduce 'max (mapcar 'cdr xs) :initial-value 0))) | |
(with-my-saving-buffer path | |
(apply | |
'insert | |
(mapconcat | |
'identity | |
`("<img src=\"http://chart.apis.google.com/chart?" | |
"chs=256x" ,(prin1-to-string (+ 20 (+ 4 (* 42 5)))) | |
"&chbh=4,1" | |
"&cht=bhs" | |
"&chds=0," ,(number-to-string max) | |
"&chd=t:" ,(mapconcat 'prin1-to-string | |
(mapcar 'cdr xs) | |
",") | |
"&chco=" | |
,(mapconcat 'identity (make-list 12 "ffcc33") "|") | |
"|" | |
,(mapconcat 'identity (make-list 30 "9c9c9c") "|") | |
"&chdlp=r" | |
"&chdl=" ,(mapconcat (compose 'w3m-url-encode-string | |
'char-to-string) | |
(subseq (mapcar 'car xs) 0 12) | |
"|") | |
"&chxt=x" | |
"&chxl=0:|" ,(format "%d|%d|%d|%d|%d" | |
0 | |
(/ 3500 4) | |
(* 2 (/ 3500 4)) | |
(* 3 (/ 3500 4)) | |
(* 4 (/ 3500 4))) | |
) | |
"") | |
"\" />" | |
nil))))) | |
(write-scores (subseq (get-scores) 0 42))) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment