Skip to content

Instantly share code, notes, and snippets.

View uyu423's full-sized avatar

Yongwoo Yu (Yowu) uyu423

View GitHub Profile
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;
class A {
constructor(value) {
this.value = value
}
adder() {
this.value += 1;
}
}
const v = new A(10);
@uyu423
uyu423 / simple404page.html
Created March 6, 2017 16:20
갑자기 필요해서 대충 만든 404 Not Found 페이지
<!DOCTYPE html>
<html lang="ko">
<head>
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>Oops !!</title>
<!-- Fonts -->
@uyu423
uyu423 / webpack.config.js
Created March 6, 2017 03:10
simple and default webpack config js (2017.03.06, webpack 2.2.1)
const path = require('path');
module.exports = {
entry: './src/index.js',
output: {
path: path.resolve(__dirname, 'public/'),
filename: 'bundle.js',
},