Skip to content

Instantly share code, notes, and snippets.

@devn
devn / pedestal-chat-errors
Created March 22, 2013 16:44
Some errors I'm getting when running the sample Pedestal chat application
chat-server.server=> (dev/start)
nil
chat-server.server=> io.pedestal.service.http.sse - {:line 76, :msg "exception sending heartbeat", :throwable #<EofException org.eclipse.jetty.io.EofException>, :stacktrace "org.eclipse.jetty.io.EofException: null\n at org.eclipse.jetty.http.HttpGenerator.flushBuffer (HttpGenerator.java:914)\n org.eclipse.jetty.server.AbstractHttpConnection.flushResponse (AbstractHttpConnection.java:654)\n org.eclipse.jetty.server.Response.flushBuffer (Response.java:1056)\n io.pedestal.service.http.sse$flush_response.invoke (sse.clj:45)\n io.pedestal.service.http.sse$do_heartbeat$fn__3729.invoke (sse.clj:74)\n io.pedestal.service.http.sse$do_heartbeat.invoke (sse.clj:71)\n io.pedestal.service.http.sse$schedule_heartbeart$f__3744.invoke (sse.clj:82)\n clojure.lang.AFn.run (AFn.java:24)\n java.util.concurrent.Executors$RunnableAdapter.call (Executors.java:439)\n java.util.concurrent.FutureTask$Sync.innerRunAndReset (FutureTask.java:317)\n java.util.concurrent.Fu
@devn
devn / getclojure-index-settings.clj
Last active December 15, 2015 07:29
getclojure index settings
getclojure.search> (pprint-code (esi/get-settings "getclojure"))
{:getclojure
{:settings
{:index.analysis.tokenizer.clojure_tokenizer.lowercase "true",
:index.analysis.tokenizer.clojure_tokenizer.pattern
"\\s+|\\(|\\)|\\{|\\}|\\[|\\]",
:index.analysis.analyzer.clojure_code.pattern
"\\s+|\\(|\\)|\\{|\\}|\\[|\\]",
:index.version.created "200499",
:index.number_of_shards "5",
@devn
devn / init.el
Created April 13, 2013 20:28
Simple Clojure Config
;; Make sure we can execute things in our ~/bin DIR
;; This may not be necessary if you're running emacs from the terminal.
(add-to-list 'exec-path (expand-file-name "~/bin"))
(setenv "PATH" (concat (expand-file-name "~/bin") ":" (getenv "PATH")))
;; Packages
(require 'package)
(require 'hippie-exp)
(add-to-list 'package-archives
'("marmalade" . "http://marmalade-repo.org/packages/") t)
(defn remove-first [pred coll]
(let [[xs ys] (split-with (complement pred) coll)]
(concat xs (rest ys))))
(remove-first (partial = 3) [1 2 3 1 2 3])
;;; (1 2 1 2 3)
(remove-first even? [1 2 3 1 2 3])
;;; (1 3 1 2 3)
(def mappings
{:sexp
{:properties
{:id {:type "integer" :store "yes"}
:input {:type "string" :store "yes" :analyzer "clojure_code"}
:output {:type "string" :store "yes" :analyzer "clojure_code"}
:value {:type "string" :store "yes" :analyzer "clojure_code"}}}})
(defn create-getclojure-index []
(when-not (esi/exists? "getclojure")
(defprotocol Coercable
"Coerce Ruby objects to Clojure types"
(clj [this] "Coerce a Ruby object to its Clojure representation"))
(extend-protocol Coercable
org.jruby.RubyString
(clj [this] (str this)))
(extend-protocol Coercable
java.lang.Long
(let [translations {"issue_1" "Issue One"
"issue_2" "Issue Two"
"issue_3" "Issue Three"
"issue_4" "Issue Four"}
items [{:priority "high",:issues ["issue_1" "issue_2"]}
{:priority "low", :issues ["issue_3" "issue_4"]}]]
(map (fn [m] (apply merge m))
(map (fn [{:keys [priority issues]}]
(map (fn [issue]
{(get translations issue), {:priority priority,
@devn
devn / useful.clj
Last active December 20, 2015 07:59
I wish these were in clojure.walk.
(ns clojure.walk.useful
(:require [clojure.walk :refer (postwalk)]))
(defn transform-keys
"Recursively transforms all keys in map `m` which return true for
a function `pred` by applying a function `f` to them."
[m pred f]
(let [func (fn [[k v]] (if (pred k) [(f k) v] [k v]))]
(postwalk (fn [x] (if (map? x) (into {} (map func x)) x)) m)))
(extend-type js/RegExp
cljs.core.IFn
(-invoke ([this s] (re-matches this s))))
(#"foo.*" "foobar") ;=> "foobar"
(#"zoo.*" "foobar") ;=> nil
(filter #".*foo.*" ["foobar" "goobar" "foobaz"]) ;=> ("foobar" "foobaz")
(extend-type js/RegExp
cljs.core.IFn
(-invoke ([this s] (re-matches this s))))
(#"foo.*" "foobar") ;=> "foobar"
(#"zoo.*" "foobar") ;=> nil
(filter #".*foo.*" ["foobar" "goobar" "foobaz"]) ;=> ("foobar" "foobaz")