Skip to content

Instantly share code, notes, and snippets.

View devCola's full-sized avatar

devCola

View GitHub Profile
@devCola
devCola / promise_catch_return_promise.ts
Created June 8, 2018 01:52
PromiseJS when catch() callback returns another promise
new Promise((resolve, reject) => reject(1))
.catch((result) => {
console.log(result);
return new Promise((resolve, reject) => resolve(2))
})
.then((result) => console.log(result))
// result: 1, 2
@devCola
devCola / any_module.d.ts
Created June 15, 2018 08:38
애니팡!
// temporary fix for any 3rd party lib. without TS definition
declare module 'any-module' {
const a: any | {
default: any
};
export = a;
}
@devCola
devCola / ramda_example.ts
Created June 19, 2018 09:15
ramda currying typescript
// yarn add ramda @types-ramda
import {
curry,
} from 'ramda';
function test(a: string, b: number, c: boolean) {
// ...
}
const curried1 = curry(test);
@devCola
devCola / node_setting.md
Last active June 20, 2018 08:24
Node 세팅하기

Node Settings

Why NVM:

  1. Permission 문제 해결:
    • System Node 로 설치되있으면:
      • npm install -g typescript 했을 때 permission 에러 (sudo 써야)
      • 해결 하려면 (sudo 안쓰려면): /usr/local/??? 등의 폴더들에게 permission 줘야
      • 사용자가 늘면 group permission 도 하고
      • ... 으아!
  • NVM 으로 node 설치하면
@devCola
devCola / ts-gen.ts
Created June 30, 2018 06:11
TS Generator example
function* generateRandomNumber() {
let count = 1;
// tslint:disable
while (true) {
count++;
console.log(count);
yield Math.random();
}
}
@devCola
devCola / tslint.json
Created June 30, 2018 09:35
tslint-1
{
"extends": "tslint-microsoft-contrib",
"rules": {
"completed-docs": false,
"trailing-comma": [
true,
{
"multiline": "always",
"singleline": {
"functions": "ignore",
@devCola
devCola / withErrorHandler.ts
Created July 5, 2018 12:42
wrapper for common error handling
async function withErrorHandler(
run: () => Promise<HTTPResponseType>,
options?: {
},
) {
try {
return run();
} catch (e) {
// handle error here.
@devCola
devCola / stripMargin.ts
Last active June 12, 2019 12:04
typescript stripMargins
// NOT MINE - FROM SOMEONE @ INTERNET
// same as scala's stripMargin
export function stripMargin(template: TemplateStringsArray, ...expressions: any[]) {
let result = template.reduce((accumulator, part, i) => {
return accumulator + expressions[i - 1] + part
})
return result.replace(/\r?(\n)\s*\|/g, '$1');
}