Skip to content

Instantly share code, notes, and snippets.

View fronterior's full-sized avatar
:electron:

Low Front fronterior

:electron:
View GitHub Profile
export type PointerType = 'pointerdown'|'pointermove'|'pointerup'|'scroll';
export interface CursorCoordinate {
type: PointerType;
x: number;
y: number;
dx?: number;
dy?: number;
}
const range = (first, last, dist = (last - first) / Math.abs(last - first)) => Array.from({length: Math.ceil((last - first) / dist)}, (_, i) => first + i * dist);
class ArrayMap extends Map {
constructor(...params) {
super();
params.forEach(([key, value]) => this.set(key, value));
}
set(key, value) {
const len = key.length;
const cp = [...key];
let chn = super.has(len) ? super.get(len) : (super.set(len, new Map),super.get(len));
let prop = cp.shift();
const p1Cache = f => {
const store = new Map;
console.log(store);
return a => store.has(a) ? store.get(a) : store.set(a, f(a)).get(a);
};
const p2Cache = f => {
const store = new Map;
return (a, b) => {
const isp = v => v === curry._;
const memo = fn => {
const cache = {};
return (...p) => {
const key = JSON.stringify(p);
return key in cache ? cache[key] : cache[key] = fn(...p);
}
};
function curry(fn, length = fn.length) {
if (length === 0) return fn;
/**
Only .ai file with PDF compatible.
Except IE...
*/
const AI_FILE_DIR = './test.ai'
const main = async () => { try {
const res = await fetch(AI_FILE_DIR)
const originBlob = await res.blob()
const fs = require("fs");
const stream = fs.createWriteStream("./fake-read-stream");
const fakeReadableStream = new (class {
readable = true;
constructor() {
this.data =
"abc ewij fj wiefj ewi tj94htr834h u4 hru4 u9jr92i3 i09rj 239ij erw9i fgj3u94it 34i9 tj";
this.cursor = 0;
function* numberOfCases(...args) {
const stack = [[[], args]];
while (stack.length) {
const target = stack.shift();
if (target) {
const [result, rest] = target;
for (let i = 0; i < rest.length; i++) {
let r;
yield r = [...result, rest[i]];
stack.push([r, rest.filter((_, index) => index !== i)]);
function* getDivisor(n) {
let temp = 0;
for (let i = 1; i <= n; i++) {
if (n % i) continue;
if (temp === i) break;
yield i;
temp = n / i;
yield temp;
}
}
// https://stackoverflow.com/questions/836777/how-to-detect-browsers-protocol-handlers
// https://jsfiddle.net/stefansundin/0uca4h2o/
function checkRegisteredProtocol(protocol: string) {
const input = document.createElement('input');
input.style.position = 'absolute';
input.style.opacity = '0';
document.body.appendChild(input);
let isSupported = false;
input.focus();
input.onblur = () => isSupported = true;