Skip to content

Instantly share code, notes, and snippets.

View claj's full-sized avatar

Linus Ericsson claj

  • Sweden
  • 16:29 (UTC +02:00)
View GitHub Profile
@claj
claj / datomic_util.cljc
Created September 3, 2024 08:34 — forked from tomconnors/datomic_util.cljc
kc datomic util
(ns kc.datomic
"Datomic utility functions
Usage Notes:
Some functions in this namespace take sequences of facts and return them modified in some way. Some up-front modifications are useful for those functions, like replacing all map-form facts with vector-form facts. In order to avoid doing these modifications repeatedly to same the same set of facts (which would be harmless but wasteful), two versions of these functions exist: a \"safe\" version that does those up-front modifications, and an \"unsafe\" version that expects those modifications to already have been performed. The unsafe versions are named like the safe ones, but with a single quote appended.
TODO:
- consider implementing all fns that branch based on operation as multimethods
These fns mostly support :db/add, :db/retract :db.fn/retractEntity, :db.fn/cas,
@claj
claj / core.clj
Last active March 17, 2016 10:38
state in go-loop
(ns world.core
(:require [clojure.core.async :refer [go chan >! <! <!! put! timeout close!]]))
(defn apply-to-fsm
[[state _] event]
(case [state event]
[:init :create] [:running [:allocate :run]]
[:running :stop] [:stopped [:stop]]
[:running :start] [:running []]
;; claj's solution to Reverse Interleave
;; https://4clojure.com/problem/43
(fn [a b] (map #(take-nth b (drop % a)) (range b)))
;; claj's solution to Set Intersection
;; https://4clojure.com/problem/81
(fn [a b] (set (filter a b)))
;; claj's solution to Anagram Finder
;; https://4clojure.com/problem/77
(fn [a]
(set
(map set
(filter #(< 1 (count %))
(vals
(group-by
(fn [b] (reduce conj #{} b))
@claj
claj / alephNoir.clj
Created October 3, 2011 06:37 — forked from ibdknox/alephNoir.clj
aleph and noir
(require '[noir.server :as server])
(use 'noir.core 'aleph.http 'lamina.core)
(defn async-response [response-channel request]
(enqueue response-channel
{:status 200
:headers {"content-type" "text/plain"}
:body "async response"}))
(defpage "/" [] "hey from Noir!")