Skip to content

Instantly share code, notes, and snippets.

/*
/-------------\
/ \
/ \
/ \
| XXXX XXXX |
| XXXX XXXX |
| XXX XXX |
\ X /
--\ XXX /--
(ns scorewords
(:use [clojure.test]))
(defn score-sub [words]
(map (fn [[word n]] [word (if (> n 3)
0
(/ 1 n))]) (partition 2 (interleave words (iterate inc 2)))))
(defn score-words
([term words base]
load(["lib/underscore.js"]);
load(["lib/json2.js"]);
var fact = ['def', 'fact', ['fn', ['n'],
['if', ['<=', 'n', 2],
'n',
['*', 'n', ['fact', ['-', 'n', 1]]]]]]
var infix = ['+', '-', '*', '/', '<', '>', '<=', '>='];
(defn files-in-dir
([& dirs]
(map files-in-dir dirs))
([dir]
(let [dirFile (File. dir)]
(.list dirFile)))
([dir suffix]
(let [dirFile (File. dir)
fileFilter (proxy [FilenameFilter] []
(accept [dir name] (.endsWith name suffix)))]
@alandipert
alandipert / glob.clj
Created March 28, 2010 00:04 — forked from jkk/glob.clj
(set! *warn-on-reflection* true)
(defn bfs-seq [branch? children root]
"Same as tree-seq but walks the tree breadth-first instead
of depth-first."
(let [walk (fn walk [queue]
(when-let [node (peek queue)]
(lazy-seq
(cons node (walk (into (pop queue)
(when (branch? node)
Imap.prototype.next: ((id, fmt) ->
prefix: (for i in [0...fmt.replace(/0/g, "").length]
(-> this.charAt(Math.random()*this.length))
.call("ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789")
).join("")
fmt: fmt.replace(/X/g, "")
return ( ->
id: ++id % (parseInt(fmt.replace(/0/g, "9")) + 1)
(ns org.jtornadoweb.cljhttputils
(:use [clojure.contrib.monads :only (domonad maybe-m)]
[clojure.contrib.str-utils2 :only (split)])
(:gen-class
:name org.jtornadoweb.CljHttpUtils
:methods [[parseQueryString [String] java.util.HashMap]]
:main false))
(defn- parse-qs
[uri]
@alandipert
alandipert / gist:1144670
Created August 14, 2011 07:28 — forked from micha/gist:997056
Euler project problem #1
; Euler problem #1. Sum of integers between 1 and N which are
; divisible by i, j, k, ..., or l.
;
; The sum 1+2+3+...+n = (n^2 + n)/2, call this sum-range(n).
;
; Then the sum of i+2i+3i+...+qi = i * sum-range(floor(n/i)), where
; qi is the greatest multiple of i such that i <= n.
;
; For n=20, f(3,5) involves summing the rows in a table:
;
@alandipert
alandipert / config.ru
Created January 5, 2012 18:36
Deploy static sites to heroku and use heroku caching
use Rack::Static,
:urls => ['/css', '/images'], # put directories here, files will get served for free
:root => "public"
run lambda { |env|
[
200,
{ 'Content-Type' => 'text/html', 'Cache-Control' => 'public, max-age=86400' },
File.open('public/index.html', File::RDONLY) # Point this at the starting file
]
@alandipert
alandipert / lithp.rb
Created January 26, 2012 00:19 — forked from fogus/lithp.rb
class Lisp
def initialize
@env = {
:label => lambda { |(name,val), _| @env[name] = val },
:quote => lambda { |sexpr, _| sexpr[0] },
:car => lambda { |(list), _| list[0] },
:cdr => lambda { |(list), _| list.drop 1 },
:cons => lambda { |(e,cell), _| [e] + cell },
:eq => lambda { |(l,r), _| l == r },
:if => lambda { |(cond, thn, els), ctx| eval(cond, ctx) ? eval(thn, ctx) : eval(els, ctx) },