Skip to content

Instantly share code, notes, and snippets.

View olivergeorge's full-sized avatar

Oliver George olivergeorge

  • Tasmania, Australia
View GitHub Profile
@olivergeorge
olivergeorge / queries.clj
Last active September 6, 2017 11:05
Spike to see what an alias aware SQL query DSL might look like. Make joins easier to add. Deal with munging/demunging column names. Boils down to a HoneySQL query and a row-fn demunger.
(s/def ::columns (s/coll-of qualified-keyword? :type set?))
(s/def ::from (s/coll-of simple-keyword? :type set?))
(s/def ::aliases (s/map-of simple-keyword? simple-keyword?))
(s/def ::left-join (s/map-of simple-keyword? ::where))
(s/def ::where (s/coll-of ::condition))
(s/def ::condition (s/cat :op #{:=} :args (s/+ any?)))
(def my-query1
{::columns #{:SITE/NAME :BL/NAME}
::from #{:SITE}
@olivergeorge
olivergeorge / require-macros-example.md
Created July 19, 2017 01:28
Example of self requiring macros in cljs
(def example-data (atom {:args #{} :ret #{}}))
(defn record-example [k v]
(js/console.debug ::record-example [k v])
(swap! example-data update k conj v)
v)
@olivergeorge
olivergeorge / replacing_fks.clj
Created March 16, 2017 22:11
Using JDBC metadata to find and replace fks in a database. Would allow data massaging like "merging records".
(ns condense.replacing-fks
(:require [clojure.inspector]
[clojure.pprint :refer [pprint]]
[clojure.java.jdbc :as j]
[clojure.string :as string]
[clojure.spec :as s]
[honeysql.core :as sql]
[honeysql.helpers :as hh]))
(defn db-primary-keys
(def reg
{::doc '(keys [::id ::title ::summary ::authors])
::doc2 '(keys [::title])
::title :field/text
::summary :field/text
::authors '(and (coll-of ::author) :field/many)
::author '(keys [::id ::name])
:field/text (fn [data] {:value data :type :text})
:field/many (fn [data] {:value data :type :many})})
@olivergeorge
olivergeorge / memoizer
Last active February 23, 2017 05:43
memoize with strategies on CLJS
(ns kotka.memoizer)
; Published by Meikel Brandmeyer on 15 March 2010, 23:53.
; https://kotka.de/blog/2010/03/memoize_done_right.html
; Minor tweaks for CLJS use
; Untested!
(defn current-time-millis
[]
@olivergeorge
olivergeorge / pdb-instrument.md
Last active February 19, 2017 22:06
Random thoughts on clojurescript debugging

This strikes me as a handy debugging pattern:

(defonce dbg-db (atom {}))

(defn log [k v]
  (swap! dbg-db update-in [k] conj v)
  (js/console.log k v)
 v)

Context:

Currently writing a function spec is a bit like verbose destructing - it can require as much code as the function itself.

Reduced effort in spec'ing functions would be nice.

Spec encourages namespaced keywords to have one "type". That means within your program any map with that key can be assumed to have a predictable type.

A similar convention is to have one meaning for a variable name in a specific namespace. Nothing in spec about that... it's just less confusing.

@olivergeorge
olivergeorge / om-to-reagent.cljs
Created December 18, 2016 05:52
Aim: See if there's a way to avoid rewriting existing om views in move to re-frame. Method: 1. Workout what om api calls are needed. 2. Try and implement them using reagent. Results: Incomplete. Note: this code includes bad ideas.
(ns om.core
(:require [reagent.core :as r]))
(defn component? [x])
(defprotocol IInitState (init-state [_]))
(defprotocol IRender (render [this]))
(defprotocol IRenderState (render-state [this state]))
(defprotocol IDisplayName (display-name [this]))
(defprotocol IWillReceiveProps (will-receive-props [this next-props]))
(->> (for [{:keys [table_name]} (db-tables db {:schemaPattern "AFM"})]
[table_name (db-query db (str "select * from " table_name))])
(into {})
(spit "db.edn"))