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 bar.baz | |
(:require [vertigo.core :as vc] | |
[vertigo.structs :as vs])) | |
;; | |
;; based off of work by Michał Marczyk | |
;; http://stackoverflow.com/questions/8949837/binary-search-in-clojure-implementation-performance | |
;; | |
(set! *warn-on-reflection* true) |
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
; discussed here https://groups.google.com/d/msg/clojure-dev/cWzMS_qqgcM/7IAhzMKzVigJ | |
; nested reduced | |
=> (transduce (comp (take 1)) conj [:a]) | |
[:a] | |
=> (transduce (comp (take 1) (take 1)) conj [:a]) | |
#<Reduced@65979031: [:a]> | |
=> (transduce (comp (take 1) (take 1) (take 1)) conj [:a]) | |
#<Reduced@fcbc8d1: #<Reduced@60bea99a: [:a]>> | |
=> (transduce (comp (take 1) (take 1) (take 1) (take 1)) conj [:a]) |
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
; passes | |
(let [{:keys [bar foo] | |
:or {foo 1 | |
bar (inc foo)}} {}] | |
(assert (= foo 1)) | |
(assert (= bar 2))) | |
; does not compile | |
(let [{:keys [foo bar] | |
:or {foo 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
(defn sig [x] | |
(:sig (meta (resolve x)))) | |
(defmulti type-of (comp type first list)) | |
(defmethod type-of :function [thing & _] (sig thing)) | |
(defmethod type-of java.util.List [expr & a] | |
(conj (map #(type-of % (first a)) (rest expr)) |
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
;; xercise 1 - Cellular Automaton - Cellular automata are fun and fairly easy to implement. | |
;; In this exercise you will build Conway's Game of Life in Clojure with a Swing GUI. | |
;; Kudos For Oregu (author). | |
(ns life | |
(:import (javax.swing JFrame JPanel JButton JTextArea JLabel SwingUtilities JScrollPane WindowConstants) | |
(java.awt Graphics BorderLayout FlowLayout Color Dimension) | |
(java.awt.event MouseListener ActionListener MouseEvent MouseAdapter)) | |
(:use [clojure.contrib.seq-utils :only (flatten)])) |
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 'java.awt.Color) | |
(def *default-color-fraction* 0.2) | |
(def *default-blend-fraction* 0.5) | |
(defn- format-hex [c] | |
(str "#" (format "%02x%02x%02x" | |
(.getRed c) | |
(.getGreen c) |
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 http-client | |
(:import [org.mortbay.jetty.client HttpClient ContentExchange] | |
[java.io ByteArrayInputStream])) | |
(defn request | |
"Takes a request conforming to the Ring specification and sends it to | |
the server. Returns a Ring response." | |
[req] | |
(let [{:keys [scheme server-name server-port uri query-string content-type headers character-encoding request-method body]} req | |
client (HttpClient.) |
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
(defmacro nth-> | |
"Fast lookup into nested vectors. Indices must be ints" | |
[coll [id & idx]] | |
(let [coll (with-meta coll {:tag Indexed})] | |
(if (seq idx) | |
`(nth-> (.nth ~coll ~id) ~idx) | |
`(.nth ~coll ~id)))) |
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
; Copyright (c) Rich Hickey. All rights reserved. | |
; The use and distribution terms for this software are covered by the | |
; Eclipse Public License 1.0 (http://opensource.org/licenses/eclipse-1.0.php) | |
; which can be found in the file epl-v10.html at the root of this distribution. | |
; By using this software in any fashion, you are agreeing to be bound by | |
; the terms of this license. | |
; You must not remove this notice, or any other, from this software. | |
; modified by Chris Houser | |
(require '[clojure.contrib.reflect :as hack]) |
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 pumpkin [op & args] | |
(apply op args)) | |
(pumpkin + | |
1 | |
2 | |
3) | |
;; in emacs do: | |
;; M-x eval-expression |
OlderNewer