Skip to content

Instantly share code, notes, and snippets.

Avatar

Kannan Kannndev

View GitHub Profile
@Kannndev
Kannndev / udp.js
Created Jul 31, 2021 — forked from sid24rane/udp.js
Simple UDP Client and Server in Node.js ==> ( Echo Server )
View udp.js
var udp = require('dgram');
// --------------------creating a udp server --------------------
// creating a udp server
var server = udp.createSocket('udp4');
// emits when any error occurs
server.on('error',function(error){
console.log('Error: ' + error);
@Kannndev
Kannndev / System Design.md
Created Dec 15, 2020 — forked from vasanthk/System Design.md
System Design Cheatsheet
View System Design.md

System Design Cheatsheet

Picking the right architecture = Picking the right battles + Managing trade-offs

Basic Steps

  1. Clarify and agree on the scope of the system
  • User cases (description of sequences of events that, taken together, lead to a system doing something useful)
    • Who is going to use it?
    • How are they going to use it?
@Kannndev
Kannndev / event-loop.md
Created Dec 15, 2020 — forked from jesstelford/event-loop.md
What is the JS Event Loop and Call Stack?
View event-loop.md

Regular Event Loop

This shows the execution order given JavaScript's Call Stack, Event Loop, and any asynchronous APIs provided in the JS execution environment (in this example; Web APIs in a Browser environment)


Given the code

@Kannndev
Kannndev / NestJs-app.e2e-spec.ts
Last active Oct 26, 2020 — forked from firxworx/app.e2e-spec.ts
NestJS Integration/E2E Testing Example with TypeORM, Postgres, JWT
View NestJs-app.e2e-spec.ts
import { Test, TestingModule } from '@nestjs/testing'
import { INestApplication, LoggerService } from '@nestjs/common'
import * as request from 'supertest'
import { AppModule } from './../src/app.module'
class TestLogger implements LoggerService {
log(message: string) {}
error(message: string, trace: string) {}
warn(message: string) {}
debug(message: string) {}
@Kannndev
Kannndev / tagged-template-usecase.js
Created Oct 16, 2020
Funtion that transforms dynamic value to bold elements
View tagged-template-usecase.js
const makeBold = (strings, ...values) => {
let str = '';
strings.forEach((string, i) => {
str += `${string} ${values[i] ? `<strong>${values[i]}<strong>` : ''}`;
});
return str;
}
const name = 'Kannan';
const role = 'Javascript developer';
@Kannndev
Kannndev / tagged-template-sample.js
Last active Oct 16, 2020
Tagged template sample
View tagged-template-sample.js
const generateIntro = (strings, ...values) => {
console.log(strings); // [ 'My name is ', ' and I am a ', '' ]
console.log(values); // [ 'Kannan', 'Javascript developer' ]
let str = '';
strings.forEach((string, i) => {
str += string + (values[i] || '');
});
return str;
}
@Kannndev
Kannndev / tagged-template-intro.js
Last active Oct 16, 2020
Tagged template intro
View tagged-template-intro.js
const Button = styled.button`
color: blue;
`;
const userQuery = gql`
{
users {
firstName
}
}
@Kannndev
Kannndev / node-express-non-blocking.js
Last active Oct 9, 2020
Node non blocking using workers
View node-express-non-blocking.js
const express = require('express');
const { Worker } = require('worker_threads');
const app = express();
app.get('/', function (req, res) {
const worker = new Worker(__dirname + '/worker.js', {
workerData: { ping: 'pong' },
});
worker.on('message', (pi) => {
@Kannndev
Kannndev / node-express-blocking.js
Created Oct 9, 2020
Node js thread blocking example
View node-express-blocking.js
const express = require('express');
const app = express();
function getPi() {
let sum = 0;
for (let n = 0; n < 10000000000; n++) {
let mult = n % 2 === 0 ? 1 : -1;
sum += mult * (1 / (2 * n + 1));
}
return sum * 4;
@Kannndev
Kannndev / Promise-bonus.js
Created Oct 4, 2020
Medium Promise-Bonus tip example
View Promise-bonus.js
const dog = new Promise((resolve, reject) => {
setTimeout(() => {
resolve('🐶');
console.log('I am still executing!!');
}, 1000);
})
const cat = new Promise((resolve, reject) => {
setTimeout(() => {
reject('🐈');
console.log('Even I am!!');