Skip to content

Instantly share code, notes, and snippets.

View jtzeng's full-sized avatar

Justin T. Zeng jtzeng

  • Champaign, IL
View GitHub Profile
package main
import (
"fmt"
"github.com/go-martini/martini"
"io/ioutil"
"log"
"math/rand"
"net/http"
"os"
(defun list-sample (lst &optional (amt 1 amt-supplied-p))
"Choose a random element or n random elements from the collection."
(labels ((sample-inner (lst amt res)
(if (not (and lst (plusp amt)))
(if (and (= (length res) 1) (not amt-supplied-p))
(car res)
res)
(let ((elem (elt lst (random (length lst)))))
(sample-inner (remove elem lst :count 1) (1- amt)
(nconc res (list elem)))))))
;; Color numeric constants.
(make-face 'font-lock-number-face)
(set-face-foreground 'font-lock-number-face "#cf6a4c")
(setq font-lock-number-face 'font-lock-number-face)
(defvar font-lock-number
(concat "\\b[0-9]+\\(_+[0-9]+\\)*"
"\\(\\.[0-9]+\\(_+[0-9]+\\)*\\)?"
"\\([eE][+-]?[0-9]+\\(_+[0-9]+\\)*\\)?"
"[dDfFlLuU]?\\b"))
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>Ansi 0 Color</key>
<dict>
<key>Blue Component</key>
<real>0.0</real>
<key>Green Component</key>
<real>0.0</real>
@jtzeng
jtzeng / itoa.rb
Last active December 30, 2015 14:19
require 'test/unit'
def itoa(n)
s = ''
neg = n < 0
n = -n if neg
while true
r = n % 10
n /= 10
s = ('0'.ord + r).chr << s
#!/usr/bin/python
# ISB AQI checker.
# TODO: Better error checking.
import time
import traceback
INTERVAL = 60
TABLE = [
['Good', 0, 12.0, 0, 50],
(defun rot13 (s)
"Rotate each character by thirteen places."
(map 'string (lambda (c)
(let ((n (char-code c)))
(cond ((and (char-not-lessp c #\n) (char-not-greaterp c #\z))
(code-char (- n 13)))
((and (char-not-lessp c #\a) (char-not-greaterp c #\m))
(code-char (+ n 13)))
(t c)))) s))
(defconstant +pb-site+ "http://www.powerball.com/powerball/winnums-text.txt")
(defun pb-values ()
(multiple-value-bind (body sts h uri stream close reason)
(drakma:http-request +pb-site+)
(cdr (split-sequence:split-sequence #\Newline body))))
(defun occurs (lines &optional (occur (make-hash-table)))
(dolist (line lines)
(when (plusp (length line))
;; Knight's tour using Warnsdorff's rule.
;; https://en.wikipedia.org/wiki/Knight%27s_tour
(defconstant +board-sz+ 8)
(defparameter *board* (make-array `(,+board-sz+ ,+board-sz+) :initial-element 0))
(defconstant +knight-moves+
'(#(1 -2) #(2 -1) #(2 1) #(1 2) #(-1 2) #(-2 1) #(-2 -1) #(-1 -2)))
@jtzeng
jtzeng / .ccl-init.lisp
Created November 3, 2013 15:53
ccl w/ linedit
;;; The following lines added by ql:add-to-init-file:
#-quicklisp
(let ((quicklisp-init (merge-pathnames "quicklisp/setup.lisp" (user-homedir-pathname))))
(when (probe-file quicklisp-init)
(load quicklisp-init)))
(when (interactive-stream-p *standard-input*)
(ql:quickload "linedit")
(funcall (intern "INSTALL-REPL" :linedit)))