Skip to content

Instantly share code, notes, and snippets.

View keybase.md

Keybase proof

I hereby claim:

  • I am mscalora on github.
  • I am mscalora (https://keybase.io/mscalora) on keybase.
  • I have a public key ASBipYrZDCrdzGvlafxUvRxpYnb_7D_AWslP7efmBgH5vAo

To claim this, I am signing this object:

@mscalora
mscalora / ttd_dom_ready.js
Created Apr 3, 2021
simplified ttd_dom_ready - does not support (old) IE
View ttd_dom_ready.js
(function (){
window.ttd_dom_ready = window.ttd_dom_ready || function (cb) {
if (document.readyState === "complete" ||
(document.readyState !== "loading" && !document.documentElement.doScroll)) {
cb();
} else {
let mcb = () => {
document.removeEventListener("DOMContentLoaded", mcb);
cb();
};
@mscalora
mscalora / counter.html
Last active Mar 15, 2021
Perfect JS Counter
View counter.html
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Counter</title>
<style>
html {
height: 100%;
margin: 0;
padding: 0;
View emoji-favicon.html
<link rel="icon" href="data:image/svg+xml,<svg xmlns=%22http://www.w3.org/2000/svg%22 viewBox=%220 0 100 100%22><text y=%22.9em%22 font-size=%2290%22>☃️</text></svg>">
@mscalora
mscalora / spin-the-needle.js
Created Apr 1, 2020
Work towards a spin the needle animation using SVG
View spin-the-needle.js
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Make</title>
<style>
</style>
</head>
<body>
View object-diff.js
// From: NicolasLetellier @ https://gist.github.com/Yimiprod/7ee176597fef230d1451#gistcomment-3058093
function objectDiff(object, base) {
function changes(object, base) {
const accumulator = {};
Object.keys(base).forEach((key) => {
if (object[key] === undefined) {
accumulator[`-${key}`] = base[key];
}
});
@mscalora
mscalora / search_all_up.sh
Last active Mar 8, 2020
search up a directory tree for multiple filenames
View search_all_up.sh
#!/bin/bash
search_all_up() {
# extended from https://stackoverflow.com/a/19011599/370746
local look=${PWD%/}
while [[ -n $look ]]; do
for name in $@ ; do
[[ -e $look/$name ]] && {
printf '%s\n' "$look/$name"
return
@mscalora
mscalora / ansi.js
Created Feb 13, 2020
Javascript tools for dealing with ansi formatted text
View ansi.js
// regexp group 1: visible text group 2: ansi codes
// eslint-disable-next-line no-control-regex
const ansiMatcher = new RegExp("([^\u001B\u009B]*)([\u001B\u009B][[\\]()#;?]*(?:(?:(?:[a-zA-Z\\d]*(?:;[-a-zA-Z\\d\\/#&.:=?%@~_]*)*)?\u0007)|(?:(?:\\d{1,4}(?:;\\d{0,4})*)?[\\dA-PR-TZcf-ntqry=><~]))|$)", "g")
function stripAnsi (s) {
return s.replace(ansiMatcher, "$1")
}
function truncateAnsi (s, len) {
let total = 0
View resize-table.js
// table resize test for tty-table
const Table = require("tty-table")
const Chalk = require("chalk")
let failures = []
function test (width, truncate, marginLeft) {
let output = new Table([
{minWidth: 6, shrink: 0},
@mscalora
mscalora / isInViewport.js
Created Dec 13, 2019
test if dom element is in viewport either fully or fully/partially/none
View isInViewport.js
function isInViewport (elem, partially) {
let box = elem.getBoundingClientRect(),
top = box.top,
bottom = box.bottom,
right = box.right,
left = box.left,
h = window.innerHeight || document.documentElement.clientHeight,
w = window.innerWidth || document.documentElement.clientWidth,
fully = (top >= 0 && box.left >= 0 && bottom <= h && box.right <= w);