Skip to content

Instantly share code, notes, and snippets.

@AprilArcus
AprilArcus / MyError.ts
Created July 22, 2022 19:07
Pedantic JavaScript / TypeScript Error subclass
// Recipe for a pedantically correct subclass of JavaScript's built-in
// "Error" constructor.
// * Preserves the ability of JS Errors to be constructed with
// a `new`-less function call
// * Can be subclassed itself
// * Backward- and Forward-compatible TypeScript annotations
// * Correct enumerable / writable / configurable settings on
// .prototype, .prototype.constructor, .prototype.name, and
// custom instance fields.
# I've always disliked the "./configure" incantation - it's right here! I
# shouldn't need to tell the shell where to look for it. But of course,
# putting '.' in your $PATH is terrible -- it's insecure and throws permission
# errors if you try to 'execute' regular files. Bash 4's `shopt -s autocd`
# solves half the problem; and the ability to override
# command_not_found_handle() solves the other.
#
# This is an OS X-oriented script that attempts to do the most intelligent
# thing possible when you enter the name of a file in your $PWD into the bash
# prompt. It will:
@AprilArcus
AprilArcus / gist:ec2bf19078da83199e93
Last active November 25, 2016 01:53
Thoughts on Typefaces

(c) April Arcus 2015

SANS SERIFS

Many important sans serifs can be organized on a single axis from geometric to humanist.

Radically Geometric

/* @flow */
export function foo(test: boolean, callback: () => Array<number>): Array<number|string> {
if (test) return [1, '1'];
return callback();
}
3: export function foo(test: boolean, callback: () => Array<number>): Array<number|string> {
^^^^^^ string. This type is incompatible with
3: export function foo(test: boolean, callback: () => Array<number>): Array<number|string> {
$ flow check
src/injectCallbacks.js:0
0:
^ inconsistent use of library definitions
67: detachEvent?: (type: string, listener: EventListener) => void;
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ undefined. This type is incompatible with. See: /private/tmp/flow/flowlib_2dc60f56/dom.js:67
67: detachEvent?: (type: string, listener: EventListener) => void;
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ function type. See: /private/tmp/flow/flowlib_2dc60f56/dom.js:67
/* @flow */
declare class SVGElement extends Element {}
declare class HTMLParagraphElement extends HTMLElement {
align: string;
}
type ElementRegistrationOptions<T> = {
prototype?: {
@AprilArcus
AprilArcus / gist:7024adb7ec765f669e41
Last active January 7, 2016 03:17
custom element errors
element.js:
------------------------------
/* @flow */
declare class HTMLParagraphElement extends HTMLElement {
align: string
}
type CustomElementCallbacks = {
createdCallback?: () => void;
element.js
/* @flow */
declare class HTMLParagraphElement extends HTMLElement {
align: string
}
declare class Document extends Node {
registerElement(type: string, options?: ElementRegistrationOptions): void;
}
import { default as React, Component, Children, cloneElement } from 'react';
class ComponentWithComputedWidths extends Component {
constructor(props) {
super(props);
this.state = { computedWidthsAvailable = false; computedWidths: {} };
this.updateComputedWidths = this.updateComputedWidths.bind(this);
}
updateComputedWidths() {
<!-- polyfills -->
<script src="https://cdnjs.cloudflare.com/ajax/libs/bluebird/2.9.34/bluebird.min.js">
<script src="https://cdnjs.cloudflare.com/ajax/libs/fetch/0.9.0/fetch.min.js">
<script>
var imageCache = {};
function preload(name) {
var url = "images/" + name + ".jpg";
return fetch(url) // returns a promise...