Skip to content

Instantly share code, notes, and snippets.

View wildermuthn's full-sized avatar

Nate Wildermuth wildermuthn

View GitHub Profile
@wildermuthn
wildermuthn / datascript-subscription.cljs
Last active September 14, 2015 09:50
Experimenting with subscribing to datascript db updates in a way that at least loosely parallels a query.
(ns sb-db.experiments
(:require [datascript :as d]
[cljs.core.match :refer-macros [match]])
(:require-macros [sb.macros :refer [logc]]))
;;; Experiment to see if we can subscribe to database updates using core.match, in order to re-query database and get new data that will be (eventually) passed to a reagent component
;;; Initialize
(def schema {:show {}
(defn- build-handle-tx
"On db update, put updated entity onto update-ch"
[ch db]
(fn
[{:keys [tx-data]}]
(let [id (-> tx-data first first)
e (ds/entity @db (-> tx-data first first))]
(if e (go (>! ch e))))))
(defn get-updates
@wildermuthn
wildermuthn / ganymede.cljs
Created September 2, 2015 22:26
Using generated styles with reagent and garden
(def page (make :div))
(def title (make :h1))
(def article (make :p))
(def ul (make :ul {:color "gray"}))
(select title {:color "red"})
(select [page article] {:color "green"})
(select [page ul :li] {:font-weight "bold"})
(def list-select (select [page ul]))
(ns fncards.db.utils
(:require [fncards.db.api :as db-api]
[datascript :as ds]
[cljs.pprint :refer [pprint]]
[cljs.core.async :as async :refer [chan <! >! put! take! timeout mult tap pub sub]])
(:require-macros [cljs.core.async.macros :refer [go go-loop]]
[fncards.macros :refer [log logr logd logc]]))
;; Channel and Subscription
@wildermuthn
wildermuthn / stacktrace.txt
Created May 11, 2015 22:28
Stacktrace using cljs.jar and clojurescript quickstart
~/Sites/nowthis-2 => $ rlwrap ./start.sh
Compiling client js ...
Waiting for browser to connect ...
Watch compilation log available at: out/watch.log
To quit, type: :cljs/quit
cljs.user=> (require '[sb.core :as sb] :reload)
nil
[Acljs.user=(require '[sb.core :as sb] :reload)
nil
cljs.user=> (+ 1 1)
@wildermuthn
wildermuthn / 0-angular-filter.html
Last active August 29, 2015 14:16
New Ramda Switch
<input ng-model="filter.search" type="text" />
<select ng-model="filter.category" ng-options="c for c in categories" />
@wildermuthn
wildermuthn / noswitch.html
Last active August 29, 2015 14:16
no need for switches
<input class="input-search" type="text" ng-model="filter.search" name="" id="" value="" />
var request = require('request')
, cheerio = require('cheerio')
, async = require('async')
, format = require('util').format;
var reddits = [ 'ImagesOfSpace' ]
, concurrency = 2;
async.eachLimit(reddits, concurrency, function (reddit, next) {
var links = {};
@wildermuthn
wildermuthn / files.js
Last active August 29, 2015 14:02
nodejs rendering of an object, injected straight into Angulart
// in app.js
app.get('/app/js/services/config.js', function(req, res) {
routes.getConfig(req, res, configs.angular);
});
// in routes/index.js
exports.getConfig = function(req, res, angular){
res.setHeader('Cache-Control', 'no-cache');
res.render('config', {
clientShortName: angular.clientShortName,
@wildermuthn
wildermuthn / formItem.js
Created April 22, 2014 22:20
for morgan formItem directive
'use strict';
angular.module('crossroadsDonateApp')
.directive('formItem', ['$compile', '$http', '$templateCache', function($compile, $http, $templateCache, $rootScope) {
var rootScope = $rootScope;
var getTemplate = function(contentType) {
var templateLoader,
baseUrl = 'views/',
templateMap = {
text: 'form-item-text.html',