Skip to content

Instantly share code, notes, and snippets.

function generateDeferredPromise<T>(): {
promise: Promise<T>;
reject: (reason?: unknown) => void;
resolve: (value: T | PromiseLike<T>) => void;
} {
let resolve!: (value: T | PromiseLike<T>) => void;
let reject!: (reason?: unknown) => void;
const promise = new Promise<T>((res, rej) => {
[resolve, reject] = [res, rej];
});
@manbearwiz
manbearwiz / parseCodepoints.js
Last active November 9, 2023 18:02
Parse a font svg, extract the escaped unicode characters, and output a map of the glyph name to its corresponding code. `cat icon-font.svg | node parseCodepoints > icon-font.codepoints`
const { WritableStream } = require('htmlparser2/lib/WritableStream');
const escape = (_, s) => s.codePointAt().toString(16);
const parserStream = new WritableStream({
onopentag(name, { unicode, 'glyph-name': glyphName }) {
if (name === 'glyph' && glyphName && unicode) {
process.stdout.write(`${glyphName} ${escape`${unicode}`}\n`);
}
},
@manbearwiz
manbearwiz / conditional-view.ts
Created November 1, 2023 04:10
An angular utility class for conditionally creating and destroying views.
import { ViewContainerRef, TemplateRef, EmbeddedViewRef } from '@angular/core';
/**
* A utility class for conditionally creating and destroying views.
*/
export class ConditionalView<T = unknown> {
private _viewRef?: EmbeddedViewRef<T>;
/**
* Creates a new ConditionalView.
@manbearwiz
manbearwiz / removeImport.ts
Created September 1, 2022 20:25
Angular schematic function to remove import from file. Inspired by `insertImport` from the angular cli repo.
import { findNodes } from '@schematics/angular/utility/ast-utils';
import { NoopChange, RemoveChange } from '@schematics/angular/utility/change';
import {
ImportSpecifier,
isStringLiteral,
SourceFile,
SyntaxKind,
} from 'typescript';
/**
@manbearwiz
manbearwiz / .block
Last active February 22, 2018 07:36 — forked from mbostock/.block
Stacked Bar Chart
license: gpl-3.0
@manbearwiz
manbearwiz / mindwavemobileuserguide.md
Created September 27, 2016 15:59
MindWave Mobile: User Guide

#MindWave Mobile: User Guide

Setting Up Your MindWave Mobile

Power

To power on the MindWave Mobile headset, slide the switch to the ON (middle) position. When held past the ON position for 3 seconds and then released, the headset will enter Bluetooth pairing mode. If instead the switch is held past the ON position for 6 seconds, the headset's pairing memory will be cleared.

While the MindWave Mobile headset is powered on, the LED light on the side of the headset will be turned on. If the MindWave has a low battery, the LED light will flash to indicate low battery status.

@manbearwiz
manbearwiz / ECON2130.md
Created April 16, 2015 08:19
ECONOMIC 2130 - Principles of Macroeconomics

#ECONOMIC 2130 - Principles of Macroeconomics

##Chapter 10

###Money

Anything accepted as a medium of exchange.

  1. Means of payment or Means of Exchange – accepted as payment for goods and services.
  2. Store of Value – transports purchasing power from one time period to another.

#FACE Stack Project

##Requirements

  1. Must work right
  2. Must work well
  3. Must work really well
  4. Must work fast

##Use Cases

@manbearwiz
manbearwiz / Feeder.xml
Last active August 29, 2015 14:05
Exported feed from my rss reader, feedly
<?xml version="1.0" encoding="UTF-8"?><opml version="1.0"><head><title>Feeder - RSS Feed Reader</title></head><body><outline title="Tech News" text="Tech News"><outline text="Ars Technica » Disciplines » Open Source" title="Ars Technica » Disciplines » Open Source" type="rss" xmlUrl="http://feeds.arstechnica.com/arstechnica/open-source?format=xml" htmlUrl="http://arstechnica.com" rssfr-favicon="http://static.arstechnica.net/favicon.ico"/><outline text="Ars Technica » software" title="Ars Technica » software" type="rss" xmlUrl="http://feeds.arstechnica.com/arstechnica/software?format=xml" htmlUrl="http://arstechnica.com" rssfr-favicon="http://static.arstechnica.net/favicon.ico"/><outline text="Ars Technica » Technology Lab" title="Ars Technica » Technology Lab" type="rss" xmlUrl="http://feeds.arstechnica.com/arstechnica/technology-lab?format=xml" htmlUrl="http://arstechnica.com" rssfr-favicon="http://static.arstechnica.net/favicon.ico"/><outline text="Engadget Software" title="Engadget Software" type="rss" xml