This file contains 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
let hex = new Uint8Array(0); | |
const td = new TextDecoder(); | |
const te = new TextEncoder(); | |
function packBigInt(blocks, blockSize) { | |
function encode(blocks, length) { | |
const u32 = new Uint32Array(hex.buffer); | |
let k = (length >> 2) - 1;//TODO:!? |
This file contains 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 uint64 = new BigUint64Array(1); | |
const uint32 = new Uint32Array(uint64.buffer); | |
function clz64(bigint) { | |
uint64[0] = bigint; | |
let x = Math.clz32(uint32[1]); | |
let y = Math.clz32(uint32[0]); | |
return x + (x === 32 ? y : 0); | |
} |
This file contains 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
/*jshint esversion:6, bitwise:false*/ | |
// https://webassembly.github.io/wabt/demo/wat2wasm/index.html helps a lot | |
function wast2wasm(sExpression) { | |
function sExpressionToJSON(s) { | |
return JSON.parse(s.trim().replace(/\s*\)/g, ']').replace(/\(\s*/g, '[').replace(/\s+/g, ',').replaceAll('"', '').replace(/([^\[\],]+)/g, '"$1"')); | |
} |
This file contains 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
// CPU L2 cache size | |
function ASMModule1(stdlib, foreign, heap) { | |
"use asm"; | |
var memory = new stdlib.Uint32Array(heap); | |
function loop(c) { | |
c = c | 0; | |
var k = 0; | |
var j = 0; | |
for (j = c; (j | 0) != 0; j = (j - 1) | 0) { | |
k = memory[k >> 2] << 2; |
This file contains 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* continuedFractionForSqrt(n) { | |
// https://trizenx.blogspot.com/2018/10/continued-fraction-factorization-method.html | |
function floorDiv(a, b) { | |
return typeof a === "bigint" && typeof b === "bigint" ? a / b : Math.floor(a / b); | |
} | |
n = BigInt(n); | |
if (n < 0n) { | |
throw new RangeError(); | |
} | |
const root = BigInt(sqrt(n)); |
This file contains 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
// Usage: | |
// var x = document.querySelector('[contenteditable]'); | |
// var caretPosition = getSelectionDirection(x) !== 'forward' ? getSelectionStart(x) : getSelectionEnd(x); | |
// setSelectionRange(x, caretPosition + 1, caretPosition + 1); | |
// var value = getValue(x); | |
// it will not work with "<img /><img />" and, perhaps, in many other cases. | |
function isAfter(container, offset, node) { | |
var c = node; |
This file contains 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
// Implementation of the standard decodeURIComponent using TextDecoder. | |
// The original JavaScript specification does not separate UTF-8 decoding this way. | |
// The purpose is to show the possible implementation in JavaScript language. | |
function hexDigit(code) { | |
if (code >= '0'.charCodeAt(0) && code <= '9'.charCodeAt(0)) { | |
return code - '0'.charCodeAt(0); | |
} else if (code >= 'A'.charCodeAt(0) && code <= 'F'.charCodeAt(0)) { | |
return code + (10 - 'A'.charCodeAt(0)); | |
} else if (code >= 'a'.charCodeAt(0) && code <= 'f'.charCodeAt(0)) { |
This file contains 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
/*jslint strict:global*/ | |
/*global self, fetch, caches, console, Promise, Request*/ | |
"use strict"; | |
var CACHE_NAME_PREFIX = "ru~"; | |
var CACHE_NAME = "ru~20180818T075107Z"; | |
var URLS_TO_CACHE = "./;js.js?20180818T075107Z;css.css?20180818T075107"; | |
self.addEventListener("install", function (event) { |
This file contains 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 replaceSimpleDigit(code) { | |
if (code >= 0x0660 && code <= 0x669) { | |
return {code: code - 0x0660 + 48, name: "arab"}; | |
} | |
if (code >= 0x06F0 && code <= 0x6f9) { | |
return {code: code - 0x06F0 + 48, name: "arabext"}; | |
} | |
if (code >= 0x0966 && code <= 0x96f) { | |
return {code: code - 0x0966 + 48, name: "deva"}; | |
} |
NewerOlder