Skip to content

Instantly share code, notes, and snippets.

;; Because in formal logic, ∀x.P(x) = ¬∃x.¬P(x)
(d/q '[:find ?id
:in $ [?interest ...]
:where
[?a :account/id ?id]
(not-join [?a ?interest]
[?a :account/interest ?i]
(not [(= ?i ?interest)]))])
;; It is harder to understand when you bind interest as above if you
@favila
favila / pdftree.clj
Created September 27, 2018 22:24
create a clojure-data-structure representation of a pdf document (from pdfbox) just for visibility into the pdf's structure
(with-open [pdf-document (PDDocument/load (clojure.java.io/file THE-FILE))]
(let [doc (.getDocument pdf-document)
getobj (fn [^COSObject x]
[:pdf.type/object (.getObjectNumber x) (.getGenerationNumber x)])
visit (fn [^COSBase x ^ICOSVisitor vis]
(if (.isDirect x)
(if (instance? COSObject x)
(getobj x)
(.accept x vis))
(cond
@conan
conan / url-spec.clj
Last active December 30, 2019 16:32
(require
'[cemerick.url :as url]
'[clojure.spec.alpha :as s]
'[clojure.spec.gen.alpha :as sgen])
(defn non-empty-string-alphanumeric
[]
(sgen/such-that #(not= "" %)
(sgen/string-alphanumeric)))
@Deraen
Deraen / edn.cljx
Last active August 6, 2023 06:51
Transit / edn date/datetime serialisers
(ns metosin.common.edn
#+clj
(:require [clj-time.format :as f])
#+cljs
(:require [cljs-time.format :as f]
cljs.reader)
#+clj (:import [org.joda.time DateTime LocalDate]))
;;
;; #DateTime tagging
@favila
favila / gen-transactor-props.sh
Created February 2, 2015 21:15
Generate a datomic transactor property file for google cloud mysql storage engine with SSL and client authentication
#!/bin/sh
# Generate datomic transactor properties file and command line arguments.
# Specific scenario: using Google Mysql Cloud storage with SSL and client
# authentication.
OUTFILE='transactor.properties'
#TRANSACTOR_ARGS_FILE='transactor-arguments.txt'
@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
@teepark
teepark / btree.py
Created September 9, 2010 22:45
a pure-python B tree and B+ tree implementation
import bisect
import itertools
import operator
class _BNode(object):
__slots__ = ["tree", "contents", "children"]
def __init__(self, tree, contents=None, children=None):
self.tree = tree