Skip to content

Instantly share code, notes, and snippets.

View DemonDaddy22's full-sized avatar
💻
JavaScripting

Rohan Gupta DemonDaddy22

💻
JavaScripting
View GitHub Profile
@DemonDaddy22
DemonDaddy22 / csvToArray.ts
Last active January 1, 2022 17:13
Util function to convert CSV into an array of objects
const isEmptyString = <T>(value: string | T): boolean =>
typeof value !== 'string' || !value?.trim()?.length;
const csvToArray = (csvString: string, delimiter: string = ','): Array<any> => {
if (isEmptyString(csvString)) return [];
/*
get the first piece of string by slicing the string till the first new line character is encountered
split the sliced string about the delimiter to get the list of headers
*/
@DemonDaddy22
DemonDaddy22 / flatten.js
Created December 8, 2021 18:42
Polyfilling in JavaScript
/**
* Array Polyfill to flatten out an array upto specified depth
*
* @param {number} depth
* @default 1
* @returns new flattened out array object
*
* @example `[1, 2, [3, 4, [5, 6, [7]]]].flatten() -> [1, 2, 3, 4, [5, 6, [7]]]`
* @example `[1, 2, [3, 4, [5, 6, [7]]]].flatten(2) -> [1, 2, 3, 4, 5, 6, [7]]`
*
@DemonDaddy22
DemonDaddy22 / executionContext.md
Last active September 11, 2021 17:19
All about JAVASCRIPT! This gist contains numerous helpful links, resources and stuff related to JS.

EXECUTION CONTEXT

Execution context (EC) is defined as the environment in which the JavaScript code is executed.

  • JavaScript is a synchronous, single-threaded language.
  • Everything in JS happens inside an Execution Context(EC).
  • EC is created in 2 phases - memory allocation (Variable Environment) and code execution (Thread of Execution).
  • MEMORY ALLOCATION - all the variables and functions are initialised and stored as key-value pairs here.
  • CODE EXECUTION - entire code is executed line-by-line here, values are assigned to variables and functions are executed. For every function call, the JS engine creates a new Function Execution Context. The Function Execution Context is similar to the Global Execution Context, but instead of creating the global object, it creates the arguments object that contains a reference to all the parameters passed into the function.
  • To keep track of all the execution contexts, including the Global Execution Context and Function Execution Contexts, t
@DemonDaddy22
DemonDaddy22 / frosty.json
Created August 22, 2021 13:12
zsh shell indeed improves productivity with plugins and stuff, and with ohmyzsh, one can even style it to one's liking. I have created couple of theme profiles which can be easily imported in your iTerm2 (or any terminal which supports zsh) preferences.
{
"Working Directory" : "\/Users\/rohangupta",
"Prompt Before Closing 2" : false,
"Selected Text Color" : {
"Red Component" : 0.12941176470588237,
"Color Space" : "sRGB",
"Blue Component" : 0.12941176470588237,
"Alpha Component" : 1,
"Green Component" : 0.12941176470588237
},
@DemonDaddy22
DemonDaddy22 / .eslintrc.cjs
Last active August 22, 2021 13:05
ESLint Rules used by me across my various projects. First file is the one that I use for backend stuff and second one for front-end part. To enforce these rules, I also add prettier plugin in my projects and specify some basic config rules to setup prettier.
module.exports = {
parser: '@babel/eslint-parser',
env: {
browser: true,
es2021: true,
node: true,
},
parserOptions: {
ecmaVersion: 12,
sourceType: 'module',