Skip to content

Instantly share code, notes, and snippets.

@suguanYang
suguanYang / gist:31fc7d63b6482eb6725003c787ca9e8b
Last active July 6, 2021 09:28
A fast way to check if 2 string are composed of same characters.
const alphas = {
  a: 101,
  b: 2,
  c: 3,
  d: 5,
  e: 7,
  f: 11,
  g: 13,
 h: 17,
@suguanYang
suguanYang / tooltip
Created December 1, 2021 09:54
tooltip with dynamic position
const { x: offsetLeft } = currentTarget.getBoundingClientRect();
const innerWidth = window.innerWidth;
const offsetRight = innerWidth - offsetLeft;
if (offsetLeft < TOOLTIP_WIDTH / 2) {
// if left space is too small
// --------
// |s. |
// |---- | s = offsetLeft
// | | left = -s = -
// --------
@suguanYang
suguanYang / Infrastructure.js
Created March 13, 2022 12:43 — forked from sebmarkbage/Infrastructure.js
SynchronousAsync.js
let cache = new Map();
let pending = new Map();
function fetchTextSync(url) {
if (cache.has(url)) {
return cache.get(url);
}
if (pending.has(url)) {
throw pending.get(url);
}