Skip to content

Instantly share code, notes, and snippets.

View Atif252's full-sized avatar

Atif Atif252

  • Contanuity
  • Pakistan
View GitHub Profile
@Atif252
Atif252 / sleep.js
Created November 17, 2021 13:11
Script to sleep main thread with Promises
async function sleep(time){
return new Promise(resolve => setTimeout(() => resolve(time), time))
}
@Atif252
Atif252 / settings.json
Last active May 11, 2023 12:01
VS code settings
{
"editor.defaultFormatter": "esbenp.prettier-vscode",
"editor.detectIndentation": true,
// "editor.fontFamily": "Fira Code,Consolas, 'Courier New', monospace",
"editor.fontFamily": "Fira Code",
"editor.fontWeight": "400",
// "editor.fontSize": 16,
// "editor.fontFamily": "Cascadia Code, Consolas, 'Courier New', monospace",
// "editor.fontWeight": "350",
"editor.fontLigatures": true,
import Redis from "ioredis";
import connectRedis from "connect-redis";
import session from "express-session";
const RedisStore = connectRedis(session);
const redis = new Redis(process.env.REDIS_URL);
app.use(
session({
name: COOKIE_NAME,
@Atif252
Atif252 / iterable_objects.js
Last active September 15, 2021 07:22
Making objects iterable
// for iterating over values without generator
var obj = {
a: 1,
b: 2,
c: 3,
[Symbol.iterator]: function(){
var keys = Object.keys(this);
var index = 0
return {
next: () =>
app.use("/graphql", (req, res, next) => {
const startHrTime = process.hrtime();
res.on("finish", () => {
if (req.body && req.body.operationName) {
const elapsedHrTime = process.hrtime(startHrTime);
const elapsedTimeInMs =
elapsedHrTime[0] * 1000 + elapsedHrTime[1] / 1e6;
logger.info({
type: "timing",
@Atif252
Atif252 / youtube_playlist_total_time.js
Created May 23, 2020 10:40
A small script to sum the time of all the videos in the youtube playlist.
var list = document.querySelectorAll('#overlays ytd-thumbnail-overlay-time-status-renderer')
toSec = () => {
var time = 0
list.forEach(video => {
var t = video.innerText.split(':')
var sec = parseInt(t[0]) *60 + parseInt(t[1])
time += sec
})
toHMS(time)
@Atif252
Atif252 / promise.js
Last active July 23, 2020 08:24
Javascript Callbacks and Promises
// CALLBACK
// function loginUser(email, password, callback){
// setTimeout(() => {
// callback({email})
// }, 2000);
// }
// function getUserPosts(email, callback){
@Atif252
Atif252 / mongodb_cheat_sheet.md
Created April 8, 2020 15:08
MongoDB Commands

MongoDB Cheat Sheet

Show All Databases

show dbs

Show Current Database

@Atif252
Atif252 / time-series.csv
Last active March 21, 2020 07:50
Time Series of COVID-19 in Pakistan
02/28 02/29 03/01 03/02 03/03 03/04 03/05 03/06 03/07 03/08 03/09 03/10 03/11 03/12 03/13 03/14 03/15 03/16 03/17 03/18 03/19 3/20
2 4 4 4 5 5 5 6 6 6 6 16 19 20 21 28 53 187 249 307 461 495