Skip to content

Instantly share code, notes, and snippets.

View uyu423's full-sized avatar

Yongwoo Yu (Yowu) uyu423

View GitHub Profile
// 과도하게 추상화된 코드
interface Processor {
process();
}
class OrderProcessor: Processor { ... }
class PaymentProcessor: Processor { ... }
// 실제론 단순히 order.process(), payment.process() 호출할 뿐...
// 비트 연산으로 해시 충돌 최소화
// (단순한 % 연산보다 빠르지만 의도를 이해하기 어려우므로 설명을 남김)
val hash: Int = key.hashCode() & (capacity - 1);
@uyu423
uyu423 / EasyToReadCodeSample01.kt
Created September 2, 2025 14:48
EasyToReadCodeSample01.kt
// 코틀린 숙련도가 낮은 팀에선 아래처럼 작성하는 편이 이해하기 쉽다
val user = userRepository.findById(userId)
if (user != null) {
sendWelcomeMessage(user)
}
// 숙련된 팀이라면 코틀린스럽게 더 간결하게 쓸 수 있다
userRepository.findById(userId)?.let { sendWelcomeMessage(it) }
import ioredis from 'ioredis';
import { DateTime } from 'luxon';
interface IRedisOption {
expire: number | false;
}
type IRedisResponse<T> = IRedisHaveDataSuccessResponse<T> | IRedisNotHaveDataSuccessResponse | IRedisFailureResponse;
interface IRedisCommonResponse {
@uyu423
uyu423 / asyncFunctionSeriesDoUsingArrayReduce.ts
Created December 17, 2019 05:15
async function series do using array reduce
const array = [];
array.reduce((promise, payload) => {
return promise.then(() => {
// something await function do
});
}, Promise.resolve());
@uyu423
uyu423 / NodejsSingletonPattern.js
Created January 3, 2018 20:17
Common Node.js Singleton pattern
// Singleton.js
class Singleton {
constructor(initValue = 0) {
this.value = initValue;
}
setValue(value) {
this.value += value;
}
getValue() {
return this.value;
const knex = require('knex')({
client: 'mysql',
connection: {
host: 'hostname',
user: 'usernmae',
password: 'password',
database: 'dbname',
},
});
const fetch = require('node-fetch');
@uyu423
uyu423 / CatchApiServerExceptionWithTelegramBot.js
Last active March 20, 2020 16:48
서버에서 나는 Exception을 텔레그램 봇으로 알림을 받아보자
import express from 'express';
import fetch from 'node-fetch';
const app = express();
app.get('/error/:number', (request, response) => {
try {
const result = occurError(request.params.number);
response.json(result);
} catch (error) {
@uyu423
uyu423 / myNodejsRepositoryPattern.js
Last active April 21, 2018 16:28
Node.js 에서 사용할 수 있는 효율적인 Repository Pattern 에 대해 생각해보자
import config from 'getconfig';
import knex from 'knex';
import mongoose from 'mongoose';
import { User, Log } from './domainObjects';
import { Log as LogSchema } from './mongodbSchemas';
class MySQL {
constructor() {
this.driver = knex(config.DATABASE.MYSQL);
}
class Money {
constructor(value) {
if (value < 0) throw Error('Money Type Valiation Exception');
this.value = value;
}
}
class Email {
constructor(email) {
const regExp = /^[0-9a-zA-Z]([-_\.]?[0-9a-zA-Z])*@[0-9a-zA-Z]([-_\.]?[0-9a-zA-Z])*\.[a-zA-Z]{2,3}$/i;