Skip to content

Instantly share code, notes, and snippets.

@tomconnors
tomconnors / gist:5861093
Last active December 18, 2015 23:19
limiting array fields on client side w/ meteor
Posts.find({}, {
fields: {
upvoters: {
$elemMatch: {
id: userId //userId is the current user's id.
}
}
}
});
@tomconnors
tomconnors / gist:6583595
Created September 16, 2013 17:15
an alternate api for the Meteor template lifecycle
//==============================================================================
// template utilities
// making Meteor's template api a bit less, well, awful
//==============================================================================
define([
"lib/ext"
],
function(ext){
"use strict";
@tomconnors
tomconnors / gist:7423559
Last active December 28, 2015 01:49
Layout and Views
<!--Whole application shares this markup: -->
<body>
<ul id="nav">
<li>Home</li>
<li>Other Page</li>
</ul>
<div id="content"></div>
</body>
<!-- Home Page 'focus' -->
@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]
@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 / 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 / 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 / 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 / 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 / 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,