Skip to content

Instantly share code, notes, and snippets.

(defn merge-keyed
"Returns a map that consists of the rest of the maps conj-ed onto
the first. If a key occurs in more than one map, the mapping(s)
from the latter (left-to-right) will be combined with the mapping in
the result by calling (f key val-in-result val-in-latter)."
[f & maps]
(when (some identity maps)
(let [merge-entry (fn [m e]
(let [k (key e) v (val e)]
(if (contains? m k)
(ns spec-context
(:require [clojure.spec :as s]))
(defmulti node-spec ::fancy?)
(defmethod node-spec true [_] ::fancy-node)
(defmethod node-spec :default [_] ::boring-node)
(s/def ::node (s/multi-spec node-spec ::fancy?))
(s/def ::fancy? boolean?)
(def ^:dynamic foo [])
(def ^:dynamic bar)
(defn state []
{#'foo foo, #'bar bar})
(defn helper []
(uses bar)
@brandonbloom
brandonbloom / input.clj
Last active December 8, 2016 00:09
meta-js
(let [n 5]
(js/eval
(iife
(let x 1)
(for [(let y 1) (<= y n) (++ y)]
(set! x (* x y)))
(return x)
)))
(defproject .......
:cljsbuild {
:builds [
{:id "dev"
:source-paths ["src/"]
:compiler {:main "lev.client"
:asset-path "js"
:output-to "resources/public/js/lev.js"
:output-dir "resources/public/js"}
"nREPL-worker-0" #14 daemon prio=5 os_prio=31 tid=0x00007fdec7d93800 nid=0x5703 runnable [0x000070000313c000]
java.lang.Thread.State: RUNNABLE
at clojure.lang.PersistentHashMap.valAt(PersistentHashMap.java:152)
at clojure.lang.PersistentHashMap.valAt(PersistentHashMap.java:156)
at clojure.lang.RT.get(RT.java:750)
at clojure.spec$map_spec_impl$reify__13776.conform_STAR_(spec.clj:782)
at clojure.spec$conform.invokeStatic(spec.clj:150)
at clojure.spec$dt.invokeStatic(spec.clj:731)
at clojure.spec$dt.invokeStatic(spec.clj:727)
at clojure.spec$merge_spec_impl$reify__13969$fn__13970.invoke(spec.clj:1140)
{:user {:deploy-repositories [["clojars" {:url "https://clojars.org/repo"
:creds {:username "USERNAME" :password "PASSWORD"}
:sign-releases false}]]}}
@brandonbloom
brandonbloom / test.lua
Created June 25, 2016 22:48
Thread locals in Lua
local thread = require 'thread'
local x = thread.variable(0)
print(x())
x(5)
print(x())
local itr = coroutine.wrap(function()
for i = 1, 10 do
let Database = require('jseg').default;
let schema = require('./schema');
class Builder {
constructor() {
this._jseg = new Database(schema);
this._roots = {};
}
// Consider a "relative" pointer to some offset within
// a buffer with some base address.
struct RelativePtr {
void* base;
int offset;
}
// Now consider some operation to compute the relative address: