Skip to content

Instantly share code, notes, and snippets.

View sharjeel619's full-sized avatar
🎯
Focusing

Sharjeel Imtiaz sharjeel619

🎯
Focusing
View GitHub Profile
@sharjeel619
sharjeel619 / gist:332f190aadbc8309312a54e7739960c2
Last active March 21, 2024 21:39
Alternative to setTimeout
// These examples Block UI
let startTime = performance.now();
while (performance.now() - startTime < 500) {
// // Do nothing for 500 ms to emulate extremely slow code
}
const wait = (ms) => {
const start = Date.now();
let now = start;
ipconfig /release; ipconfig /flushdns; ipconfig /renew; netsh winsock reset; netsh interface ipv4 reset; netsh interface ipv6 reset; netsh interface ip delete destinationcache;
@sharjeel619
sharjeel619 / index.js
Created January 5, 2022 22:06
Deep compare two objects in javascript
// https://www.30secondsofcode.org/articles/s/javascript-object-comparison
const equals = (a, b) => {
if (a === b) return true;
if (a instanceof Date && b instanceof Date)
return a.getTime() === b.getTime();
if (!a || !b || (typeof a !== 'object' && typeof b !== 'object'))
return a === b;
if (a.prototype !== b.prototype) return false;
const keys = Object.keys(a);
if (keys.length !== Object.keys(b).length) return false;
Below link consists of all of the avatars you see on netflix inlcuding Squid Game, Lucifer, The crown, Money Heist and more..
https://drive.google.com/file/d/1C0Il2a9g-l2RaELFDkMk7NTF7SqrM53Q/view?usp=sharing
@sharjeel619
sharjeel619 / gist:98f5b2cff5eef14fd39cbd399b8df6b2
Last active September 9, 2021 11:54
Powershell command for windows 10 to rename multiple mp3(can be any type of file, just replace the .mp3 extension name) files
get-childitem *.mp3 | foreach { rename-item $_ $_.Name.Replace("string to be replaced", "string to replace") }
@sharjeel619
sharjeel619 / index.js
Created August 31, 2021 14:40
Async/Await in a Loop | Javascript
// sequentially get data from API while waiting for previous call to finish
for (let temp of arr) {
const res = await fetch('https://jsonplaceholder.typicode.com/users/' + temp).then(res => res.json()).then(res => res);
}
// sequentially get data from API asynchronously
const promises = Array(10).fill(null).map((item, index) => fetch(`https://jsonplaceholder.typicode.com/users/${index + 1}`).then(res => res.json()).then(res => res));
for await (const item of promises) {
console.log(await item)
}
import "./styles.css";
import { Suspense, useState, useEffect, Component } from "react";
class ErrorBoundary extends Component {
constructor(props) {
super(props);
this.state = { hasError: false };
}
static getDerivedStateFromError(error) {
ipconfig /release; ipconfig /flushdns; ipconfig /renew; netsh winsock reset; netsh interface ipv4 reset; netsh interface ipv6 reset; netsh interface ip delete destinationcache;
//https://stackoverflow.com/questions/2218999/remove-duplicates-from-an-array-of-objects-in-javascript?page=2&tab=oldest#tab-top
const things = [
{place:"here",name:"stuff"},
{place:"there",name:"morestuff"},
{place:"there",name:"morestuff"}
];
const filtered = things.filter(function({place, name}) {
const key =`${place}${name}`;
@sharjeel619
sharjeel619 / index.html
Last active December 24, 2020 21:50
Implementing simple custom circular mouse pointer
<html>
<head>
<style>
body {
background: #111;
cursor: none;
}
.cursor {
width: 30px;
height: 30px;