Skip to content

Instantly share code, notes, and snippets.

import {reconcile} from './utils/reconcile.mjs'
import {bar} from './bar-component.mjs'
import {baz} from './baz-component.mjs'
export const app = () => {
/// This is a component; it creates a node, sets some invariant properties on
/// that node (e.g., handler functions, sometimes CSS classes, &c.).
/// => any => Object
@jeffmcmahan
jeffmcmahan / class-like-functions.js
Last active November 18, 2019 15:05
Heritable, stateful functional units (i.e., class-like things)
// A pattern for creating objects with public, private, and static methods
// without relying on bad parts of javascript.
const myType = id => {
// Creates a silly type that acts like a class.
// => Object
const token = Math.random()
const hmac = ghmac(token)
### Keybase proof
I hereby claim:
* I am jeffmcmahan on github.
* I am jeffmcmahan (https://keybase.io/jeffmcmahan) on keybase.
* I have a public key ASC3jAtlxxlcBa5i4OLHdTL4NXExKExGX0pP5PFXofrsngo
To claim this, I am signing this object:
@jeffmcmahan
jeffmcmahan / sql.js
Created April 25, 2017 21:21
SQL template tag
'use strict'
/**
* Maps the given value to a value expressible in SQL.
* @param {*} val
* @return {String}
*/
function sqlValue(val) {
if (val === null) return null
if (val === "'null'") return 'null'
@jeffmcmahan
jeffmcmahan / html.js
Created April 25, 2017 21:12
HTML template tag
'use strict'
/**
* Print null/undefined and arrays to strings sensibly.
* @param {*} val
* @param {String} str
* @return {String}
*/
function htmlValue(val, str) {
if (val === null || typeof val === 'undefined') return ''
@jeffmcmahan
jeffmcmahan / jss-default-unit-values.html
Last active July 18, 2016 18:04
Generates default units for jss-default-unit
<!doctype html>
<html>
<head>
<title>Default Props</title>
</head>
<body>
<script>
'use strict'
@jeffmcmahan
jeffmcmahan / recursiveReaddirSync.js
Last active September 22, 2015 19:39
Recursively, synchronously, read files from a directory with nodejs.
var recursiveReaddirSync = function (topDir) {
function readdir (dir) {
fs.readdirSync(dir).filter(function (pth) {
return !/^\./.test(pth)
}).forEach(function (pth) {
pth = path.join(dir, pth)
if (fs.lstatSync(pth).isDirectory()) readdir(pth)
else files.push(pth)
})
}
@jeffmcmahan
jeffmcmahan / recursiveReaddir.js
Last active August 29, 2015 14:00
Recursively, asynchronously read directories in Node.js
// Calling reAsyncReaddir("file/path", callback) passes an object composed of
// a "files" array and a "directories" array (=keys) to your callback.
var fs = require("fs");
var results = {
"files" : [],
"directories" : []
};
var counts = {
"fsObjects" : 0,