Skip to content

Instantly share code, notes, and snippets.

@micha
micha / rpc.clj
Created March 17, 2014 15:45
Datomic transactor function that works like Clojure's `swap!` function.
{:db/id #db/id[:db.part/db]
:db/doc "Works like clojure.core/swap!, basically."
:db/ident :swap!
:db/fn #db/fn {:lang "clojure"
:params [db id k expr args]
:code "(let [f (if-not (string? expr)
(resolve expr)
(eval (read-string expr)))
e (datomic.api/entity db id)
v (apply f (concat [(get e k 0)] args))]
@micha
micha / build.clj
Created April 25, 2014 16:38
Boot tasks: run tasks in the background, etc.
(def bgs
"List of tasks running in other threads that will need to be cleaned up before
boot can exit."
(atom ()))
;; cleanup background tasks on shutdown
(-> (Runtime/getRuntime)
(.addShutdownHook (Thread. #(doseq [job @bgs] (future-cancel job)))))
(deftask once
@micha
micha / gist:37b02eb356094f8611f9
Created July 12, 2014 19:29
Hoplon discourse site code markdown
I've been using the triple-backquote method and it works pretty well. For example:
```
(map inc [1 2 3])
```
Check out [the source for this post](https://gist.github.com/micha/37b02eb356094f8611f9) on GitHub.
@micha
micha / text-macro.clj
Created August 22, 2014 14:50
text= macro
(defmacro text= [form]
`(tailrecursion.javelin/cell= ~(interpol8 form)))
@micha
micha / cli_util.clj
Last active August 29, 2015 14:06
Clojure macro defines a macro which evaluates expressions with some bindings.
(defmacro defbound [sym bindings]
`(defmacro ~sym [& body#]
`(let ~'~bindings ~@body#)))
(comment
user=> (defbound with-xy [x 100 y 200])
#'user/with-xy
user=> (with-xy (+ x y))
300
)
@micha
micha / .vimrc
Created November 15, 2014 18:06
set nocompatible " be iMproved, required
filetype off " required
" set the runtime path to include Vundle and initialize
set rtp+=~/.vim/bundle/Vundle.vim
call vundle#begin()
" alternatively, pass a path where Vundle should install plugins
"call vundle#begin('~/some/path/here')
" let Vundle manage Vundle, required
@micha
micha / .vimrc
Created November 15, 2014 21:17
set nocompatible " be iMproved, required
filetype off " required
" set the runtime path to include Vundle and initialize
set rtp+=~/.vim/bundle/Vundle.vim
call vundle#begin()
" alternatively, pass a path where Vundle should install plugins
"call vundle#begin('~/some/path/here')
" let Vundle manage Vundle, required
;; -*- mode: clojure; -*-
(set-env!
:src-paths #{"src/clj" "src/cljs"}
:rsc-paths #{"resources"}
:update :always
:dependencies '[[org.clojure/clojure "1.7.0-alpha4"]
[org.clojure/core.async "0.1.346.0-17112a-alpha"]
[com.taoensso/timbre "3.3.1-1cd4b70"]
[http-kit "2.1.19"]
(require 'boot.pod 'boot.repl)
(boot.pod/add-dependencies
(assoc-in (boot.core/get-env)
[:dependencies] '[[cider/cider-nrepl "RELEASE"]]))
(swap! boot.repl/*default-middleware* conj 'cider.nrepl/cider-middleware)
CREATE EXTENSION IF NOT EXISTS "uuid-ossp";
DROP TABLE IF EXISTS owner CASCADE;
DROP TABLE IF EXISTS pet_breed CASCADE;
DROP TABLE IF EXISTS breed;
DROP TABLE IF EXISTS pet;
CREATE TABLE owner (
id SERIAL PRIMARY KEY,
name varchar(20),