Skip to content

Instantly share code, notes, and snippets.

Isiah Meadows isiahmeadows

Block or report user

Report or block isiahmeadows

Hide content and notifications from this user.

Learn more about blocking users

Contact Support about this user’s behavior.

Learn more about reporting abuse

Report abuse
View GitHub Profile
@isiahmeadows
isiahmeadows / mini-css-in-js-framework-docs.md
Last active May 1, 2019
Mini CSS-in-JS framework in under 50 lines of ES6 code
View mini-css-in-js-framework-docs.md

A mini CSS-in-JS framework

It exports two functions:

  • renderToString(styles) - Render the CSS to a string. (This has no DOM dependency, and it omits the @charset - that's for you to set.)
  • renderToDOM(styles) - Render the CSS to the DOM.

Note that renderToString omits any charset - the user should specify that before emitting.

Styles are specified as follows:

@isiahmeadows
isiahmeadows / mithril-fontawesome.js
Created Feb 2, 2019
Mithril port of react-fontawesome
View mithril-fontawesome.js
// This is a direct API port of https://github.com/FortAwesome/react-fontawesome
// to Mithril, with a few optimizations for faster vnode creation and more
// efficient normalization. It's also combined into a single UMD file and
// written to support a pure ES5 environment without transpiling. It's less than
// 200 lines of code excluding this long introductory comment, and is about
// 1.3KB min+gzip.
//
// Here's a few example vnodes:
//
// ```js
View id-generate.js
"use strict"
// Creates a `generate` function using an alphabet, for optimally small IDs
// if you can only use certain characters. This could be useful for file name
// generators, minifiers, among many others. You *do* need to expand letter
// ranges, though.
module.exports = alphabet => {
const charTable = [...new Set(Array.from(alphabet, x => `${x}`))]
let counter = 0
if (charTable.length < 2) {
@isiahmeadows
isiahmeadows / classnames-object.js
Created Dec 16, 2018
`classnames`, but emitting an object instead of a string.
View classnames-object.js
var hasOwn = {}.hasOwnProperty
function writeClasses() {
for (var i = 0; i < arguments.length; i++) {
var arg = arguments[i]
if (!arg) continue
if (typeof arg === 'string' || typeof arg === 'number') {
this[arg] = true
} else if (typeof arg === 'string') {
@isiahmeadows
isiahmeadows / 0-react-hooks.jsx
Created Oct 29, 2018
React if they went with a new language rather than an embedded DSL
View 0-react-hooks.jsx
// This is a rough port of their TodoMVC app, using their Hooks API
import React, { useRef, useState, useEffect, useMemo } from "react"
import { render } from "react-dom"
function uuid() {
let uuid = ""
for (let i = 0; i < 32; i++) {
if (i === 8 || i === 12 || i === 16 || i === 20) uuid += "-"
View uncached-load.js
var Module = require("module")
function requireUncached(file, baseDir) {
// Hack: hijack Node's internal resolution algorithm to require the file
// as if from a fake module in the correct base directory. It also will
// avoid several bugs with the `resolve` module (Node's is necessarily
// more stable).
var dirname = path.resolve(baseDir)
var m = new Module(path.join(dirname, "dummy.js"))
@isiahmeadows
isiahmeadows / mithril-remove-node-from-dom.js
Created Aug 28, 2018
Recast Mithril node removal code
View mithril-remove-node-from-dom.js
function removeNodeFromDOM(vnode) {
var parent = vnode.dom.parentNode
if (parent != null) {
var count = vnode.domSize
if (count != null && count > 1) {
while (--count) parent.removeChild(vnode.dom.nextSibling)
}
parent.removeChild(vnode.dom)
}
}
@isiahmeadows
isiahmeadows / weak-collections.js
Last active Jul 30, 2018
Weak maps and weak sets in terms of private symbols
View weak-collections.js
const _wmSymbol = Symbol.private("wmSymbol")
const _wsSymbol = Symbol.private("wsSymbol")
const call = Function.call.bind(Function.call)
const hasOwn = Function.call.bind({}.hasOwnProperty)
const getOwn = Object.getOwnPropertyDescriptor
const TE = TypeError
const checkMapThisKey = makeChecker("WeakMap", "weak map", _wmSymbol)
const checkSetThisKey = makeChecker("WeakSet", "weak set", _wsSymbol)
function makeChecker(name, human, symbol) {
View fl-types.d.ts
// A complete set of type defs for Fantasy Land
interface Setoid {
"fantasy-land/equals"(other: this): boolean;
}
interface Ord {
"fantasy-land/lte"(other: this): boolean;
}
interface Semigroupoid<A, B> {
@isiahmeadows
isiahmeadows / util-inspect.js
Last active Jul 26, 2018
WIP `util-inspect` replacement that features the most recent Node APIs. An attempt is made here to remain compatible with older IE/etc. with `es5-shim` and without `es5-sham`.
View util-inspect.js
// Copyright Joyent, Inc. and other Node contributors.
//
// Permission is hereby granted, free of charge, to any person obtaining a
// copy of this software and associated documentation files (the
// "Software"), to deal in the Software without restriction, including
// without limitation the rights to use, copy, modify, merge, publish,
// distribute, sublicense, and/or sell copies of the Software, and to permit
// persons to whom the Software is furnished to do so, subject to the
// following conditions:
//
You can’t perform that action at this time.