Skip to content

Instantly share code, notes, and snippets.

View tikarammardi's full-sized avatar
🎯
Focusing

Tikaram Mardi tikarammardi

🎯
Focusing
View GitHub Profile
const net = require("net");
const readline = require("readline");
const rl = readline.createInterface({
input: process.stdin,
output: process.stdout,
});
const port = process.env.PORT ?? 3000;
const host = process.env.HOST ?? "127.0.0.1";
const net = require("net");
const port = process.env.PORT ?? 3000;
const server = net.createServer((socket) => {
console.log("Client connected");
socket.on("data", (data) => {
console.log(`Server Received msg: ${data}`);
socket.write(`Server has received your message: ${data}`);
});
#!/bin/sh
# set -x verbose #echo on
# Find files with trailing whitespace
for file in `git diff --check --cached | grep '^[^+-]' | grep -o '^.*[0-9]\+:'` ; do
file_name=`echo ${file} | grep -o '^[^:]\+'`
line_number=`echo ${file} | grep -oP '(?<=:)[0-9]+(?=:)'`
sed -i '' "${line_number}s/[[:space:]]*$//" ${file_name}
git add ${file_name}
done
@tikarammardi
tikarammardi / js
Last active November 23, 2020 17:09
sub-type error-eg
function setWindowSize(size){
let startWindow = 10;
let endWindow = 30;
if(size > endWindow){
throw new RangeError(` Size ${size} is out of range`);
}
//do some more coding
}
@tikarammardi
tikarammardi / a.js
Last active August 9, 2022 02:48
check specific error types
try{
// some code to run
}catch(e){
if(e instanceof EvalError ){
//do something
}else{
//do something else
}
@tikarammardi
tikarammardi / b.js
Last active August 9, 2022 02:48
create, throw, and handle the error
// main
function main(){
try{
if(conditon){
throw new Error('We have error here, bye bye , see you in catch block');
}
// this part of code it won't reach
}catch(e){
console.log('Error is :', e);
}