Skip to content

Instantly share code, notes, and snippets.

View mathiasbynens's full-sized avatar

Mathias Bynens mathiasbynens

View GitHub Profile
const normalizeTimeZone = (timeZone) => {
const dtf = new Intl.DateTimeFormat('en-US', { timeZone });
const normalized = dtf.resolvedOptions().timeZone;
console.log(`${timeZone} → ${normalized}`);
return normalized;
};
// https://github.com/justingrant/proposal-canonical-tz#3-fix-out-of-date-canonicalizations-in-v8webkit
normalizeTimeZone('Africa/Asmara');
normalizeTimeZone('Africa/Asmera');
@mathiasbynens
mathiasbynens / escape.js
Created June 26, 2019 07:29
Escaping JSON-stringified data for use as a JavaScript string literal
// This object contains a string value that in contains a single quote,
// a double quote, a backtick, and a backslash.
const data = { foo: `a'b"c\`d\\e` };
// Turn the data into its JSON-stringified form.
const json = JSON.stringify(data);
// Now, we want to insert the data into a script body as a JavaScript
// string literal per https://v8.dev/blog/cost-of-javascript-2019#json,
// escaping special characters like `"` in the data.
http://AI./
└ IP: 209.59.119.34
http://ARAB./
└ IP: 127.0.53.53
http://BH./
└ IP: 10.10.10.10
http://CM./
└ IP: 195.24.205.60
http://DK./
└ IP: 193.163.102.58
@mathiasbynens
mathiasbynens / .gitignore
Last active September 12, 2024 08:14
Unicode version diff for ECMAScript
node_modules
package-lock.json
const compare = (versionA, versionB) => {
// TODO: Does there exist a path for which every single Unicode version
// gets new entries? If so, use that instead.
const path = 'General_Category/Other_Letter';
const before = new Set(require(
`unicode-${ versionA }/${ path }/code-points.js`
));
const after = require(
`unicode-${ versionB }/${ path }/code-points.js`
);
@mathiasbynens
mathiasbynens / web-platform-status-links.md
Last active July 4, 2024 22:36
Web platform status links
#!/usr/bin/env bash
# https://code.google.com/p/chromium/issues/detail?id=226801
url='https://chromium.googlesource.com/chromium/src/net/+/master/http/transport_security_state_static.json?format=TEXT';
curl -#s "${url}" | \
base64 --decode | \
sed '/^ *\/\// d' | \
sed '/^\s*$/d' > hsts.json;
@mathiasbynens
mathiasbynens / bf.js
Created July 17, 2015 10:56
How many hex-formatted Unicode code points can be mistaken for a number in scientific notation? Which ones are those? https://twitter.com/tabatkins/status/621440178087960576
'use strict';
const pad = function(string) {
const totalCharacters = 4;
return string.length < totalCharacters ?
(Array(totalCharacters + 1).join('0') + string).slice(-totalCharacters) :
string;
}
const UNICODE_MIN = 0x0;
@mathiasbynens
mathiasbynens / README.md
Last active August 5, 2023 03:20
Superfish certificate
[\x80-\uD7FF\uDC00-\uFFFF]|[\uD800-\uDBFF][\uDC00-\uDFFF]|[\uD800-\uDBFF]