This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from collections.abc import Mapping, Sequence | |
from typing import Any, Iterator, Protocol, Tuple, TypeVar, runtime_checkable | |
K = TypeVar('K') # Key type for mappings | |
V = TypeVar('V') # Value type | |
@runtime_checkable | |
class SupportsItems(Protocol[K, V]): | |
def items(self) -> Iterator[Tuple[K, V]]: ... |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function compactify(ugly) { | |
// Step 1: JSON stringify with indentation (4 spaces) | |
const first_pass = JSON.stringify(JSON.parse(ugly), null, 4) | |
// Step 2: Put comma-sep. numbers on same line | |
const comma_num_newline_ptn = /,\n +((\d\.)?\d+)/g | |
const num_same_line = first_pass.replace(comma_num_newline_ptn, ', $1') | |
// Step 3: Put flat arrays on same line | |
const flat_array_ptn = /\[\n\s+(([\d.]+, )+[\d.]+)\n\s+\]/g |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package main | |
import ( | |
"encoding/json" | |
"fmt" | |
"github.com/kr/pretty" | |
) | |
func main() { |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const urtype = (x) => Object.prototype.toString.call(x).split(' ')[1].slice(0, -1) | |
// examples | |
[ | |
['undefined primitive', undefined], | |
['undefined via void operator', void ''], | |
['null', null], | |
['boolean primitive', true], | |
['number primitive', 123], | |
['string primitive', 'I feel pretty'], |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
-- Generate a calendar in PostgreSQL | |
-- Rather than create a calendar table and insert rows into it statically, | |
-- this approach materializes a recursive [iterative] query. | |
CREATE MATERIALIZED VIEW cal AS | |
WITH RECURSIVE dd(d) AS ( | |
VALUES ('2005-01-01'::DATE) | |
UNION ALL | |
SELECT d + 1 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Object.getOwnPropertyNames(window).filter(name => name.match(/^HTML[a-zA-Z]*Element$/)).forEach(h => { | |
[{abbr: 'qs', name: 'querySelector'}, {abbr: 'qsa', name: 'querySelectorAll'}].forEach(fn => { | |
try { | |
window[h]['prototype'][fn.abbr] = window[h]['prototype'][fn.name] | |
console.log(`${h}: added alias ${fn.abbr} for ${fn.name} method.`) | |
} catch (e) { | |
console.log(`${h} has no ${fn.name} method.`, e.message) | |
} | |
}) | |
}) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(function () { | |
function __kill_added_iframe_mutob_callback(mList, ob){ | |
const addedNodesToRemove = [] | |
mList.forEach(mRec => { | |
mRec.addedNodes.forEach(addedNode => { | |
if (addedNode.tagName.match(/^iframe$/i)) { | |
addedNodesToRemove.push(addedNode) | |
} | |
}) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var cp = (function () { | |
class CoolorsPalette { | |
constructor() { | |
// Row spans all palette columns: i.e., one shade of each color | |
this.rows = Array.from(document.querySelectorAll('#palette-shades div.palette-shades-row')) | |
const numCols = this.rows[0].querySelectorAll('div.palette-shades-col').length | |
this.colors = Array(numCols).fill([]) | |
this.rows.forEach(row => { | |
Array | |
.from(row.querySelectorAll('div.palette-shades-col')) |