In PM2 you can use the PM2 time
option to add timestamps to logs. In a Lambda, it automatically adds the timestamp to CloudWatch. I think the log level is also shown in CloudWatch. Ideally PM2 would output the level of the log too.
This file contains 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
createRunner = () => { | |
const beforeAlls = []; | |
const afterAlls = []; | |
const beforeEaches = []; | |
const afterEaches = []; | |
const tests = []; | |
const test = (description, process) => { | |
tests.push({ | |
description, |
This file contains 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
// Preventing hoisting. We're used to reading top to bottom, so this can be quite confusing. | |
const result = add(1, 2); | |
function add(x, y) { | |
return x + y; | |
}; | |
console.log(result); |
This file contains 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 * as lodash from 'lodash'; | |
import * as moment from 'moment'; | |
// tslint:disable-next-line:no-class | |
class A { | |
public constructor() { return; } | |
} | |
interface B { | |
readonly c: number; |
First of all, make sure you have Node installed on your computer, I'd recommend using NVM. Then create a new folder and make a "index.js" file with the following contents.
const http = require('http');
const server = http.createServer((request, response) => {
response.end('hello');
});
server.listen(1337, () => {
This file contains 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
app = async ({count,fraction}) => { | |
const seconds = Math.floor(count / fraction); | |
const div = document.createElement('div'); | |
const span = document.createElement('span'); | |
span.innerText = `${seconds}.${count % fraction}`; | |
div.style.color = 'white' | |
div.appendChild(span); | |
return div; | |
}; | |
client = () => { |
This file contains 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
// Using forEach. | |
[1,2,3].forEach((item, index, items) => { | |
console.log('item', item); // Logs "1" for the first item, "2" for the second item, and "3" for the third item. | |
console.log('index', index); // Logs "0" for the first item, "1" for the second item, and "2" for the third item. | |
console.log('items', items); // Logs "[1,2,3]" to the console for every item. | |
}); | |
// Using map to add one to each item in an array. | |
const plusOneItems = [1,2,3].map((item, index, items) => { | |
return item + 1; |
This file contains 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
// Using resolved promises with the .then callback. | |
Promise.resolve('hello world').then((message) => { | |
console.log(message); // Logs "hello world" in the console. | |
}); | |
// Using rejected promises with the .catch callback. | |
Promise.reject('error message').catch((err) => { | |
console.error(err); // Logs "error message" in the console. | |
}); |
This file contains 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
for file in $(find src -name '*.js'); do mv "$file" "${file%.js}.ts"; done |
This file contains 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
escapedChar = (char) => { | |
return `\\${char}`; | |
} | |
normChars = `w_~!$&'()*+,;=:-`.split('').map(escapedChar).join(''); | |
otherChars = '\\u00A0-\\uD7FF\\uF900-\\uFDCF\\uFDF0-\\uFFEF\\uFFEF-\\uFFFD'; | |
allChars = `${normChars}${otherChars}`; | |
extChars = `(?:[${allChars}]|(?:\\%[a-f0-9][a-f0-9]))`; | |
capturePattern = (pattern) => { |
NewerOlder