Skip to content

Instantly share code, notes, and snippets.

Viktor Yaffle

Block or report user

Report or block Yaffle

Hide content and notifications from this user.

Learn more about blocking users

Contact Support about this user’s behavior.

Learn more about reporting abuse

Report abuse
View GitHub Profile
@Yaffle
Yaffle / decodeURIComponent.js
Created Feb 15, 2019
decodeURIComponent using TextDecoder
View decodeURIComponent.js
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)) {
return code + (10 - 'a'.charCodeAt(0));
} else {
throw new URIError();
}
View gist:40c58eb0c8075949313b3348bbb5f2b0
/*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) {
View gist:af5498d9e4fa5674fe5f4164a70fa506
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"};
}
@Yaffle
Yaffle / index.html
Last active May 10, 2017
isSafeInteger #jsbench #jsperf (http://jsbench.github.io/#ba6a3ecbe65fe3b16e9fb60ff6816723) #jsbench #jsperf
View index.html
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8"/>
<title>isSafeInteger #jsbench #jsperf</title>
<script src="https://cdnjs.cloudflare.com/ajax/libs/benchmark/1.0.0/benchmark.min.js"></script>
<script src="./suite.js"></script>
</head>
<body>
<h1>Open the console to view the results</h1>
View index.html
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8"/>
<title>Math.cbrt #jsbench #jsperf</title>
<script src="https://cdnjs.cloudflare.com/ajax/libs/benchmark/1.0.0/benchmark.min.js"></script>
<script src="./suite.js"></script>
</head>
<body>
<h1>Open the console to view the results</h1>
@Yaffle
Yaffle / index.html
Last active Dec 21, 2016
Math.trunc vs Math.floor #jsbench #jsperf (http://jsbench.github.io/#da9d5dbe6f00bc69c5c1328b6a3f6cee) #jsbench #jsperf
View index.html
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8"/>
<title>Math.trunc vs Math.floor #jsbench #jsperf</title>
<script src="https://cdnjs.cloudflare.com/ajax/libs/benchmark/1.0.0/benchmark.min.js"></script>
<script src="./suite.js"></script>
</head>
<body>
<h1>Open the console to view the results</h1>
@Yaffle
Yaffle / Math.fma.js
Last active Mar 19, 2017
Math.fma - fused multiply–add (FMA) or fused multiply–accumulate (FMAC) in JavaScript
View Math.fma.js
// a * b + c
// Math.fma - fused multiply–add (FMA) or fused multiply–accumulate (FMAC) in JavaScript
// For implementation details, see "The Handbook of Applied Cryptography"
// http://www.cacr.math.uwaterloo.ca/hac/about/chap14.pdf
// and
// https://github.com/JuliaLang/openlibm/blob/master/src/s_fma.c
//!? BUGGY
(function () {
@Yaffle
Yaffle / sort.js
Last active Sep 8, 2018
merge sort
View sort.js
// `Array#sort` implementation using the merge sort
// Notes:
// 1) calls comparator for undefined values, holes, values from the prototype chain;
// 2*) replaces holes with undefined values or values from the prototype chain;
// 3*) does not use `ToObject(this)`, `ToLength(this.length)`;
// 4*) does not throw errors for non-undefined non-function `comparefn`.
// 5*) uses `Math`, `Math.floor`, `String`, `Array`.
// 6*) calls setters of `Array.prototype` during internal buffer initialization.
// * This behaviour is inconsistent across browsers even for built-in `Array#sort`.
View canvas-drawArrow.js
var drawArrow = function (context, x1, y1, x2, y2) {
context.lineWidth = 1.25;
context.beginPath();
context.moveTo(x1, y1);
context.lineTo(x2, y2);
context.stroke();
var a = Math.PI / 8;
var h = 12;
var sa = Math.sin(a);
View gist:3c0a9a6d1fb535e24b21
// (Math.exp(704.6589) / Math.expm1(704.6589) - 1) / Number.EPSILON
var isExpOK = Math.exp(704.6589) >= 1.0702171200481775e+306 * (1 - 16 * Math.pow(2, -52)) &&
Math.exp(704.6589) <= 1.0702171200481775e+306 * (1 + 16 * Math.pow(2, -52));
// (Math.exp(704.6589) / Math.expm1(704.6589) - 1) / Number.EPSILON
var isExpOK = Math.exp(704.6589) >= 1.0702171200481775e+306 * (1 - 16 * Math.pow(2, -52)) &&
Math.exp(704.6589) <= 1.0702171200481775e+306 * (1 + 16 * Math.pow(2, -52));
Math.exp = function (x) {
var hi = 0.6931471805598903;
var lo = 5.497923018708371e-14;
var k = Math.floor(x / hi + 0.5);
You can’t perform that action at this time.