Skip to content

Instantly share code, notes, and snippets.

@vickychijwani
vickychijwani / ai-class.py
Created November 12, 2011 10:37 — forked from sumodx/ai-class.py
Download lecture videos of ai-class, with HTTP proxy and basic resume support
#!/usr/bin/env python
# -*- coding: utf-8 -*-
__author__ = "Deepak.G.R."
__credits__ = "Sumod Hajela"
__license__ = 'Public Domain'
"""
usage:
Go to command line and type
(defn-e f [x y]
([_ 0] (a/< x 3))
([_ 2] (a/<= 3 x) (a/< x 6))
([_ 4] (a/<= 6 x)))
(defmacro match
"shitty pattern matching macro
Example:
(def eval [exp]
(match exp
(:var v) v
(:abstraction arg body) (create-procedure arg body)
(:application operator operand) (operator operand)))
(defn alternate
"Take two collections and return a lazy seq of alternating items
from the first coll, then from the second etc until one of the
collections is runs out of elements. Unlike interleave, the first
collection may contain one element more than the second, which will
be included in the resulting laz seq."
[c1 c2]
(lazy-seq
(when-first [x c1]
(cons x (alternate c2 (rest c1))))))
@budu
budu / gist:782221
Created January 16, 2011 22:32
Prototype a new Marginalia parser
(use '(clojure.contrib [reflect :only [get-field]])
'(clojure [string :only [join replace]]))
(deftype Comment [content])
(defmethod print-method Comment [comment ^String out]
(.write out (str \" (.content comment) \")))
(defn read-comment [reader semicolon]
(let [sb (StringBuilder.)]
@pepijndevos
pepijndevos / parsistent_heap.clj
Created January 15, 2011 17:13
A persistent heap implemented in Clojure
(ns persistent-heap)
(defn swap [heap idx idy]
(assoc heap idx (get heap idy) idy (get heap idx)))
(defn children [idx]
(let [idx (inc (* idx 2))
idy (inc idx)]
[idx idy]))
(ns slouchdb)
; Fast scalable in-memory concurrent NoSQL database
(def db (ref {:bob {:age 59 :sex :male}
:bill {:age 17 :sex :male}
:mary {:age 28 :sex :female}}))
;; Views ;;
(defn total-age []
(defmacro arrow
([val]
val)
([val x & xs]
(if (symbol? x)
(list* 'user/arrow (list x val) xs)
(list* 'user/arrow
(list* (first x) val (rest x))
xs))))
@mattpodwysocki
mattpodwysocki / testing-linq.clj
Created January 2, 2011 21:03
Testing LINQ
user=> (import 'System.Linq.Enumerable)
System.Linq.Enumerable
user=> (def r1 (Enumerable/Range 1 10))
#'user/r1
user=> (seq r1)
(1 2 3 4 5 6 7 8 9 10)
user=> (def r2 (. Enumerable (generic Repeat Int32) 3 4))
#'user/r2
user=> (seq r2)
(3 3 3 3)
; The New Year in Snowflakes
; A Clojure doodle by Chouser
(import '(java.awt Color Graphics Frame RenderingHints))
(defonce draw-agent (agent nil))
(defonce halt (atom false))
(defmacro ui-thread [& body]
`(javax.swing.SwingUtilities/invokeAndWait (fn [] ~@body)))