Skip to content

Instantly share code, notes, and snippets.

devCola

Block or report user

Report or block devCola

Hide content and notifications from this user.

Learn more about blocking users

Contact Support about this user’s behavior.

Learn more about reporting abuse

Report abuse
View GitHub Profile
@devCola
devCola / withErrorHandler.ts
Created Jul 5, 2018
wrapper for common error handling
View withErrorHandler.ts
async function withErrorHandler(
run: () => Promise<HTTPResponseType>,
options?: {
},
) {
try {
return run();
} catch (e) {
// handle error here.
View tslint.json
{
"extends": "tslint-microsoft-contrib",
"rules": {
"completed-docs": false,
"trailing-comma": [
true,
{
"multiline": "always",
"singleline": {
"functions": "ignore",
@devCola
devCola / ts-gen.ts
Created Jun 30, 2018
TS Generator example
View ts-gen.ts
function* generateRandomNumber() {
let count = 1;
// tslint:disable
while (true) {
count++;
console.log(count);
yield Math.random();
}
}
@devCola
devCola / node_setting.md
Last active Jun 20, 2018
Node 세팅하기
View node_setting.md

Node Settings

Why NVM:

  1. Permission 문제 해결:
    • System Node 로 설치되있으면:
      • npm install -g typescript 했을 때 permission 에러 (sudo 써야)
      • 해결 하려면 (sudo 안쓰려면): /usr/local/??? 등의 폴더들에게 permission 줘야
      • 사용자가 늘면 group permission 도 하고
      • ... 으아!
    • NVM 으로 node 설치하면
@devCola
devCola / ramda_example.ts
Created Jun 19, 2018
ramda currying typescript
View ramda_example.ts
// yarn add ramda @types-ramda
import {
curry,
} from 'ramda';
function test(a: string, b: number, c: boolean) {
// ...
}
const curried1 = curry(test);
View any_module.d.ts
// temporary fix for any 3rd party lib. without TS definition
declare module 'any-module' {
const a: any | {
default: any
};
export = a;
}
@devCola
devCola / promise_catch_return_promise.ts
Created Jun 8, 2018
PromiseJS when catch() callback returns another promise
View promise_catch_return_promise.ts
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 / stripMargin.ts
Last active Jun 12, 2019
typescript stripMargins
View stripMargin.ts
// 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');
}
You can’t perform that action at this time.