Skip to content

Instantly share code, notes, and snippets.

@Omkaragrawal
Omkaragrawal / temp.md
Last active February 21, 2023 07:27
temp
Database.raw(
            `(${PersonalLoanApplicationRepository.queryColumn(
              'createdAt',
            )} at time zone 'Asia/Kolkata')::varchar as "customerApplicationInitiatedDate"`,
          ),
@Omkaragrawal
Omkaragrawal / generateRandomString.ts
Last active April 21, 2022 13:08
Use nanoid to generate random unique string. This function has lots of available formatting.
import { customAlphabet, nanoid } from 'nanoid';
import nanoidDictionary from 'nanoid-dictionary';
export enum NanoidStringEnum {
NUMERIC = 'NUMERIC',
LOWERCASE = 'LOWERCASE',
UPPERCASE = 'UPPERCASE',
ALPHABETS = 'ALPHABETS',
ALPHANUMERIC = 'ALPHANUMERIC',
LOWERCASE_NUMERIC = 'LOWERCASE_NUMERIC',

for better understanding, I am showcasing a file downloader as worker.js

let data;
let currentPage = -1;
let currentArticle = 0;
let loaderElement, articleContainer;
let totalPages;
const toggleLoader = () => {
if (loaderElement.classList.contains('hidden')) {
loaderElement.classList.remove('hidden');
} else {
import React, { useEffect, useState } from 'react';
import axios from 'axios';
const App = () => {
let [list, setList] = useState(<>LOADING</>);
useEffect(() => {
// You can use your link here
// I have created corsenabled.herokuapp.com just to bypass the CORS issue. It's only for testing and educational purpose only. No intention to infringe any copyrights or other legal matters
ction f1() {
return this;
}
// In a browser:
f1() === window; // true
// In Node:
f1() === globalThis; // true
'use strict'; // see strict mode
function f2() {
// 'use strict'; or else here
return this;
}
console.log(f2() === undefined) // true
// An object can be passed as the first argument to call or apply and this will be bound to it.
var obj = {a: 'Custom'};
// We declare a variable and the variable is assigned to the global window as its property.
var a = 'Global';
function whatsThis() {
return this.a; // The value of this is dependent on how the function is called
}
function f() {
return this.a;
}
var g = f.bind({a: 'azerty'});
console.log(g()); // azerty
var h = g.bind({a: 'yoo'}); // bind only works once!
console.log(h()); // azerty
@Omkaragrawal
Omkaragrawal / getter-setter.js
Created May 18, 2020 22:21
scope of "this" in getters and setters of regular function
function sum() {
return this.a + this.b + this.c;
}
var o = {
a: 1,
b: 2,
c: 3,
get average() {
return (this.a + this.b + this.c) / 3;