(() => {
let { offsetWidth, offsetHeight } = document.documentElement;
let walker = document.createTreeWalker(document.body, NodeFilter.SHOW_ELEMENT);
while (walker.nextNode()) {
let bound = walker.currentNode.getBoundingClientRect();
let isWidthOverflow = bound.right > offsetWidth || bound.left < 0;
let isHeightOverflow = bound.bottom > offsetHeight || bound.top < 0;
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// deno run sql_format.ts | |
import { format } from "http://esm.sh/sql-formatter@4.0.2"; | |
import { readAll, writeAll } from "https://deno.land/std@0.117.0/io/mod.ts"; | |
const input = await readAll(Deno.stdin); | |
const unformatted = new TextDecoder().decode(input); | |
const formatted = format(unformatted, { language: "mysql" }); | |
await writeAll(Deno.stdout, new TextEncoder().encode(formatted)); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{ | |
const collapsedTrace = (message) => { | |
console.groupCollapsed(message); | |
console.trace(); | |
console.groupEnd(); | |
}; | |
const isPrimitive = (x) => x !== Object(x); | |
const proxy = (target, path) => { |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# You shouldn't execute this if you didn't read it. | |
# If not installed | |
brew install sd | |
# Not effective commands | |
find . -ipath '*apple*' -type f | tac > source.txt | |
cat source.txt | sd 'apple' 'banana' | sd 'Apple' 'Banana' > dest.txt | |
paste -d" " source.txt dest.txt > replace.txt |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import React from 'react'; | |
import PropTypes from 'prop-types'; | |
import { useKeenSlider } from 'keen-slider/react'; | |
import 'keen-slider/keen-slider.min.css'; | |
KeenSlider.propTypes = { | |
children: PropTypes.node, | |
}; | |
function KeenSlider({ children, ...props }) { | |
const [sliderRef] = useKeenSlider({ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
jq 'def r: walk(if type == "array" then if .[0] then [.[0]] else [] end else (fromjson? | r) // . end); r' a.json | |
# a.json | |
# { | |
# "array": [1,2,3], | |
# "nested_json": "{\"likes\": [1,2,3]}" | |
# } | |
# | |
# output | |
# { |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{ | |
// See https://go.microsoft.com/fwlink/?LinkId=733558 | |
// for the documentation about the tasks.json format | |
"version": "2.0.0", | |
"tasks": [ | |
{ | |
"label": "build", | |
"type": "shell", | |
"command": "chcp 65001; stack build --fast", | |
"group": { |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* @return example: '0zz12948ab0', length fixed | |
*/ | |
function getRandomString(): string { | |
const rand = Math.random() * 2 ** 52; | |
const pad = '00000000000'; | |
const padded = pad + rand.toString(36); | |
return padded.substr(padded.length - pad.length); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import { useEffect, useState } from 'react'; | |
function useInterval(interval, setter) { | |
const [updater] = useState({}); | |
updater.update = setter; | |
useEffect(() => { | |
const id = setInterval(() => { | |
updater.update(c => c + 1); | |
}, interval); | |
return () => clearInterval(id); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* It depends on JSoup. | |
* Kotlin port of https://stackoverflow.com/a/50363077 | |
*/ | |
object Utils { | |
private val block = "address|article|aside|blockquote|canvas|dd|div|dl|dt|" + | |
"fieldset|figcaption|figure|footer|form|h\\d|header|hr|li|main|nav|" + | |
"noscript|ol|output|p|pre|section|table|tfoot|ul|video" | |
private val rxlongWSpaces = Regex("""\s{2,}""") | |
private val rxNestedBlock = Regex("""(\s*?</?(${block})[^>]*?>)+\s*""", RegexOption.IGNORE_CASE) |