Skip to content

Instantly share code, notes, and snippets.

View whostolebenfrog's full-sized avatar

Ben Griffiths whostolebenfrog

View GitHub Profile
@tomconnors
tomconnors / datomic_util.cljc
Created October 22, 2018 19:27
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,
@favila
favila / datomic-mysql-bootstrap.sql
Created January 22, 2015 17:49
Better MySQL bootstrap setup for datomic's datomic_kvs table
-- Optimized MYSQL schema for datomic
-- Unfortunately the bin/sql/mysql-*.sql bootstrapping files for datomic are not
-- very good, and can actually cause failures if not adjusted.
-- One symptom of this is the following error:
-- SQL Error (1071): Specified key was too long; max key length is 767 bytes.
-- Reported here: https://support.cognitect.com/entries/28462168-MySQL-Caveats
-- This is caused by the default collation for the `id` column possibly being
@timruffles
timruffles / bloom-filter.clj
Created October 28, 2013 11:42
bloom fiter done with @dgt79 at Software Craftsmanship UK 2013 Just a learning version, emphasises readability, not optimial for so many reasons (using persistent vectors, reason #1 :) )
(ns bloom-filters.core
(:require [clojure.core :refer :all]))
(defn bloom-filter
[hashes vector]
{:hashes hashes :vector vector})
(defn- bit-index [h value vector]
"takes a hashing function, an input to the hash function and a vector; returns the index of the bucket in the vector."
#!/bin/bash
ROOT_STAT=`stat -c %d:%i /proc/1/root/`
VERBOSE="verbose"
set -e
fatal()
{
echo "error: $1" 1>&2
exit 1
@cgrand
cgrand / fcoll.clj
Created June 27, 2013 13:55
functional collections for the bristol workshop
;; Clojure 1.5.1
=> 1
1
=> (require '[clojure.core.reducers :as r])
nil
=> (use 'clojure.repl)
nil
=> (doc r/fold)
-------------------------
clojure.core.reducers/fold
@timmc
timmc / fact.swear.clj
Last active July 5, 2022 13:34
Factorial in Clojure without using alphanumeric characters
;; It all started here: http://clojure-log.n01se.net/date/2011-04-06.html#19:04
(#((% (+(*))) %) ;; call arg 1 with all args
[;; data
(+ (*)(*)(*)(*)(*)(*)(*))
;; main fn -- simulate 'if' with map lookup and closures
#(({(+) (% (+(*)(*)))} ;; if zero return 'then' clause
(% (+)) ;; dispatch on first arg
(% (+(*)(*)(*)))) ;; call 'else' clause (n not found in map)
%)