This is supposed to be served next to a fonts.css file defining one or more font-families, ex:
@font-face {
font-family: "American Captain";
src: url("./American-Captain.woff") format("woff");
}
This is supposed to be served next to a fonts.css file defining one or more font-families, ex:
@font-face {
font-family: "American Captain";
src: url("./American-Captain.woff") format("woff");
}
const ignoreKeys = new Set([ | |
'parent', | |
'transform', | |
]); | |
const numberKeyRgx = /^[0-9]+$/; | |
const simpleKeyRgx = /^[a-zA-Z_\$][a-zA-Z0-9_\$]*$/; | |
const getExpr = function (key: string) { | |
if (numberKeyRgx.test(key)) return `[${key}]`; | |
return (simpleKeyRgx.test(key)) ? `.${key}` : `['${key}']`; |
{ config, pkgs, ... }: | |
{ | |
imports = | |
[ | |
./hardware-configuration.nix | |
]; | |
boot.loader.systemd-boot.enable = true; | |
boot.loader.efi.canTouchEfiVariables = true; |
import { expect } from 'chai'; | |
import { ArrayUtils } from './ArrayUtils'; | |
function sortByNumericAttribute() { | |
const arr = [ | |
{ a: 'a', n: 3 }, | |
{ a: 'b', n: 2 }, | |
{ a: 'c', n: 6 }, | |
]; | |
expect(ArrayUtils.sortByNumericAttribute(arr, 'n', false)).to.deep.eq([ |
So we we're using an API which returns a JSON response. One of its attributes is a numeric key. Due to historical reasons we're now being served longer number (longs) so the server, which is not based on JavaScript, started returning long integers.
I had heard about issues like this but hadn't cross against a real use case before.
So what started happening on our JavaScript clients (browser and React Native alike) is that the primitive value we get back once we get the fetch json promise resolved is an overflown number.
JavaScript engines commonly have the symbol Number.MAX_SAFE_INTEGER
so one can retrieve the number above which problems start to appear (it is 9007199254740991
).
function saveSvgFile(svgEl, linkLabel) { | |
svgEl.setAttribute('version', '1.1'); | |
svgEl.setAttribute('xmlns', 'http://www.w3.org/2000/svg'); | |
var markup = svgEl.outerHTML; | |
var b64 = btoa(markup); | |
var aEl = document.createElement('a'); | |
aEl.setAttribute('download', linkLabel + '.svg'); | |
aEl.href = 'data:image/svg+xml;base64,\n' + b64; | |
document.body.appendChild(aEl); | |
aEl.click(); |
// to capture actual responses | |
let i = 0; | |
global.fetch = jest.fn(async (url, options) => { | |
console.log(`#${i++}: ${options.method || 'GET'} ${url}`); | |
const resp = await originalFetch(url, options); | |
const body = await resp.json(); | |
console.log(` status: ${resp.status}, body: ${JSON.stringify(body, null, 2)}`); | |
return body; | |
}); |
mysql -h localhost -u USER -P 3306 -p --protocol=TCP |
function clamp(v, m, M) { | |
return v < m ? m : v > M ? M : v; | |
} | |
function average(arr) { | |
return arr.reduce((prev, curr) => prev + curr, 0) / arr.length; | |
} | |
// triangle m0 x l of area 1 (linear degradation) | |
function averageWithDegradation(arr) { |