This file contains 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
; minihttpd, tiny barebones clojure web server | |
; http://alan.xen.prgmr.com/ | |
(ns alandipert.minihttpd | |
(:use [clojure.contrib.duck-streams :only (reader writer read-lines spit to-byte-array)] | |
[clojure.contrib.str-utils :only (re-split str-join re-gsub)]) | |
(:import (java.net ServerSocket URLDecoder) | |
(java.io File))) | |
(def codes {200 "HTTP/1.0 200 OK" |
This file contains 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
sealed abstract class Expr { | |
def eval():Double | |
} | |
case class EValue(value:Double) extends Expr { | |
def eval():Double = value | |
} | |
case class ESum(a:List[Expr]) extends Expr { | |
def eval():Double = a.foldLeft(0.0)(_+_.eval) |
This file contains 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
(import '(org.jivesoftware.smack XMPPConnection)) | |
(use '[clojure.set :only (difference)]) | |
(defn connect [jid pass] | |
(doto (XMPPConnection. (last (.split jid "@"))) | |
.connect | |
(.login (first (.split jid "@")) pass))) | |
(defn ls [] |
This file contains 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
; Project euler problem 138 | |
; http://projecteuler.net/index.php?section=problems&id=138 | |
(use 'clojure.contrib.math) | |
(defn height [base leg] | |
(sqrt (- (expt leg 2) (expt (/ base 2) 2)))) | |
(defn base [leg height] | |
(* 2 (sqrt (- (expt leg 2) (expt height 2))))) |
This file contains 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
(defn running-sums1 [nums] | |
(rest (reduce #(conj %1 (+ (last %1) %2)) [0] nums))) | |
(defn running-sums2 [nums] | |
(rest (reverse (reduce #(cons (+ (first %1) %2) %1) '(0) nums)))) | |
(def num-runs 1000) | |
(def range-ceil 100) | |
(time (dotimes [_ num-runs] |
This file contains 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
(ns cljutils.math | |
"Functions for doing stuff") | |
(defn- powers-of [n] | |
"For given base n, create lazy sequence of powers of n" | |
(iterate #(* % n) 1)) | |
(defn- char-range [& limits] | |
"Given an even number of limit characters, creates an inclusive character sequence" | |
(apply concat (map (fn [[start end]] |
This file contains 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
# Clojure syntax highlighting for GNU source-highlight | |
# rocks with SHJS | |
# http://gist.github.com/265810 | |
comment start ";" | |
include "number.lang" | |
vardef SPECIALCHAR = '\\.' |
This file contains 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
if (! this.sh_languages) { | |
this.sh_languages = {}; | |
} | |
sh_languages['clojure'] = [ | |
[ | |
[ | |
/;/g, | |
'sh_comment', | |
1 | |
], |
This file contains 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
;; Y combinator and fib in clojure | |
;; see also: | |
;; http://www.fatvat.co.uk/2009/04/understanding-y-combinator.html | |
;; ftp://publications.ai.mit.edu/ai-publications/pdf/AIM-453.pdf p72 | |
(defn Y [f] | |
((fn [g] | |
(f (g g))) | |
(fn [g] | |
(fn [x] |
This file contains 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
(import '(javax.swing JLabel JButton JPanel JTextField JFrame) | |
'(java.awt.event ActionListener) | |
'(java.awt GridLayout)) | |
(defmacro on-action [component event & body] | |
`(. ~component addActionListener | |
(proxy [java.awt.event.ActionListener] [] | |
(actionPerformed [~event] ~@body)))) | |
(defn celsius [] |