Skip to content

Instantly share code, notes, and snippets.

View stuarthalloway's full-sized avatar

Stuart Halloway stuarthalloway

View GitHub Profile
;; licensed like Clojure, copyright 2010 by Stuart Halloway
(ns
#^{:author "Stuart Halloway"
:doc "Protocols for type-aware collection functions"}
clojure.contrib.collections
(:import [java.util ArrayList Collection]))
(declare slice do-slice)
;; Copyright 2010 Relevance, Inc. Same license as Clojure http://clojure.org. You know the drill.
(ns clojure.core.protocols
(:refer-clojure :exclude [reduce nth count]))
#_(def array-classes
(map
#(Class/forName %)
["[Ljava.lang.Object;"
"[B" "[F" "[I" "[D" "[Z" "[J" "[C"]))
(deftest various-beans-are-readable
(testing "that all java.lang beans can be read without error"
(doseq [mb (jmx/mbean-names "*:*")]
(jmx/mbean mb))))
; response to http://toinfinity.wordpress.com/2010/05/01/does-groovy-know-you-are-seeing-clojure
; tell the gnomes! phase two is (map - closing-prices)!
; prior to 1.2, reductions is in clojure.contrib.seq-utils
(->> (reductions min closing-prices) ;; lowest prices at each point
(map - closing-prices) ;; possible profit at each point
(apply max)) ;; profit!
; a clojure 1.2 impl for
; http://blogs.tedneward.com/2010/05/06/Code+Kata+Compressing+Lists.aspx
(def group (partial partition-by identity))
(defn runnify
[coll]
(->> (group coll) (map #(vector (count %) (first %)))))
; into pairs
(runnify [4, 4, 4, 4, 2, 2, 2, 3, 3, 2, 2, 2, 2, 1, 1, 1, 5, 5])
(do
(use 'clojure.test)
(defn re-test [ns]
(remove-ns ns)
(require :reload-all ns)
(run-tests ns)))
;; pick a namespace
(re-test 'clojure.test-clojure.other-functions)
; 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.
(defn merge-with*
"Like merge-with, but handles initial seed value a la reduce.
(do (require 'pallet.repl)
(pallet.repl/use-pallet)
(use 'pallet.crate.automated-admin-user)
(use 'pallet.crate.java)
(use 'pallet.crate.git)
(use 'pallet.crate.ssh))
(defn demo-amazon
[id pass]
(def service (compute-service "ec2" id pass :log4j :ssh))
; 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.
; Author: Frantisek Sodomka, Robert Lachlan
@stuarthalloway
stuarthalloway / gist:941069
Created April 25, 2011 19:47
Generic clojure encoding map for rummage
;; needs rummage to use as-set instead of as-collection...
(def clojure-encoding-map
(assoc enc/all-strings
:encode (fn encode
([k] (pr-str k))
([k v]
[(pr-str k) (pr-str v)]))
:decode (fn
([k] (read-string k))
([k v] [(read-string k) (read-string v)]))))