Skip to content

Instantly share code, notes, and snippets.

View ellemedit's full-sized avatar
๐Ÿ 
Working from home

Marshall Han ellemedit

๐Ÿ 
Working from home
  • Seoul
  • 15:55 (UTC +09:00)
View GitHub Profile
#include <stdio.h>
#include <limits.h>
// paper color
#define WHITE 0
#define BLACK 1
class Paper {
private:
int x, y, size;
#include <stdio.h>
int result[2][2];
void multiplyTwoTwoMatrix(int result[][2], int m1[][2], int m2[][2]) {
result[0][0] = (m1[0][0] * m2[0][0] + m1[0][1] * m2[1][0]) % 10000;
result[0][1] = (m1[0][0] * m2[0][1] + m1[0][1] * m2[1][1]) % 10000;
result[1][0] = (m1[1][0] * m2[0][0] + m1[1][1] * m2[1][0]) % 10000;
result[1][1] = (m1[1][0] * m2[0][1] + m1[1][1] * m2[1][1]) % 10000;
}
atom settings
@ellemedit
ellemedit / react.ts
Last active August 12, 2019 15:01
skipping to update state
React.useEffect(() => {
let canceled = false;
axios.post().then((res) => {
if (canceled) {
return;
}
setState(res.data);
});
return () => {
canceled = true;
@ellemedit
ellemedit / README.md
Last active March 17, 2021 01:07
suspenseAll: React Suspense hook sugar for fetching data concurrently.

suspenseAll

React Suspense hook sugar for fetching data concurrently.

Why this needed?

React suspense implementations is that catches a thrown promise in suspense tree. See useSWR and react-query. This blocks next hook till previous promise done if you don't prefetch.

@ellemedit
ellemedit / useScrollLock.ts
Last active April 7, 2020 09:49
React hook for body scroll lock
import React from "react";
import { enableBodyScroll, disableBodyScroll, BodyScrollOptions } from "body-scroll-lock";
export const useScrollLock = (
targetElement?: HTMLElement | Element | null | false,
bodyScrollOption?: BodyScrollOptions
) => {
React.useLayoutEffect(() => {
if (!targetElement) {
return;
@ellemedit
ellemedit / useScreenEffect.ts
Created April 23, 2020 08:10
sometimes we need to care screen itself rather than intersectionObserver.
import * as React from 'react';
export function useScreenEffect(handler: () => void, deps: ReadonlyArray<any>) {
React.useLayoutEffect(() => {
const enhancedHandler = debounceToNextAnimationFrame(handler);
window.addEventListener("scroll", enhancedHandler, canUsePassive && { passive: true });
window.addEventListener("resize", enhancedHandler, canUsePassive && { passive: true });
enhancedHandler();
return () => {
@ellemedit
ellemedit / combineRef.ts
Created April 23, 2020 09:07
sometimes you have to deal with multiple React.Refs. This is short helper
export const combineRef = <T>(...refs: (React.Ref<T> | string | void)[]) => {
// basically, JSX elements allows string refs for backward-compatiblity
// there's certain case runtime check needed
if (process.env.NODE_ENV !== "production" && refs.some((x) => typeof x === "string")) {
throw new Error("string refs are forbbiden");
}
return (node: T | null | undefined) => {
for (const ref of refs) {
if (!ref || typeof ref === "string") {
continue;
@ellemedit
ellemedit / post.md
Last active December 18, 2021 11:02

์ œ ๊ฒฝํ—˜์ด ๋‹น์‹ ์˜ next.js ํ”„๋กœ์ ํŠธ์— ๋„์›€์ด ๋˜๊ฑฐ๋‚˜ ์˜๊ฐ์„ ์ฃผ๋ฉด ์ข‹๊ฒ ์Šต๋‹ˆ๋‹ค.

์™œ ํผ์‹œ์Šคํ„ดํŠธ ๋ ˆ์ด์•„์›ƒ์ด ํ•„์š”ํ•œ๊ฐ€์š”?

๊ฐ€์žฅ ๊ทผ๋ณธ์ ์ธ ์ด์œ ๋Š” ํผ์‹œ์Šคํ„ดํŠธํ•˜์ง€ ์•Š์œผ๋ฉด ๋ชจ๋“  DOM ๋…ธ๋“œ๊ฐ€ ํŒŒ๊ดด๋˜๊ณ  ๋‹ค์‹œ ์ƒ์„ฑ๋œ๋‹ค๋Š” ์  ์ž…๋‹ˆ๋‹ค.

  1. ์ด์ „ ํŽ˜์ด์ง€์˜ DOM Node๊ฐ€ ๋ฒ„๋ ค์ง€๊ธฐ ๋•Œ๋ฌธ์— ํ•ญ์ƒ DOM ์ƒํƒœ๋ฅผ ์žƒ์–ด๋ฒ„๋ฆฝ๋‹ˆ๋‹ค. ์˜ˆ๋ฅผ๋“ค์–ด ๋ ˆ์ด์•„์›ƒ์— ํ”ํ•˜๊ฒŒ ์žˆ์„ ์ˆ˜ ์žˆ๋Š” ๊ฒ€์ƒ‰์ฐฝ ์ž…๋ ฅ, ๋„ค๋น„๊ฒŒ์ด์…˜ ๋ฉ”๋‰ด์˜ ํฌ์ปค์Šค ์ƒํƒœ๊ฐ€ ํŽ˜์ด์ง€ ์ด๋™๋งˆ๋‹ค ์‚ฌ๋ผ์ง‘๋‹ˆ๋‹ค.
  2. ๋‹น์—ฐํ•˜๊ฒŒ๋„ CSS Transition์ด ๋ถˆ๊ฐ€๋Šฅํ•ฉ๋‹ˆ๋‹ค. ์• ๋‹ˆ๋ฉ”์ด์…˜์ด ํ•„์š”ํ•˜๋‹ค๋ฉด ์ „ํ˜€ ๋‹ค๋ฅธ ๋ฐฉ๋ฒ•์œผ๋กœ ๊ตฌํ˜„ํ•ด์•ผ ํ•ฉ๋‹ˆ๋‹ค.

์œ„ ์ด์œ ๋กœ ์ธํ•ด ์• ํ”Œ๋ฆฌ์ผ€์ด์…˜์˜ ์‚ฌ์šฉ์„ฑ๊ณผ ์ ‘๊ทผ์„ฑ์ด ๋–จ์–ด์งˆ ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค.

@ellemedit
ellemedit / README.md
Created January 12, 2021 01:56
Generic distribution problem in TypeScript

I don't know why distribution affect to problems.