Skip to content

Instantly share code, notes, and snippets.

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

<hmmhmmhm/> hmmhmmhm

๐Ÿงฏ
BURNING!!
View GitHub Profile
@hmmhmmhm
hmmhmmhm / eventTyping.ts
Created July 28, 2020 16:37
ํƒ€์ž…์Šคํฌ๋ฆฝํŠธ ์ด๋ฒคํŠธ ์—๋ฏธํ„ฐ ํƒ€์ž… ํžŒํŠธ ๋ฐฉ๋ฒ• (Typescript EventEmitter Type Hint Solution)
import { EventEmitter } from 'events'
export interface IEventSet {
on(event: 'changed', listener: (name: string) => void): this
on(event: 'deleted', listener: (name: string) => void): this
}
const MyEvent: EventEmitter & IEventSet = new EventEmitter()
const myEvent = new MyEvent()
@hmmhmmhm
hmmhmmhm / rsa.ts
Created August 4, 2020 15:01
RSA ๋น„๋Œ€์นญํ‚ค ์•”ํ˜ธํ™” / ๋ณตํ˜ธํ™” / ์„œ๋ช… / ๊ฒ€์ฆ ์˜ˆ์‹œ (์ž๋ฐ”์Šคํฌ๋ฆฝํŠธ ๊ฒธ ํƒ€์ž…์Šคํฌ๋ฆฝํŠธ)
import forge from 'node-forge'
type encodingType = "ascii" | "utf8" | "utf-8" | "utf16le" | "ucs2" | "ucs-2" | "base64" | "latin1" | "binary" | "hex" | undefined
export const generateKeyPair = (
options: forge.pki.rsa.GenerateKeyPairOptions = { bits: 2048, workers: 2, e: 0x10001 }
): Promise<{
publicKey: string
privateKey: string
}> => {
@hmmhmmhm
hmmhmmhm / why-we-need-to-use-typescript-and-generic.ts
Last active January 11, 2021 02:30
์™œ ํƒ€์ž…์Šคํฌ๋ฆฝํŠธ์—์„œ Generic ์„ ์‚ฌ์šฉํ•ด์•ผํ•˜๋Š”์ง€์™€ ํƒ€์ž…์Šคํฌ๋ฆฝํŠธ Generic ์„ ์“ฐ๊ฒŒ ๋˜๋Š” ์ด์œ ์— ๋Œ€ํ•œ ์‚ฌ์œ 
// ํƒ€์ž…์Šคํฌ๋ฆฝํŠธ ๊ธฐ๋ณธ๊ฐ•์ขŒ๋Š” ์•„๋ž˜๋ฅผ ์ฐธ์กฐํ•ด์ฃผ์‹œ๊ธฐ ๋ฐ”๋ž๋‹ˆ๋‹ค.
// https://typescript-kr.github.io/pages/basic-types.html
// ๊ธฐ๋ณธ ์˜ˆ์‹œ์ž…๋‹ˆ๋‹ค.
let a = 'blabla'
// ํƒ€์ž…์Šคํฌ๋ฆฝํŠธ๋ฅผ ์ด์šฉํ•ด์„œ
// ๋ฌธ์ž์—ด ํ˜•์‹๋งŒ ๋„ฃ์„ ์ˆ˜ ์žˆ๋Š”
// ๋ณ€์ˆ˜๋ฅผ ์„ ์–ธํ•œ ์˜ˆ์‹œ์ž…๋‹ˆ๋‹ค.
let b: string
import { AxiosResponse } from 'axios'
import axios from 'axios'
/**
* @description
* A callback interface that contains the
* communication code requested by the physical server.
*/
export type ProcessType = (link, header) => Promise<AxiosResponse<any>>
@hmmhmmhm
hmmhmmhm / checkDuplicatesInArray.ts
Created August 28, 2020 07:18
checkDuplicatesInArray ํƒ€์ž…์Šคํฌ๋ฆฝํŠธ ๋ฐฐ์—ด ์•ˆ์˜ ๊ฐ™์€ ๊ฐ’ ์ฐพ์•„๋‚ด๊ธฐ
/**
* ๋ฐฐ์—ด ์•ˆ์˜ ๊ฒน์น˜๋Š” ๊ฐ’์„ ์ฐพ์•„๋ƒ…๋‹ˆ๋‹ค.
* @example
* const some = ['1', '2', '3', '4', '5', '1', '1']
* console.log(checkDuplicatesInArray(some))
* // { '1': [ 0, 5, 6 ] }
* @param items
* @param isNeedFirstValue
*/
export const checkDuplicatesInArray = (
@hmmhmmhm
hmmhmmhm / converter.ts
Created August 31, 2020 01:58
.code-snippets ๋ณ€ํ™˜์šฉ ์ฝ”๋“œ
let target = `` // ์—ฌ๊ธฐ ์•ˆ์— ์ฝ”๋“œ๋ฅผ ๋ณต๋ถ™ํ•ด๋„ฃ์œผ์„ธ์š”.
target = target.replace(/\/\//g, '\\/\\/')
let codes = target.split('\n')
let wrapped = ''
for(let code of codes) wrapped += `"${code}",\n`
console.log(wrapped)
/*!
diff v4.0.1
Software License Agreement (BSD License)
Copyright (c) 2009-2015, Kevin Decker <[email protected]>
All rights reserved.
@hmmhmmhm
hmmhmmhm / solapi.ts
Created September 11, 2020 02:36
์†”๋ผํ”ผ SOLAPI ํƒ€์ž…์Šคํฌ๋ฆฝํŠธ typescript ๐Ÿ˜Š
import { config, Group } from 'solapi'
config.init({
apiKey: process.env.SMS_API_KEY,
apiSecret: process.env.SMS_SECRET_KEY,
})
export interface ISendSMSParam {
/**
* ๋ฌธ์ž ๋‚ด์šฉ
@hmmhmmhm
hmmhmmhm / require.ts
Created September 15, 2020 11:38
ํƒ€์ž…์Šคํฌ๋ฆฝํŠธ๋กœ ์ธํ„ฐํŽ˜์ด์Šค ์†์„ฑ์—์„œ ๊ผญ ํ•˜๋‚˜๋Š” ์ฃผ์–ด์ ธ์•ผํ•˜๋Š”, ๋˜๋Š” ๊ผญ ํ•˜๋‚˜๋งŒ ์ฃผ์–ด์ ธ์•ผํ•˜๋Š” ํƒ€์ž… ๋งŒ๋“œ๋Š” ๋ฐฉ๋ฒ•
interface ITestObject {
a: string
b: number
c: Function
d: string[]
}
type RequireAtLeastOne<T, Keys extends keyof T = keyof T> =
Pick<T, Exclude<keyof T, Keys>>
& {
@hmmhmmhm
hmmhmmhm / fpe.ts
Last active June 20, 2021 07:49
javascript format preserving
import fe1 from 'node-fe1-fpe'
export interface IFPESetting {
min: number
max: number
privateKey: string
publicKey: string
}
export const encrypt = ({