Skip to content

Instantly share code, notes, and snippets.

@hchbaw
Created October 20, 2009 16:23
Show Gist options
  • Save hchbaw/214388 to your computer and use it in GitHub Desktop.
Save hchbaw/214388 to your computer and use it in GitHub Desktop.
(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))))
"&amp;chbh=4,1"
"&amp;cht=bhs"
"&amp;chds=0," ,(number-to-string max)
"&amp;chd=t:" ,(mapconcat 'prin1-to-string
(mapcar 'cdr xs)
",")
"&amp;chco="
,(mapconcat 'identity (make-list 12 "ffcc33") "|")
"|"
,(mapconcat 'identity (make-list 30 "9c9c9c") "|")
"&amp;chdlp=r"
"&amp;chdl=" ,(mapconcat (compose 'w3m-url-encode-string
'char-to-string)
(subseq (mapcar 'car xs) 0 12)
"|")
"&amp;chxt=x"
"&amp;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