This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 과도하게 추상화된 코드 | |
interface Processor { | |
process(); | |
} | |
class OrderProcessor: Processor { ... } | |
class PaymentProcessor: Processor { ... } | |
// 실제론 단순히 order.process(), payment.process() 호출할 뿐... |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 비트 연산으로 해시 충돌 최소화 | |
// (단순한 % 연산보다 빠르지만 의도를 이해하기 어려우므로 설명을 남김) | |
val hash: Int = key.hashCode() & (capacity - 1); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 코틀린 숙련도가 낮은 팀에선 아래처럼 작성하는 편이 이해하기 쉽다 | |
val user = userRepository.findById(userId) | |
if (user != null) { | |
sendWelcomeMessage(user) | |
} | |
// 숙련된 팀이라면 코틀린스럽게 더 간결하게 쓸 수 있다 | |
userRepository.findById(userId)?.let { sendWelcomeMessage(it) } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import ioredis from 'ioredis'; | |
import { DateTime } from 'luxon'; | |
interface IRedisOption { | |
expire: number | false; | |
} | |
type IRedisResponse<T> = IRedisHaveDataSuccessResponse<T> | IRedisNotHaveDataSuccessResponse | IRedisFailureResponse; | |
interface IRedisCommonResponse { |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const array = []; | |
array.reduce((promise, payload) => { | |
return promise.then(() => { | |
// something await function do | |
}); | |
}, Promise.resolve()); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Singleton.js | |
class Singleton { | |
constructor(initValue = 0) { | |
this.value = initValue; | |
} | |
setValue(value) { | |
this.value += value; | |
} | |
getValue() { | |
return this.value; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const knex = require('knex')({ | |
client: 'mysql', | |
connection: { | |
host: 'hostname', | |
user: 'usernmae', | |
password: 'password', | |
database: 'dbname', | |
}, | |
}); | |
const fetch = require('node-fetch'); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) { |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; |
NewerOlder