Skip to content

Instantly share code, notes, and snippets.

View MaxGraey's full-sized avatar

Max Graey MaxGraey

View GitHub Profile
@MaxGraey
MaxGraey / reverse-string.js
Last active November 29, 2018 10:35
Unicode aware reverse string Benchmarks
'use strict';
// run:
// node --expose-gc reverse-string.js
/*
node v11.3.0, MacBook Late 2013
Bench results:
[Naive reverse string]
@MaxGraey
MaxGraey / rotate.ts
Last active January 26, 2019 18:05
rotate image for squoosh
export function rotate(inputWidth: i32, inputHeight: i32, rotate: i32): void {
const bpp = 4;
let offset = inputWidth * inputHeight * bpp;
let i = 0;
// In the straight-copy case, d1 is x, d2 is y.
// x starts at 0 and increases.
// y starts at 0 and increases.
let d1Start: i32;
let d1Limit: i32;
@MaxGraey
MaxGraey / rotate-v2.ts
Created January 26, 2019 19:10
squoosh rotate v2
export function rotate(inputWidth: i32, inputHeight: i32, rotate: i32): void {
const bpp = 4;
let offset = inputWidth * inputHeight * bpp;
// In the straight-copy case, d1 is x, d2 is y.
// x starts at 0 and increases.
// y starts at 0 and increases.
let d1Start: i32;
let d1Limit: i32;
let d1Multiplier: i32;

Структура кода компонента

Последовательно, согласно нумерации.

\n - перенос строки

  1. import * as React from 'react'
  2. Импорты из сторонних библиотек\n
  3. Локальные импорты по абсолютным путям
const isOrdered = arr => !arr.some((v, i) => v == arr[i + 1]);
function swap(alphabets, idx1, idx2) {
var t = alphabets[idx1];
alphabets[idx1] = alphabets[idx2];
alphabets[idx2] = t;
return alphabets;
}
function permute(alphabets, startIndex = 0, endIndex = alphabets.length - 1) {
if (startIndex !== endIndex) {
@MaxGraey
MaxGraey / abs-approx.js
Last active January 18, 2020 19:43
Rational approximation abs with MSE = ~1.6e-7
const fj = [ 1, 0.01123596, 1, 0.19101124, 0.05617978, 0.39325843, 0.01123596, 0.59550562, 0.21348315]
const wj = [-0.232961,-0.1212703, -0.29214973,-0.12772172, 0.21085705, 0.6024462, 0.07024019, 0.3625982, -0.53436423]
const zj = [-1, -0.01123596, 1, 0.19101124, -0.05617978, -0.39325843, 0.01123596, 0.59550562, -0.21348315]
function approxAbs(x) {
const B0 = wj[0] / (x + 1 - 1e-15);
const B1 = wj[1] / (x - zj[1]);
const B2 = wj[2] / (x - 1 + 1e-15);
const B3 = wj[3] / (x - zj[3]);
const B4 = wj[4] / (x - zj[4]);
// tslint:disable-next-line:no-reference
/// <reference path="../node_modules/assemblyscript/index.d.ts" />
@sealed @unmanaged
class Ge {
x: Int64Array;
y: Int64Array;
z: Int64Array;
t: Int64Array;
(module
(type $t0 (func (param i32 i32)))
(type $t1 (func (param i32 i32) (result i32)))
(func $std.builtin.default_panic (type $t0) (param $p0 i32) (param $p1 i32)
(local $l2 i32) (local $l3 i32) (local $l4 i32)
global.get $g0
local.set $l2
i32.const 16
local.set $l3
local.get $l2
@MaxGraey
MaxGraey / bench.js
Created May 17, 2020 13:38
getStringImpl join array of strings vs string concat
let buffer;
const LENGTH = 1024 * 4 + 17;
const WARMUP_COUNT = 8;
function createStringBuffer(len = LENGTH) {
buffer = new ArrayBuffer(len * 2);
const U16 = new Uint16Array(buffer);
const alphabet = 'A BCDE, FGHI JKLM.; (NOPQ- RSTU, VWXYZ. abcd; efgh,) ijkl mnop. qrst- uvwxy,( z0123 4567, 89.)';
for (var i = 0; i < len; i++) {
U16[i] = alphabet.charCodeAt(Math.floor(Math.random() * alphabet.length));
@MaxGraey
MaxGraey / toolbar.cson
Created September 15, 2017 20:58
config for atom-flex-toolbar
[
{
type: "button"
icon: "social-buffer"
callback: "application:add-project-folder"
tooltip: "Add Project"
iconset: "ion"
style: {
color: "rgba(255, 255, 255, 0.7)"
transform: "scale(1.2)"