Skip to content

Instantly share code, notes, and snippets.

@jeiea
jeiea / sql_format.ts
Last active December 14, 2021 05:06
deno sql formatter for dbeaver
// 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));
@jeiea
jeiea / debug-scroll.md
Last active October 28, 2021 23:05 — forked from cuth/debug-scroll.md
Find the elements that are causing a horizontal scroll. Based on http://css-tricks.com/findingfixing-unintended-body-overflow/

Debug Horizontal Scroll

(() => {
  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 &gt; offsetHeight || bound.top &lt; 0;
@jeiea
jeiea / proxy.js
Created January 16, 2021 22:45
tried monitoring object
{
const collapsedTrace = (message) => {
console.groupCollapsed(message);
console.trace();
console.groupEnd();
};
const isPrimitive = (x) => x !== Object(x);
const proxy = (target, path) => {
@jeiea
jeiea / replace-path.sh
Created September 28, 2020 04:16
Substitute string from all path
# 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
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({
@jeiea
jeiea / jq-skeleton.sh
Last active December 7, 2019 16:36
It extracts json structure with parsing string json and picking first element of array
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
# {
@jeiea
jeiea / tasks.json
Created November 14, 2019 14:14
haskell stack windows vscode build task
{
// 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": {
/**
* @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);
}
@jeiea
jeiea / useInterval.jsx
Created June 26, 2019 02:23
React hook version of useInterval
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);
@jeiea
jeiea / HtmlToPlainText.kt
Created February 12, 2019 09:34
html to plain text kotlin port of https://stackoverflow.com/a/50363077
/**
* 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)