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
;; 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) |
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 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"])) |
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
(deftest various-beans-are-readable | |
(testing "that all java.lang beans can be read without error" | |
(doseq [mb (jmx/mbean-names "*:*")] | |
(jmx/mbean mb)))) |
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
; 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! | |
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
; 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]) |
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
(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) |
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. | |
(defn merge-with* | |
"Like merge-with, but handles initial seed value a la reduce. |
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
(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)) |
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. | |
; Author: Frantisek Sodomka, Robert Lachlan |
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
;; 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)])))) |
OlderNewer