Skip to content

Instantly share code, notes, and snippets.

dead-claudia / timers.js
Last active November 19, 2023 01:04
Web timers using only ES globals, the error reporting API, and the performance API
View timers.js
// TODOs
// - Confirm timings
// - Maybe roll this up into a (tested) library along with streams/etc, to
// provide a simplified foundation for runtimes, so they can save a lot of
// work and just focus on the bits specific to them. This will of course also
// be paired with a WASM module to implement various text transcoding and
// conversion algorithms, as well as compression. May even partially
// implement WASI.
// The two only Web API dependencies
dead-claudia / count-zero-bytes.c
Last active July 29, 2022 19:03
Utility to compare various ways of counting zero and (really) non-zero bytes, including exhaustive tests
View count-zero-bytes.c
// Note: there are some Clang-isms here. To compile with GCC, define `__builtin_readcyclecounter`
// to read from something like x86's `rdtsc` and return a 64-bit integer with the cycle count. It's
// always manipulated relative to a prior call, so it doesn't matter if it wraps around once in the
// process.
#define RUN_ONLY_TESTS 1
// Set to RUN_ONLY_TESTS to run only tests, RUN_ONLY_BENCHMARK to run only the benchmark, or unset
// to run both.
dead-claudia / patch.js
Created May 6, 2021 15:50
patch userland implementation
View patch.js
export function patch(target, props) {
return m(Patch, {target, ...props})
const hasOwn = {}.hasOwnProperty
const isEventKey = /^on(?!init|create|(?:before)?(?:update|remove)$)/
function Patch({attrs}) {
function handler(event) {
const onevent = attrs[`on${event.type}`]
dead-claudia / promise-settle.js
Last active May 2, 2020 01:59
Promise synchronous settle
View promise-settle.js
const call =
// `onSettled` is just `onSettled(value, isSuccess)`.
Promise.hookIntoSettlement = (thenable, onSettled) => {
function settle(value) {
let settled = false
let then
function fail(e) {
if (!settled) {
settled = true
dead-claudia / mithril-react.mjs
Last active September 27, 2021 12:21
Mithril to React adapters
View mithril-react.mjs
import m from "mithril"
import React, {useLayoutEffect, Component} from "react"
import ReactDOM from "react-dom"
// Bottom-up to Mithril, top-down to React
export function useMithril(ref, view) {
useLayoutEffect(() => { m.render(ref.current, view()) })
useLayoutEffect(() => () => { m.render(ref.current, null) }, [])
dead-claudia / foo.js
Last active December 14, 2019 01:33 — forked from sakenzhuma/foo.js
View foo.js
import {api} from '../../share/hlp'
import Header from './header'
import pgList from '../../cmp/pgList'
import editBox from '../../cmp/editBox'
import Modal from '../../cmp/modal'
export default function Storage(){
let modalstate = false
let folderView = 1
let folder = ""
let dataList = []
dead-claudia /
Last active May 1, 2019 18:28
Mini CSS-in-JS framework in under 50 lines of ES6 code

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:

dead-claudia / mithril-fontawesome.js
Last active January 23, 2020 03:07
Mithril port of react-fontawesome
View mithril-fontawesome.js
// This is a direct API port of
// 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.2KB min+gzip.
// Here's a few example vnodes:
// ```js
dead-claudia / id-generate.js
Created January 30, 2019 00:35
Simple ID generator
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 = [ Set(Array.from(alphabet, x => `${x}`))]
let counter = 0
if (charTable.length < 2) {
dead-claudia / classnames-object.js
Created December 16, 2018 21:13
`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') {