Skip to content

Instantly share code, notes, and snippets.

@Jared314
Jared314 / TreeIterator.clj
Last active Dec 22, 2015
Improving the Clojure-Git Interface with a Nice Facade
View TreeIterator.clj
(ns gitter.TreeIterator
(:import [org.eclipse.jgit.lib Repository FileMode]
[org.eclipse.jgit.treewalk WorkingTreeIterator WorkingTreeIterator$Entry WorkingTreeOptions]
[java.io ByteArrayInputStream])
(:gen-class :extends org.eclipse.jgit.treewalk.WorkingTreeIterator
:init init2
:post-init postinit
:state state
:constructors {[org.eclipse.jgit.lib.Repository Object] [org.eclipse.jgit.treewalk.WorkingTreeOptions]
[org.eclipse.jgit.lib.Repository Object org.eclipse.jgit.treewalk.WorkingTreeIterator] [org.eclipse.jgit.treewalk.WorkingTreeIterator]}))
View ohm.clj
(ns ohm
(:require [clojure.string :as string]
[clojure.java.io :refer [as-file]])
(:import [java.io File]))
(defrecord Leaf [nss declares fns])
(defn parse-value [value]
value)
@Jared314
Jared314 / async4.clj
Last active Dec 20, 2015
Clojure core.async example 4
View async4.clj
(ns async4
(:require [clojure.core.async :as async]
[clojure.core.async.lab :as lab]))
(defn inmate [name c]
(async/go
(async/<! c)
(println name " released")))
(def alice (partial inmate "Alice"))
@Jared314
Jared314 / async3.clj
Last active Dec 20, 2015
Clojure core.async example 3
View async3.clj
(ns async3
(:require [clojure.core.async :as async]))
(defn alice [c message]
(async/>!! c message))
(defn person [name c]
(async/go
(let [message (async/<! c)]
(println name " received: " message)
@Jared314
Jared314 / async2.clj
Created Jul 21, 2013
Clojure core.async example 2
View async2.clj
(ns async2
(:require [clojure.core.async :as async]
[clojure.core.async.lab :as lab]))
(defn make-fb-group [& members]
(apply lab/broadcast members))
(defn alice [c]
(async/>!! c "Dave Davenson's House @ 10pm"))
@Jared314
Jared314 / async1.clj
Created Jul 20, 2013
Clojure core.async example 1
View async1.clj
(ns async1
(:require [clojure.core.async :as async]))
(defn alice [c]
(async/>!! c "Carol Carolson's House @ 10pm"))
(defn bob [c]
(async/go (println "Bob received: " (async/<! c))))
(let [phonenumber-555-555-9292 (async/chan)]
@Jared314
Jared314 / TreeIterator.clj
Last active Dec 17, 2015
Storing a parse tree, or AST, in a git repository with Clojure and JGit
View TreeIterator.clj
(ns gittree.TreeIterator
(:import [org.eclipse.jgit.lib Repository FileMode]
[org.eclipse.jgit.treewalk WorkingTreeIterator WorkingTreeIterator$Entry WorkingTreeOptions]
[java.io ByteArrayInputStream])
(:gen-class :extends org.eclipse.jgit.treewalk.WorkingTreeIterator
:init init2
:post-init postinit
:state state
:constructors {[org.eclipse.jgit.lib.Repository Object] [org.eclipse.jgit.treewalk.WorkingTreeOptions]
[org.eclipse.jgit.lib.Repository Object org.eclipse.jgit.treewalk.WorkingTreeIterator] [org.eclipse.jgit.treewalk.WorkingTreeIterator]}))
@Jared314
Jared314 / instaparse-enlive-parsing.clj
Created May 19, 2013
Using Instaparse and Enlive for simple parsing and tree transformation / rewriting
View instaparse-enlive-parsing.clj
(ns test1
(:require [instaparse.core :as insta]
[net.cgrand.enlive-html :as enlive]
[clojure.walk :as walk]))
(defn render [nodes]
(walk/postwalk #(if (and (map? %) (:tag %))
(with-meta (hash-map (:tag %) (:content %)) (:attrs %))
%) nodes))
@Jared314
Jared314 / get-indent.clj
Last active Dec 14, 2015
A get-indent function to get the amount of indention for the next line of clojure code, based on the previous line.
View get-indent.clj
(def closing {\) \(
\} \{
\] \[})
(def opening [\( \{ \[])
(defn zero-or-more [x] (if (>= x 0) x 0))
(defn indent-exception? [[a b]] (not (and (= a \') (= b \())))
; warning: Very basic clojure language parsing. It does not handle strings.
(defn reverse-parse
([data] (reverse-parse data []))
@Jared314
Jared314 / gist:5028617
Last active Dec 14, 2015
Basic CSS3 Selector to Clojure Enlive vector format converter
View gist:5028617
;[org.jodd/jodd-lagarto "3.4.2"]
;(:import [jodd.csselly CSSelly CssSelector Combinator Selector$Type])
(defn format-attr-selector [x]
(case (.getName x)
"id" (str "#" (.getValue x))
"class" (str "." (.getValue x))
""))
(defn format-selector [x]