Skip to content

Instantly share code, notes, and snippets.

@ddprrt
ddprrt / collection.mjs
Created February 22, 2022 09:32
A lazy evaluated collection class
class Collection {
coll;
constructor(coll) {
this.coll = coll;
}
map(fn) {
return new MapCollection(this, fn);
}
@ddprrt
ddprrt / resizeobserver.d.ts
Last active July 16, 2020 13:56
Resize Observer IDL
type ResizeObserverBoxOptions = "border-box" | "content-box" | "device-pixel-content-box";
interface ResizeObserverOptions {
box?: ResizeObserverBoxOptions;
}
interface ResizeObservation {
readonly lastReportedSizes: ReadonlyArray<ResizeObserverSize>;
readonly observedBox: ResizeObserverBoxOptions;
readonly target: Element;
@ddprrt
ddprrt / curry.ts
Created June 22, 2020 07:34
Currying with variadic tuple types
function curry<T extends unknown[], U extends unknown[], V>(
f: (...ts: [...T, ...U]) => V,
...a: T
): (...b: U) => V {
return (...b) => f(...a, ...b);
}
const input = (a: number, b: string, c: boolean, d: symbol) =>
[a, b, c, d] as const;
curry(input, 1, "123", true, Symbol())();
@ddprrt
ddprrt / all-elements.ts
Created May 27, 2020 20:53
All HTML Element types
type AllElements = {
'a': HTMLAnchorElement;
'div': HTMLDivElement;
'span': HTMLSpanElement;
'ul': HTMLUListElement;
'title': HTMLTitleElement;
'textarea': HTMLTextAreaElement;
'template': HTMLTemplateElement;
'tfoot': HTMLTableSectionElement;
'thead': HTMLTableSectionElement;
@ddprrt
ddprrt / Gulpfile.js
Last active May 8, 2020 21:11
Gulp: Grabbing JavaScript assets from a CDN to add to your build pipeline
var gulp = require('gulp');
var source = require('vinyl-source-stream');
var request = require('request');
var merge = require('merge2');
var concat = require('gulp-concat');
var buffer = require('gulp-buffer');
/**
* 1. We request the latest jQuery version from the jQuery CDN. The
* request package allows for streaming. What we get in return
@ddprrt
ddprrt / typedef.js
Created July 15, 2019 11:34
My code shares on Twitter. As a gist. Primarily for #a11y
/**
* @typedef {Object} Article
* @property {string} title
* @property {number} price
* @property {number} vat
* @property {number} stock
* @property {string} description
*/
/** @type {Article} */
let article;
@ddprrt
ddprrt / index.html
Created November 11, 2016 10:23
MaPgmM
<input type="color" />
@ddprrt
ddprrt / demo-for-today.markdown
Created November 11, 2016 10:22
Demo for today
@ddprrt
ddprrt / dabblet.css
Created May 15, 2013 11:57
The first commented line is your dabblet’s title
/**
* The first commented line is your dabblet’s title
*/
html, body { height: 100%; }
body {
background: black;
color: red;
font-family: sans-serif;
text-align: center;