Skip to content

Instantly share code, notes, and snippets.

View tlcheah2's full-sized avatar
💭
Keep thinking and writing code

Tek Loon tlcheah2

💭
Keep thinking and writing code
View GitHub Profile
variable "instance_name" {
description = "Value of the name tag for EC2 Instance"
type        = string
default    = "TFExampleApp"
}
@tlcheah2
tlcheah2 / side-effects-solution.js
Created December 13, 2021 12:28
A simple example for side effect solution
let finalOuput;
function multiplyByTwo(inputNumber) {
const result = inputNumber * 2;
return result;
}
finalOuput = multiplyByTwo(6);
@tlcheah2
tlcheah2 / side-effects.js
Last active December 13, 2021 12:20
An example to demonstrate side effect
let finalOuput;
function multiplyByTwo(inputNumber) {
const result = inputNumber * 2;
finalOutput = result;
return result;
}
multiplyByTwo(6);
@tlcheah2
tlcheah2 / ouput-argument.js
Created December 6, 2021 13:44
Avoid Output Argument Example - Clean code Chapter 3
let customer = {
id: 1,
name: 'Steve'
};
function updateCustomerName(customer) {
customer.name = 'James';
}
updateCustomerName(customer);
@tlcheah2
tlcheah2 / cook-ramen.js
Created November 28, 2021 11:56
Cook Ramen Before Refactor Example - Clean Code Chapter 3
function prepareBroth() {}
function cookNoodle() {}
function cookRamen(){
const preparedIngredients = ingredients.map((ingredient) => {
if (ingredent.needCut) {
// Perform cut
}
@tlcheah2
tlcheah2 / cook-ramen.js
Last active November 28, 2021 11:47
Cook Ramen Refactored Example - Clean Code Chapter 3
function prepareIngredients(ingredients) {
return ingredients.map((ingredient) => {
if (ingredent.needCut) {
// Perform cut
}
if (ingredent.needClean) {
// Perform clean
}
});
@tlcheah2
tlcheah2 / index.js
Created November 26, 2021 02:43
getFileContents after refactor - Clean Code Chapter 3 Example
const fs = require('fs');
function readCsvFile() {
return fs.readFileSync('./random-word.csv', { encoding: 'utf8' });
}
function parseFileContent(content) {
return content.split(',').map((word) => {
return word.trim();
});
@tlcheah2
tlcheah2 / index.js
Created November 26, 2021 02:06
getFileContents before refactor - Clean Code Chapter 3 Example
const fs = require('fs');
function getFileContents() {
const content = fs.readFileSync('./random-word.csv', { encoding: 'utf8' });
const words = content.split(',').map((word) => {
return word.trim();
});
return words;
}
@tlcheah2
tlcheah2 / readFileUsingSynchoronousWay.js
Created November 17, 2021 02:25
Read File using fs.readFileSync
const fs = require('fs');
function readCsv() {
const content = fs.readFileSync('./random-word.csv');
console.log('content', content);
console.log('Finished reading file');
}
console.log('Start reading file');
readCsv();
@tlcheah2
tlcheah2 / readFileUsingCallbackway.js
Last active November 17, 2021 02:15
Read File using the fs.readFile
// The callback way
const fs = require('fs');
function readCsv() {
fs.readFile('./random-word.csv', (err, data) => {
if (err) {
console.error('Error in read csv');
}
console.log('content', data);
console.log('Finished reading file');