Skip to content

Instantly share code, notes, and snippets.

View hmmhmmhm's full-sized avatar
๐Ÿงฏ
BURNING!!

<hmmhmmhm/> hmmhmmhm

๐Ÿงฏ
BURNING!!
View GitHub Profile
@hmmhmmhm
hmmhmmhm / foundExample.ts
Created September 17, 2021 02:50
Check Map For Some
const list = [{ text: "a" }, { text: "b" }, { text: "c" }, { text: "d" }];
// Map & Filter
const i1 = list
.map((item, index) => (item.text === "c" ? index : null))
.filter((item) => item !== null)[0]!;
// For
let i2 = 0;
for (const item of list) {
import Router from 'next/router'
import { useEffect } from 'react'
export default function StaticRoute() {
useEffect(() => {
Router.replace(window.location.pathname, window.location.pathname, {
shallow: true
})
}, [])
return null
@hmmhmmhm
hmmhmmhm / buffer.ts
Created October 12, 2021 04:40
typescript ab2str & str2ab
/**
* Converts an ArrayBuffer to a String.
*
* @param buffer - Buffer to convert.
* @returns String.
*/
export const arrayBufferToString = (buffer: ArrayBuffer) =>
String.fromCharCode.apply(null, Array.from(new Uint16Array(buffer)))
/**
@hmmhmmhm
hmmhmmhm / fileInput.ts
Last active October 12, 2021 09:01
Virtual File Input
type FileCallbackType = (
event:
| {
file: File
thumbnail: string | ArrayBuffer | null
getFormData: (name: string) => FormData
}[]
| void
) => unknown
@hmmhmmhm
hmmhmmhm / packing.ts
Last active November 1, 2021 07:21
typescript grid item sort & align algorithm
export interface PackNode {
w: number
h: number
x?: number
y?: number
used?: boolean
right?: PackNode
down?: PackNode
fit?: PackNode
}
@hmmhmmhm
hmmhmmhm / download.js
Last active October 16, 2021 21:19
virtual file download
const url = `/component.js`;
const a = document.createElement("a");
a.href = url;
a.download = url.split("/").pop()!;
document.body.appendChild(a);
a.click();
document.body.removeChild(a);
@hmmhmmhm
hmmhmmhm / README.md
Created November 25, 2021 10:57
CodeWatch Personal information processing policy.

Codewatch is a watch theme that does not collect or store personal information. If you have any related questions, please contact us in the email below. pm2@kakao.com

@hmmhmmhm
hmmhmmhm / modulo.ts
Created December 15, 2021 06:34
Modulo in javascript (and typescript).
// ts
const mod = (n: number, m: number) => {
let r = n % m;
return Math.floor(r >= 0 ? r : r + m);
};
// js
const mod = (n, m) => {
let r = n % m;
return Math.floor(r >= 0 ? r : r + m);
const Excel = require("exceljs");
const workbook = new Excel.Workbook();
void (async () => {
const excel = await workbook.xlsx.readFile("before.xlsx");
const worksheets = excel.worksheets;
// ์ฒซ ๋ฒˆ์งธ ์‹œํŠธ์ •๋ณด ์–ป์–ด์˜ค๊ธฐ
const originSheet = worksheets[0];
@hmmhmmhm
hmmhmmhm / smallest-sandbox.js
Last active April 7, 2022 18:21
Lexical Free Smallest Sandbox
const outerLexicalEnvironment = {
window: {},
global: {},
Object: {},
Function: {},
self: {},
globalThis: {},
Error: {},
TypeError: {},
JSON: {},