Skip to content

Instantly share code, notes, and snippets.

@jickoo
jickoo / typescript_enum.ts
Created July 25, 2023 09:06
Typescript enum
// String
enum Family {
Mom = 'M',
Daddy = 'D',
Brother = 'B',
}
const indexOf = Object.values(Sizes).indexOf('M' as unknown as Family);
const key = Object.keys(Family)[indexOf];
@jickoo
jickoo / kotlin_handle_epochtime.kt
Last active July 21, 2023 02:41
Kotlin Handle Epochtime #kotlin #epoch #epochtime
import java.time.Instant
import java.time.LocalDateTime
import java.time.ZoneOffset
import java.time.format.DateTimeFormatter
val epochTime = 1689734454000L
val now = System.currentTimeMillis()
val ldt = LocalDateTime.ofInstant(
Instant.ofEpochMilli(now),
@jickoo
jickoo / gwk.sh
Created November 11, 2022 07:04 — forked from SungjinYoo/gwk.sh
#!/bin/bash
#==============================================================================
# GW-Kit
# @author : (origin) yunsang.choi([email protected])
# @author : (forked) jinkwon([email protected])
# @src : (origin) https://gist.github.com/gists/3115022
# @src : (forked) https://github.com/Jinkwon/naver-gw-kit/
#-------
@jickoo
jickoo / useOrientation.ts
Created April 13, 2021 15:24
useOrientation #react #hooks
function WindowAddEventListener(props: WindowAddEventListenerProps) {
const {handleFullScreen} = props;
const orientationType = useOrientationFullScreen(handleFullScreen);
useEffect(() => {
console.debug('orientation type', orientationType);
}, [orientationType]);
}
-----
@jickoo
jickoo / append-prepend-polyfill.ts
Last active June 27, 2023 04:37
append, prepend polyfill
// Source: https://github.com/jserz/js_piece/blob/master/DOM/ParentNode/append()/append().md
(function (arr) {
arr.forEach(function (item) {
if (item.hasOwnProperty('append')) {
return;
}
Object.defineProperty(item, 'append', {
configurable: true,
@jickoo
jickoo / recoilWithUseRef.js
Created March 23, 2021 18:26
recoil with useRef
import { useEffect, useRef } from 'react';
import { useRecoilState } from 'recoil';
import { someAtom } from './recoilstates/someState';
const yourCustomHook = () => {
const [someState, setSomeState] = useRecoilState(someAtom);
const latestSomeState = useRef(someState);
useEffect(()=> {
latestSomeState.current = someState;
@jickoo
jickoo / changeTimeFormat.ts
Created March 19, 2021 08:48
javascript changeTimeFormat
const changeTimeFormat = (seconds: number) => {
var hour = parseInt('' + seconds/3600);
var min = parseInt('' + (seconds%3600)/60);
var sec = Math.floor(seconds%60);
return `${hour}:${min}:${sec}`;
}
@jickoo
jickoo / interval.hook.ts
Created February 22, 2021 16:02 — forked from Danziger/interval.hook.ts
✨ Declarative useTimeout (setTimeout), useInterval (setInterval) and useThrottledCallback (useCallback combined with setTimeout) hooks for React (in Typescript)
import React, { useEffect, useRef } from 'react';
/**
* Use setInterval with Hooks in a declarative way.
*
* @see https://stackoverflow.com/a/59274004/3723993
* @see https://overreacted.io/making-setinterval-declarative-with-react-hooks/
*/
export function useInterval(
callback: React.EffectCallback,
@jickoo
jickoo / StreamPartitioningBy.java
Created July 16, 2019 05:41
java stream Collectors.partitioningBy #java #stream #partitioningBy
Stream<Integer> stream = Stream.of(1,2,3,4);
Map<Boolean, List<Integer>> patition = stream.collect(Collectors.partitioningBy(s -> (s % 2) == 0));
List<Integer> oddList = patition.get(false);
System.out.println(oddList);
List<Integer> evenList = patition.get(true);
System.out.println(evenList);
@jickoo
jickoo / LocalDateTimeSorting.java
Last active April 20, 2020 08:00
sorting by LocalDateTime in List<Model.Map<String, Object>> #LocalDateTime #List #sort #정렬
class LocalDateTimeSorting {
public static void main (String... args) {
List<Model> list = new ArrayList<>();
Model m = new Model();
Map<String, Object> map = new HashMap<>();
map.put("datetime", "2019-07-08 18:10:10.0");