Skip to content

Instantly share code, notes, and snippets.

View noprompt's full-sized avatar
The choice to have discipline is a programmer's worst enemy.

Joel Holdbrooks noprompt

The choice to have discipline is a programmer's worst enemy.
View GitHub Profile
noprompt / slurp.clj
Created February 19, 2014 04:52
How to use slurp from ClojureScript
(ns foo.core
(:refer-clojure :exclude [slurp]))
(defmacro slurp [file]
(clojure.core/slurp file))
;; In CLJS
(ns bar.core
(:require [foo.core :include-macros true :refer [slurp]]))
noprompt / cypher-dsl.clj
Last active March 24, 2023 15:57
A Clojure Cypher query DSL compatible with neocons.
(ns noprompt.cypher
(:require [clojure.string :as str]
[ :as cy]
[clojure.walk :as walk])
(:import java.lang.StringBuilder))
;; Example usage:
;; Query:
(start {:n (node [3 1])}
(defn mix*
"Helper function for mix."
{:private true}
(if (seq colls)
(if (seq (first colls))
(lazy-seq (cons (ffirst colls)
(mix* (conj (subvec colls 1)
(rest (first colls))))))
(recur (subvec colls 1)))
noprompt / project.clj
Last active December 19, 2020 14:38
Demonstration using Garden to recreate the Semantic Grid framework.
(defproject semantic-gs "0.1.0-SNAPSHOT"
:dependencies [[org.clojure/clojure "1.5.1"]
[compojure "1.1.5"]
[garden "0.1.0-beta5"]
[hiccup "1.0.3"]]
:plugins [[lein-ring "0.8.5"]]
:ring {:handler semantic-gs.handler/app}
{:dev {:dependencies [[ring-mock "0.1.5"]]}})
(require '[meander.epsilon :as m])
(m/rewrite (read-string (slurp "project.clj"))
(defproject _ _ . !key !value ...)
(m/cata [:DEPS_EDN (m/map-of !key !value)])
[:DEPS_EDN {:dependencies ?dependencies
:profiles ?profiles
:source-paths !paths
:resource-paths !paths}]
noprompt / z.clj
Last active April 22, 2020 17:59
Z Algorithm
(defn longest-prefix-at
[s i]
(let [max-k (. s length)]
(or (last (for [j (range 1 max-k)
:let [k (+ i j)]
:when (<= k max-k)
:let [s1 (subs s 0 j)
s2 (subs s i k)]
:while (= s1 s2)]
noprompt / deps.edn
Last active May 22, 2019 16:33
Implementing L-System examples from the "Algorithmic Beauty of Plants" with Meander
{:paths ["src"]
:deps {org.clojure/clojure {:mvn/version "1.10.0"}
org.clojure/clojurescript {:mvn/version "1.10.439"}
org.clojure/test.check {:mvn/version "0.10.0-alpha3"} {:mvn/version "0.3.0"}
meander/delta {:mvn/version "0.0.85"}
quil/quil {:mvn/version "3.0.0"}}
:aliases {:test {:extra-paths ["test"]
:extra-deps {org.clojure/test.check {:mvn/version "0.10.0-alpha3"}
com.cognitect/test-runner {:git/url ""
(:require [ :as r.match]
[ :as r.syntax]
[ :as r.util]))
(defn genmut
{:tag :mut
:symbol (gensym "*m__")})
(defn swap
"Swap the elements at positions `i` and `j` in `v`."
{:private true}
[v i j]
(-> v
(assoc i (nth v j))
(assoc j (nth v i))))
;; SEE:
(defn permutations
(ns scratch
[ :as json]
[clojure.string :as string]
[meander.strategy.alpha :as r]
[meander.match.alpha :as r.match]))
(def service-2-json
(slurp "")))