Skip to content

Instantly share code, notes, and snippets.

Avatar

Yu Yongwoo uyu423

View GitHub Profile
View RedisRepository.ts
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 Dec 17, 2019
async function series do using array reduce
View asyncFunctionSeriesDoUsingArrayReduce.ts
const array = [];
array.reduce((promise, payload) => {
return promise.then(() => {
// something await function do
});
}, Promise.resolve());
@uyu423
uyu423 / NodejsSingletonPattern.js
Created Jan 3, 2018
Common Node.js Singleton pattern
View NodejsSingletonPattern.js
// Singleton.js
class Singleton {
constructor(initValue = 0) {
this.value = initValue;
}
setValue(value) {
this.value += value;
}
getValue() {
return this.value;
View DBAndApiToChannelIoSync.js
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 Mar 20, 2020
서버에서 나는 Exception을 텔레그램 봇으로 알림을 받아보자
View CatchApiServerExceptionWithTelegramBot.js
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 Apr 21, 2018
Node.js 에서 사용할 수 있는 효율적인 Repository Pattern 에 대해 생각해보자
View myNodejsRepositoryPattern.js
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);
}
View valueObject.js
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;
View class_question.js
class A {
constructor(value) {
this.value = value
}
adder() {
this.value += 1;
}
}
const v = new A(10);
@uyu423
uyu423 / simple404page.html
Created Mar 6, 2017
갑자기 필요해서 대충 만든 404 Not Found 페이지
View simple404page.html
<!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 Mar 6, 2017
simple and default webpack config js (2017.03.06, webpack 2.2.1)
View webpack.config.js
const path = require('path');
module.exports = {
entry: './src/index.js',
output: {
path: path.resolve(__dirname, 'public/'),
filename: 'bundle.js',
},