Skip to content

Instantly share code, notes, and snippets.

View rajivnarayana's full-sized avatar

Rajiv Narayana Singaseni rajivnarayana

View GitHub Profile
@rajivnarayana
rajivnarayana / 1.callback_hell.js
Created May 18, 2021 14:36
Javascript - Async, Await, Promises
const fs = require("fs");
const path = "./temp.txt";
const errorCallback = (err) => {
console.log(err);
console.log("Failed writing to the files");
}
const doneCallback2 = (err) => {
if(err) {
@rajivnarayana
rajivnarayana / README.MD
Created May 11, 2021 10:59
NodeJS - Create a server from core modules.

Objective

Create a bare bones server using nodejs core modules and not expressjs.

Which core modules are used

  1. http
  2. url

Concepts

@rajivnarayana
rajivnarayana / svg-demo.html
Created April 16, 2021 12:42
Svg overlap maps
<html>
<head>
<style>
.body {
background-color: green;
}
.source_container {
position: relative;
padding: 20px 20px;
background-color: red;
@rajivnarayana
rajivnarayana / promise-async-error.js
Last active February 11, 2021 14:47
nodejs async waterfall error workaround
/**
* This is a modified form of issue https://github.com/caolan/async/issues/1611 with title
* "waterfall Callback was already called. #1611"
*
* Reason:
* First, the line no 16 executes causing the next waterfall step to execute.
* Subsequently line no 25 causes an exception which is gaurded by Promise.then in the first step
* which in turn causes catch block in line no 21 to be executed.
*/
@rajivnarayana
rajivnarayana / roman-numerals.js
Created February 10, 2021 20:30
A Javascript program to convert a given number to its roman numeral representation
/**
* Write a program to encode a given number in roman numeral form
// I - 1
// V - 5
// X - 10
// L - 50
// C - 100
// D - 500
// M - 1000
* @param {*} number
@rajivnarayana
rajivnarayana / problem.py
Created January 30, 2021 09:52
Data transformation in python.
# Online Python compiler (interpreter) to run Python online.
# Write Python 3 code in this online editor and run it.
students = [
{"name": "user1", "marks": 10, "gender": "male"},
{"name": "user2", "marks": 12, "gender": "male"},
{"name": "user3", "marks": 15, "gender": "male"},
{"name": "user4", "marks": 20, "gender": "female"},
{"name": "user5", "marks": 25, "gender": "female"}]
print("1: print all student names")
@rajivnarayana
rajivnarayana / async-await-hello-world.js
Created September 10, 2020 08:20
A sample program that demonstrates how async await works in javascript.
//Rentrant function. - Software terminology
//generator functions. - javascript terminology ()
//Read more here https://codeburst.io/understanding-generators-in-es6-javascript-with-examples-6728834016d5
function wait() {
return new Promise(resolve => setTimeout(resolve, 3000));
}
async function sayAwaitHello() {
await wait();
@rajivnarayana
rajivnarayana / array_promises.js
Created September 9, 2020 19:04
Use array functions with async callbacks
/**
* A simple promise generator that waits for n seconds and returns a promise that resolves to n.
*/
function wait(n) {
return new Promise(resolve => setTimeout(resolve.bind(null, n), n * 1000));
}
/**
* A simple function that invokes promise and displays the result.
*/
@rajivnarayana
rajivnarayana / problem.txt
Last active August 4, 2020 17:37
Transforming an array of objects in javascript
[
{"name": "user1", "marks": 10, "gender": "male"},
{"name": "user2", "marks": 12, "gender": "male"},
{"name": "user3", "marks": 15, "gender": "male"},
{"name": "user4", "marks": 20, "gender": "female"},
{"name": "user5", "marks": 25, "gender": "female"},
]
Expected output :
@rajivnarayana
rajivnarayana / ClampedHeaderScrolling.tsx
Created May 23, 2020 11:21
A clamped header scrolling with dynamic header height for React Native.
import React, {Component} from 'react';
import {
Text,
View,
Animated,
StyleSheet,
SafeAreaView,
FlatList,
LayoutChangeEvent,
} from 'react-native';