Skip to content

Instantly share code, notes, and snippets.

View jeongtae's full-sized avatar
🏠
Working from home

Dylan (Jeongtae Kim) jeongtae

🏠
Working from home
View GitHub Profile
@jeongtae
jeongtae / index.js
Created April 16, 2024 07:24
bookmarklet test
alert('hello world');
@jeongtae
jeongtae / useFetcher.ts
Last active May 30, 2023 04:49
[Vue composable] useFetcher
import { ref } from 'vue';
const CacheMap = new Map<string, QuerablePromise<any>>();
export function useFetcher<T>(key: string, fetcherFn: () => Promise<T>) {
const data = ref<T | null>(null);
const error = ref<any | null>(null);
let cache = CacheMap.get(key);
if (cache === undefined) {
@jeongtae
jeongtae / useExpirableStorage.ts
Last active May 30, 2023 04:49
[Vue composable] useExpirableStorage
const LS_KEY_PREFIX = '__expirable-storage-';
export interface ExpirableStorage<T = any> {
getItem(key: string): T | null;
hasItem(key: string): boolean;
setItem(key: string, value: T, expiresAt: number): void;
}
/** 설정한 기간이 지나면 파기되는 스토리지를 만든다. */
export function useExpirableStorage<T = any>(
@jeongtae
jeongtae / useAsyncJobsState.ts
Last active May 30, 2023 04:50
[Vue composable] This composable helps to track a pending state of async functions
import { computed, ref } from 'vue';
/**
* Tracks a pending state of async functions.
* 등록된 비동기 잡 함수의 진행 상태를 추적합니다.
*/
export function useAsyncJobsState() {
const pendingJobsCount = ref(0);
const isPending = computed(() => pendingJobsCount.value > 0);
@jeongtae
jeongtae / useReactiveParameter.ts
Last active May 30, 2023 04:50
[Vue composable] This composable helps the argument of Vue Composable guarantee Vue Reactivity.
import { MaybeRef } from '@vueuse/core';
import { computed, ComputedRef, unref } from 'vue';
/**
* Union generic type of `Raw Value` | `Ref Value`, `Value Getter`.
* `Raw 값`, `Ref 값`, `값 Getter` 타입을 모두 포용하는 Union Generic 타입입니다.
*/
export type ReactiveParam<T> = T extends Function ? never : MaybeRef<T> | (() => T);
/** Unwraps `ReactiveParam<T>` and converts it to `ComputedRef<T>`.
type AnyFunction = (...args: any) => void;
export function rafThrottle<T extends AnyFunction>(func: T) {
let rafHandle: number | null = null;
const throttled: {
(this: ThisType<T> | void, ...args: Parameters<T>): void,
cancel(): void,
} = Object.assign(
function (this: any, ...args: any) {
import { onUnmounted, Ref, watch } from '@vue/composition-api';
export type UseIntersectionObserverEntry<E extends HTMLElement> =
IntersectionObserverEntry & { target: E };
export type UseIntersectionObserverCallback<E extends HTMLElement> = (
entry: UseIntersectionObserverEntry<E>,
) => void;
export const useIntersectionObserver = <E extends HTMLElement>(
@jeongtae
jeongtae / README.md
Last active January 14, 2024 17:39
create-map-transform-fn

create-map-transform-fn

Utility function to solve issue#288 of class-transformer: ES6 Maps are not constructed properly

📦 Install

npm i gist:f65ddd8f17f8c388659aab76890f194b
# or
yarn add gist:f65ddd8f17f8c388659aab76890f194b
@jeongtae
jeongtae / utils.py
Created May 14, 2020 03:33
definition of build_url_with_query function for Python Django
from django.utils.encoding import escape_uri_path
def build_url_with_query(origin_url: str, **params) -> str:
"""
Builds an URL with query string for the GET requesting method.
"""
mapped_params = map(
lambda k: f"{escape_uri_path(k)}={escape_uri_path(params[k])}", params
)
@jeongtae
jeongtae / animation.scss
Created March 1, 2020 03:11
Sass keyframe animation mixin
@mixin animation(
$duration: 1s,
// ease, linear, ease-in, ease-out, ease-in-out, step-start, step-end, steps(), cubic-bezier()
$timing-function: linear,
$delay: 0s,
// infinite
$iteration-count: 1,
// normal, reverse, alternate, alternate-reverse
$direction: normal,
// none, forwards, backwards, both