Skip to content

Instantly share code, notes, and snippets.

@tomconnors
tomconnors / script.sh
Created October 13, 2023 15:01
Use -J flag with clojure cli
clojure -J-Dconf=local/config-overrides ... rest of command
@tomconnors
tomconnors / app.hooks.cljs
Created November 17, 2020 15:35
Integration of re-frame and react hooks.
(ns app.hooks
(:require
;; A lib provided by react to make these types of integrations easier:
["use-subscription" :as react.use-subscription]
[re-frame.interop :as rf.interop]
[re-frame.core :as rf]
[helix.hooks :as h.hooks] ; cljs wrapper of the react hooks api
))
(defn- maybe-dispose! [^clj reaction]
(ns ansible.core
(:require [clojure.java.shell :as sh]
[clojure.string :as str]
[cheshire.core :as cheshire]
[clojure.java.io :as io])
(:import (java.io File)
(com.fasterxml.jackson.core JsonGenerator)
(java.util Base64)
(java.security MessageDigest MessageDigest$Delegate)))
@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,
@tomconnors
tomconnors / example.js
Created July 5, 2016 14:13
shows event handler wrapping
var
// "appstate" object
obj = {},
// data-level onChange handler - doesn't deal w/ the dom.
onChange = function(newValue){ obj.attr = newValue; },
// start function that deals with the dom and calls the data-level event handler
start = function(handler){
$(".selector").on("change", function(e){
e.preventDefault();
handler(e.target.value);
@tomconnors
tomconnors / gist.clj
Created January 22, 2016 22:21
Multiple References to a Connection Pool (perhaps incorrect?)
(def datasources (agent {}))
(defn make-datasource [db-conf]
(send-off datasources
(fn [datasources]
(if-let [ds-conf (get datasources db-conf)]
(update-in datasources [db-conf :count] inc)
(assoc datasources
db-conf {:count 1
:ds (conn-pool/make-datasource db-conf)}))))
@tomconnors
tomconnors / om-tutorial.cljs
Last active December 21, 2015 18:26
An attempt at adding routes to the Om Components, Identity, and Normalization tutorial
(ns om-tutorial.core
(:require [goog.dom :as gdom]
[om.next :as om :refer-macros [defui]]
[om.dom :as dom]))
(enable-console-print!)
(def init-data
{:list/one [{:name "John" :points 0}
{:name "Mary" :points 0}
@tomconnors
tomconnors / and a stacktrace for your viewing pleasure
Last active August 29, 2015 13:56
project.clj that's threatening my sanity.
Exception in thread "main" java.lang.NoClassDefFoundError: clout/core/Route
at composur.routes.auth__init.load(Unknown Source)
at composur.routes.auth__init.<clinit>(Unknown Source)
at java.lang.Class.forName0(Native Method)
at java.lang.Class.forName(Class.java:270)
at clojure.lang.RT.loadClassForName(RT.java:2098)
at clojure.lang.RT.load(RT.java:430)
at clojure.lang.RT.load(RT.java:411)
at clojure.core$load$fn__5018.invoke(core.clj:5530)
at clojure.core$load.doInvoke(core.clj:5529)
@tomconnors
tomconnors / gist:8460406
Created January 16, 2014 18:25
Handling keyboard input with React and clojurescript
;;; I'm not using Om yet because I've got a lot of code using Pump and just haven't made the transition,
;;; but the principles are all the same. So you'll see Pump-specific code here.
(def code->key
"map from a character code (read from events with event.which)
to a string representation of it.
Only need to add 'special' things here."
{13 "enter"
37 "left"
38 "up"
@tomconnors
tomconnors / gist:7668570
Created November 27, 2013 00:05
Init of main component of cljs + react
;;; definition of Layout component - the root component for the application
(defr Layout
[component prop _]
[:div.nav-slide-wrap {:on-click handle-body-clicks}
;; a sub component - it's passed the entire `prop` even though it
;; doesn't need all of it. Eventually it'll be smart for me to only pass the necessary data to components.
[Nav prop]
[:div {:class-name (str "main-body " (if (:user prop) "signedIn" "notSignedIn"))}
[Header prop]
[Content prop]