Skip to content

Instantly share code, notes, and snippets.

@Jared314
Jared314 / TreeIterator.clj
Last active December 22, 2015 04:39
Improving the Clojure-Git Interface with a Nice Facade
(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]}))
@Jared314
Jared314 / ohm.clj
Last active December 20, 2015 14:09
(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 December 20, 2015 01:19
Clojure core.async example 4
(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 December 20, 2015 01:18
Clojure core.async example 3
(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 July 21, 2013 04:33
Clojure core.async example 2
(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 July 20, 2013 02:46
Clojure core.async example 1
(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 December 17, 2015 18:49
Storing a parse tree, or AST, in a git repository with Clojure and JGit
(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 06:53
Using Instaparse and Enlive for simple parsing and tree transformation / rewriting
(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 December 14, 2015 11:28
A get-indent function to get the amount of indention for the next line of clojure code, based on the previous line.
(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 December 14, 2015 04:29
Basic CSS3 Selector to Clojure Enlive vector format converter
;[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]