Skip to content

Instantly share code, notes, and snippets.

View christianromney's full-sized avatar
🏠
Working from home

Christian Romney christianromney

🏠
Working from home
View GitHub Profile
(defn show-routes
"Prints the application's route table"
[]
(print-routes routes))
(defn named-route
"Finds a route by name"
[route-name]
(->> routes
(filter #(= route-name (:route-name %)))
#!/bin/bash
set -e
CHECKOUT=/tmp/clojurescript.git
rm -rf $CHECKOUT
git clone --bare [email protected]:clojure/clojurescript.git $CHECKOUT >/dev/null 2>&1
pushd $(pwd) > /dev/null
cd $CHECKOUT
VERSION=$(git describe --abbrev=0 --tags | sed "s/^r//")
(ns datascript-to-datomic-util
(:require [datascript :as d]))
;;;; a utility to help with a datomic-datascript roundtrip process involving:
;;; 1. export some data from a datomic database and transact into a datascript instance.
;;; 2. perform one or more transactions against datascript.
;;; 3. transact the sum of all changes made against datascript back into datomic in a single tx
;;; this namespace contains two public functions:
;;; listen-for-changes: listen to datascript transactions and build up a record of changes
(def path-element (s/or :key keyword? :index integer?))
(s/def :column/title string?)
(s/def :column/spec (s/or :path (s/+ path-element)
:path+keys (s/cat :path (s/* path-element)
:keys (s/coll-of keyword? []))
:path+fn (s/cat :path (s/* path-element)
:fn fn?)
:fn fn?))
(s/def ::column (s/keys :req [:column/title :column/spec]))
(s/def :grid/title string?)
{:product/type :product.type/ebp
:product/name "Teen Intervene"
:product/surveys
[{:survey/type :survey.type/pre
:survey/title "Pre-Test"
:survey/version 3
:survey/questions
[{:question/id 2030
:question/text "Do you smoke?"
:question/type :question.type/single-option
@christianromney
christianromney / map-reduce.js
Last active May 27, 2016 11:27
Functional Programming example: Implementing `map` in terms of `reduce`
// implementing map in terms of reduce
function count(coll) {
return (typeof coll === "undefined") ? 0 : coll.length;
}
function isEmpty(coll) {
return (0 === count(coll));
}
(def github-repositories-url "https://api.github.com/search/repositories")
(defn repositories-req [language]
(go (let [response (<! (http/get github-repositories-url
{:with-credentials? false
:query-params {"q" (str "language:" language)
"sort" "stars"
"order" "desc"}}))]
;; just *use* the value inside this block...
(println (get-in response [:body :items]))))
# (c) 2016 Mario Cruz
# please credit me if you modify and/or use this code
# not for commercial use
# lots of help from Giles Booth @blogmywiki
# and Christian Romney Twitter: @christianromney
import os
import glob
import json
import random
# (c) 2016 Mario Cruz
# please credit me if you modify and/or use this code
# not for commercial use
# lots of help from Giles Booth @blogmywiki
# and Christian Romney Twitter: @christianromney
import os
import glob
import json
import random
{"title": "Fire and Ice",
"author": "Robert Frost",
"text": ["Some say the world will end in fire,",
"Some say in ice.",
"From what I've tasted of desire,",
"I hold with those who favor fire.",
"But if I had to perish twice,",
"I think I know enough of hate",
"To say that for destruction ice",
"Is also great",