Skip to content

Instantly share code, notes, and snippets.

using System;
class Base
{
public virtual string Method()
{
return "base method";
}
}
;; manual
(def fuel (atom 10))
(loop []
(when (zero? (swap! fuel dec))
(fail "out of fuel!"))
(recur))
;;; Handlers.
;; Approximates effect handlers without unwinding the stack.
;; Captures thread bindings so as to avoid "open recursion" between handlers.
;; Also binds `super` to bubble effect up to the next handler.
(def ^:dynamic super)
(defn bind-handler [var f]
(let [bindings (assoc (get-thread-bindings) #'super @var)]
(fn [& args]
export class Signal<T> {
private _promise: Promise<T>;
private _resolve: (x: T) => void;
constructor() {
this._makePromise();
}
_makePromise() {
this._promise = new Promise((resolve, reject) => {
type Base = {
x: number,
};
type Derived = Base & {
y: number,
};
let to = <T>(x: T): T => x;
let steps = [[0, t => t * 2], [0.5, t => t * 5]];
let x;
for (let i = 0; i < steps.length; i++) {
let [k, f] = steps[i];
if (k <= t) {
x = f(t);
break;
}
}
;; Step 1) Produce a build with :advanced optimizations. Tell me the size of the .js file.
;; Step 2) Run `gzip` on your output .js file and tell me the size of the .js.gz file.
;; Step 3) Apply this monkey patch:
(in-ns 'cljs.closure)
(import '[com.google.javascript.jscomp VariableRenamingPolicy PropertyRenamingPolicy])
(def wrapped-set-options set-options)
(defn set-options [opts ^CompilerOptions compiler-options]
(ns blah
(:require [com.walmartlabs.lacinia.schema :as schema]
[com.walmartlabs.lacinia.util :refer [attach-resolvers]]
[com.walmartlabs.lacinia :as lacinia]))
(defn batch [ctx id]
(prn 'batch id)
(swap! (::loader ctx)
(fn [loader]
(if (contains? (:cache loader) id)
package mvt
// See https://www.mapbox.com/vector-tiles/specification/
// and https://github.com/mapbox/vector-tile-spec/tree/master/2.1
// Zero value is ready to use.
type GeomBuffer struct {
geom []uint32
begun bool // True if a command sequence has begun.
start int // Index of the command header.
count uint32 // Number of commands written so far in this sequence.
(s/def ::m1 (s/keys :req [::a ::b]))
(s/def ::a int?)
(s/def ::b int?)
(s/def ::x int?)
(s/def ::y int?)
(s/def ::ab (s/keys :req [::a ::b]))
(s/def ::xy (s/keys :req [::x ::y]))
(s/def ::m (s/merge ::ab (s/nilable ::xy)))
(s/exercise ::m)