Skip to content

Instantly share code, notes, and snippets.

Avatar

Stuart Halloway stuarthalloway

View GitHub Profile
View Indexed
;; 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)
View InternalReduce
;; 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"]))
View broad brush
(deftest various-beans-are-readable
(testing "that all java.lang beans can be read without error"
(doseq [mb (jmx/mbean-names "*:*")]
(jmx/mbean mb))))
View profit
; 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!
View run-compressing-seqs.clj
; 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])
View Test from the REPL
(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)
View merge-with plus initval
; 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.
View pallet scribblings
(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))
View multimethod testing wip
; 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 Apr 25, 2011
Generic clojure encoding map for rummage
View gist:941069
;; 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)]))))