Skip to content

Instantly share code, notes, and snippets.

(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)
; 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])
; 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
(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))
;; 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)]))
@chrisschreiner
chrisschreiner / color-utils.clj
Created July 11, 2010 12:00
Color utilities for CSS
(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)
(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.)
(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))))
@Chouser
Chouser / avoid-force-print.clj
Created September 21, 2010 13:38
Avoid forcing lazy seqs when printing
; 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])
@fogus
fogus / emagic.clj
Created January 7, 2011 18:22
how to make your own forms indent properly in emacs with clojure-mode
(defn pumpkin [op & args]
(apply op args))
(pumpkin +
1
2
3)
;; in emacs do:
;; M-x eval-expression