Skip to content

Instantly share code, notes, and snippets.

@thickey
thickey / flatmap.clj
Last active December 22, 2023 05:42
Example in Clojure of round-tripping a hierarchical map to/from a flattened version
(ns flatmap
(:require [clojure.string :as str]))
(def default-delimiter \$)
;; via https://stackoverflow.com/questions/31704704/depth-first-tree-traversal-accumulation-in-clojure/31709202#31709202
(defn traverse [t]
(letfn [(traverse- [path t]
(when (seq t)
@thickey
thickey / cider+deps.md
Last active March 9, 2023 17:47
Cider jack-in with tools.deps

Instructions

Note: you must have Cider version 0.18.*

For pure tools.deps (non-lein)

In deps.edn

{:paths ["src" "resources"]
 :deps {org.clojure/clojure {:mvn/version "1.9.0"}}
@thickey
thickey / ember-precompile.js
Created June 25, 2012 19:55 — forked from zilkey/ember-precompile.js
Precompile .handlebars templates with node js
var fs = require('fs');
var vm = require('vm');
var emberjs = fs.readFileSync('public/javascripts/vendor/ember-0.9.5.min.js', 'utf8');
var templatesDir = 'templates';
var destinationDir = 'public/javascripts/templates';
function compileHandlebarsTemplate(templatesDir, fileName) {
var file = templatesDir + '/' + fileName;
@thickey
thickey / deps+nrepl.md
Last active October 26, 2018 19:57 — forked from solussd/deps+nrepl.md
nrepl + deps.edn quickstart

Instructions

  1. Add nrepl server dep to deps.edn :dev alias extra deps
org.clojure/tools.nrepl {:mvn/version "0.2.12"}
  1. create dev/user.clj containing the following:
(ns user
 (:require [clojure.tools.nrepl.server :as nrepl]))
@thickey
thickey / README.md
Last active October 14, 2017 17:10
Handling multiple results from Clojure with SQL the includes temp tables

Handling multiple results from SQL that includes temp tables.

NB! this is using clojure.java.jdbc v0.6.1, as we have performance issues w/ 0.7.x

Although this gist was very helpful when all statements return results, this is what is ultimately needed to properly traverse the intermediate reults that return nothing (e.g. temp tables).

Keybase proof

I hereby claim:

  • I am thickey on github.
  • I am thickey (https://keybase.io/thickey) on keybase.
  • I have a public key whose fingerprint is 0ED7 4731 F2C7 F5EE 5635 8BB7 818A EC24 E433 4A5D

To claim this, I am signing this object:

@thickey
thickey / pom2proj.clj
Created March 7, 2012 01:36
Convert Maven pom.xml file to Lein project.clj
(ns pom2proj
(:require [clojure.xml :as xml]
[clojure.zip :as zip]
[clojure.java.io :as io]
[clojure.data.zip.xml :as zx])
(:use [clojure.pprint :only [pprint]]))
(defn- text-attrs
[loc ks]
(map (fn [k]
@thickey
thickey / nrepl-eval-form-to-repl.el
Last active December 28, 2015 17:09
A little bit of elisp for outputting the form in the repl buffer in front of output. (a la Tim Baldridge's Clojure/conj 2013 core.async presentation).
;; Works with nrepl-0.1.6.el
(defun my-form-printing-handler (buffer form)
(lexical-let ((form form))
(nrepl-make-response-handler buffer
(lambda (buffer value)
(nrepl-emit-result buffer (format "%s" form) t)
(nrepl-emit-result buffer (format "%s" value) t))
(lambda (buffer out)
(nrepl-emit-output buffer out t))
@thickey
thickey / rps.clj
Last active December 19, 2015 14:29 — forked from puredanger/rps.clj
;; An implementation of the rock-paper-scissors variant -
;; rock-paper-scissors-lizard-spock - based on Alex Miller's core.async
;; implementation.
;; - http://tech.puredanger.com/2013/07/10/rps-core-async/
;; - https://gist.github.com/puredanger/5965883
;; - https://github.com/relevance/labrepl/blob/master/src/solutions/rock_paper_scissors.clj
;; - http://www.imdb.com/title/tt1256039/quotes?item=qt0493730
(require 'clojure.core.async :refer :all)
(ns dinesman
(:refer-clojure :exclude [==])
(:use clojure.core.logic))
(defne aboveo [x y l]
([_ _ [y . r]]
(membero x l))
([_ _ [z . r]]
(!= z y)
(aboveo x y r)))