Skip to content

Instantly share code, notes, and snippets.

View app.mjs
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 Nov 18, 2019
Heritable, stateful functional units (i.e., class-like things)
View class-like-functions.js
// 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)
View gist:7f229b46fe307bacdf6d044ab5c8f96e
### 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 Apr 25, 2017
SQL template tag
View sql.js
'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 Apr 25, 2017
HTML template tag
View html.js
'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 Jul 18, 2016
Generates default units for jss-default-unit
View jss-default-unit-values.html
<!doctype html>
<html>
<head>
<title>Default Props</title>
</head>
<body>
<script>
'use strict'
@jeffmcmahan
jeffmcmahan / recursiveReaddirSync.js
Last active Sep 22, 2015
Recursively, synchronously, read files from a directory with nodejs.
View recursiveReaddirSync.js
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 Aug 29, 2015
Recursively, asynchronously read directories in Node.js
View recursiveReaddir.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,