Skip to content

Instantly share code, notes, and snippets.

@dazld
dazld / Makefile
Created March 18, 2018 10:56
find multiple entry points and build a bundle into the directory of each
build:
@find . -name "index.js" -not -path "*/node_modules/*" | xargs -I @@ bash -c '{ browserify @@ -o `dirname "@@"`/bundle.js; }'

Sure, let's say you're writing a web app that at some point needs to look up users by id and password. You could implement this as a function:

(defn get-user [db id pw]
  ...query the db...)

But the problem as you've noticed is that it's hard to test this function, because you have to somehow either actually hit a database during a test, or you have to redef the function. Instead I say we should make formal contracts in our applications. So we'd implement a protocol:

(defprotocol IDb
 (get-user [this id pw]))
@dazld
dazld / _LIVERELOAD_README.md
Last active September 7, 2018 15:04
barebones livereload

running

  • clone this gist  git clone https://gist.github.com/0c19582a14b8d657649af01d2c23f0e9.git my-project
  • cd my-project
  • npm install
  • npm run start

making a build

  • npm run build will output a bundle.js file to the directory suitable for publishing to static hosting etc. might want to run it through uglify or something too ;)
@dazld
dazld / Makefile
Created November 30, 2017 08:35
make ... file
ifndef (${BAZ})
BAZ := "/baa"
endif
FOO := "blabalabl"
vvvv:
@echo "${BAZ} ${FOO} asdiajsd"
foo.text: BLA=bla
(ns itag.test.handler
(:require [clojure.test :refer :all]
[clojure.spec.alpha :as spec]
[clojure.spec.gen.alpha :as gen]
[clojure.pprint :refer :all]
[ring.mock.request :refer :all]
[itag.handler :refer :all]))
(def id-regex #"^[0-9]*$")
(def skills (gen/elements ["java" "js" "clojure" "c" "python" "bash" "sql"]))
@dazld
dazld / datomic-reset-attributes.clj
Created May 13, 2017 08:15 — forked from favila/datomic-reset-attributes.clj
Datomic transaction functions to "reset" attributes: i.e. make them have a post-transaction value you specify without having to enumerate the retractions.
(def tx-fns
[{:db/ident :db.fn/reset-attribute-values
:db/doc "Transaction function which accepts an entity identifier, attribute identifier
and set of values and expands to any additions and retractions necessary to
make the final post-transaction value of the attribute match the provided
values. Attribute values must be scalars.
If multiple values are provided on a cardinality-one attribute you will get a
datom conflict exception at transaction time."
:db/fn (d/function
@dazld
dazld / news-votes.clj
Created March 18, 2017 10:26 — forked from stuarthalloway/Datomic News Updates
Datomic update examples against a social news database
;; Datomic example code
;; demonstrates various update scenarios, using a news database
;; that contains stories, users, and upvotes
;; grab an in memory database
(use '[datomic.api :only (q db) :as d])
(def uri "datomic:mem://foo")
(d/create-database uri)
(def conn (d/connect uri))
let am7c = "[a4, c4, e4, g5]"
d1 $ density 5 $ rarely (iter 3) $ every 2 ( # n am7c) $ struct "[x(5,8,2) x(3,8)]/5" $ n gm7
--
import Data.Maybe
let inhabit :: [(String, Pattern a)] -> Pattern String -> Pattern a
inhabit ps p = unwrap' $ (\s -> fromMaybe silence $ lookup s ps) <$> p
@dazld
dazld / index.js
Last active February 9, 2017 05:56
const ma = require('moving-average')(10000);
const log = (a)=>{ console.log(a); return a}
let run = true;
log(process.version)
function count(){
const now = Date.now();
return new Promise(function(res, rej){
const vals = Array(9e4).fill('').map(_ => Math.random());
vals.reduce((t,v) => {return t + v}, 0);
let skip = 5;
let img = 502;
const canvas = document.querySelector('#thing');
const ctx = canvas.getContext('2d')
const h = window.innerHeight;
const w = window.innerWidth;
canvas.setAttribute('width', w);
canvas.setAttribute('height', h);