Skip to content

Instantly share code, notes, and snippets.

(defn use-atom
"Creates a subscription to the given atom and will put its state inside a setState.
Returns the current state."
[a]
(let [[state set-state] (use-state @a)]
(react/useEffect
(fn []
(let [k (-> gensym str keyword)]
(add-watch a k (fn [k r old-state new-state]
(set-state new-state)))
@adz5a
adz5a / jsx.clj
Last active September 21, 2019 14:35
(s/def ::element
(s/cat :type (s/or :htmltag keyword?
:component symbol?)
:props (s/? (s/map-of keyword? any?))
:children (s/* (s/or :text-node string?
:element ::element))))
(s/def ::component
(s/cat :name symbol?
:props-signature (s/spec (s/cat :props any?))
: error TS2322: Type '() => void' is not assignable to type 'Ca│~
llInterface'.
Type 'void' is not assignable to type 'number'.
/home/adza/work/ts-playground/node_modules/typescript/lib/tsc.js:2062
throw e;
^
Error: Debug Failure. False expression.
at computePositionOfLineAndCharacter (/home/adza/work/ts-playground/node_mod
@adz5a
adz5a / fiddle.js
Last active July 27, 2017 14:50
stream-fold
"use strict";
const xs = require("xstream").default;
const fromDiagram = require("xstream/extra/fromDiagram").default;
const delay = require("xstream/extra/delay").default;
const get = () => {
console.log("called");
/**
* Sample of serverside generation of Highcharts using an extension to jsdom in node.js.
*
* Usage:
* npm install jsdom
* npm install highcharts
* node highcharts-jsdom
*/
/* eslint-env node */
@adz5a
adz5a / better-nodejs-require-paths.md
Created March 11, 2016 19:38 — forked from branneman/better-nodejs-require-paths.md
Better local require() paths for Node.js

Better local require() paths for Node.js

Problem

When the directory structure of your Node.js application (not library!) has some depth, you end up with a lot of annoying relative paths in your require calls like:

var Article = require('../../../models/article');

Those suck for maintenance and they're ugly.

Possible solutions