Skip to content

Instantly share code, notes, and snippets.

View nhusher's full-sized avatar

Nicholas Husher nhusher

View GitHub Profile
@nhusher
nhusher / README.md
Last active September 30, 2022 15:42
Bizarre React Devtools problem

Usage:

git clone [email protected]:33981014bb69318ead012c11a73eff52.git react-issue-repro
npx static-server

Visit the URL provided by static-server.

  1. Have React devtools installed
const close = it => {
if (it.return) it.return()
}
const iterator = it => {
if (typeof it !== 'object') throw new TypeError(`Iterator expected`)
if ('next' in it) return it
else if (Symbol.iterator in it) return it[Symbol.iterator]()
else throw new TypeError(`Iterator expected`)
}
/**
The MIT License (MIT)
Copyright (c) 2019 Faraday Inc.
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:
function * drainObservable (observable) {
let buf = []
let waiting = []
let err = null
let done = false
let subscription
try {
subscription = observable.subscribe(val => {
if (waiting.length) waiting.shift().resolve(val)
export class Icon extends PureComponent {
constructor (...args) {
super(...args)
this.ref = node => { this.node = node }
}
applyFill () {
if (!this.node) return
const fill = this.props.fill
Array.from(this.node.querySelectorAll('path')).forEach(path => {
@nhusher
nhusher / 1.gcd.rs
Created February 15, 2018 12:09
very simple gcd in wasm
#![feature(lang_items)]
#![no_std]
#[no_mangle]
pub extern "C" fn gcd(mut n: i32, mut m: i32) -> i32 {
assert!(n != 0 && m != 0);
while m != 0 {
if m < n {
let t = m;
m = n;
node_modules
@nhusher
nhusher / redux-ish.clj
Last active September 18, 2018 17:28
Redux with basically no effort in clojurescript, plus core.async to handle asynchronous actions
(ns reduxish.state-tools
(:require-macros [cljs.core.async.macros :refer [go go-loop]])
(:require [cljs.core.async.impl.protocols :refer [WritePort ReadPort]]
[cljs.core.async :refer [<!]]))
(defn channel?
"A predicate that determines if the provided thing is a core.async channel"
[ch]
(and (satisfies? WritePort ch) (satisfies? ReadPort ch)))
import React from 'react'
// TODO: warn when using this, because it's high-test enriched technical debt:
export class TinyNavigator extends React.Component {
constructor (...args) {
super(...args)
this.state = {
path: this.checkPath()
}
import React from 'react'
// Call the provided function with the provided value as the only argument,
// if the call throws an exception, return the original value, otherwise
// return the result of applying fn to val
function attempt(fn, val) {
try {
return fn(val)
} catch (e) {
return val