Skip to content

Instantly share code, notes, and snippets.

@av1v3k
av1v3k / debounce_throttle.js
Created March 12, 2026 06:35
Debounce & Throttle
/*Debounce Function*/
//==================
/*Wait for the "quiet" moment.*/
function debounce(func, delay) {
let timeoutId;
return function(...args) {
clearTimeout(timeoutId); // Reset the clock every time
timeoutId = setTimeout(() => {
@av1v3k
av1v3k / .js
Created February 12, 2026 11:39
angular | scenario - clicking any button must cancel any existing API request.
//after click of any buttons in the web application, I need to cancel any existing API request and must trigger the new API request associated with the Button. How do I do it in angular ?
import { Subject, switchMap } from 'rxjs';
// Inside your component
private clickTrigger = new Subject<void>();
// Set up the stream in ngOnInit or the constructor
this.clickTrigger.pipe(
switchMap(() => this.myService.getData())
@av1v3k
av1v3k / map.js
Created December 15, 2025 15:47
Use Map in JS
let m = new Map<string, number>([
['address', 500],
['age', 25],
]);
m.set('street', 400);
console.log(m.get('address'))
console.log(m)
@av1v3k
av1v3k / mocha.js
Created December 6, 2025 03:39
mocha & nodemon command: automated
nodemon --exec mocha -R min
@av1v3k
av1v3k / gist:12ff2d1aff0d6a06adca50973e8944cc
Created December 1, 2025 04:44
Created for generating RSA - Public, Private key pair.
https://gemini.google.com/share/3355cbddb91b
@av1v3k
av1v3k / datetime.js
Created November 7, 2025 11:52
convert UTC to IST using ES6 method
new Intl.DateTimeFormat('en-US', {
timeZone: 'Asia/Calcutta',
hour: "numeric",
minute: "numeric",
second: "numeric",
}).format(new Date(new Date().toISOString()))
@av1v3k
av1v3k / product-form.js, product-action.js
Created October 27, 2025 13:45
useActionState() - starter
Product Form:
============
"use client"
import { useActionState } from "react";
import { productAction } from "@/app/actions/product";
export default function ProductForm() {
@av1v3k
av1v3k / firstLocust.py
Created October 12, 2025 17:12
Basic locust program to test
from locust import User, task, between
class MyUser(User):
wait_time = between(2, 3)
@task
def my_task1(self):
print('First Task 1')
@task
@av1v3k
av1v3k / global_window.js
Last active September 26, 2025 01:17
How to declare global window object in Angular ?
// effects.ts declare as below,
declare global {
interface Window {
dataLayer: any[];
}
}
==============
@av1v3k
av1v3k / pick_omit.js
Created September 20, 2025 06:03
Difference between Pick and Omit in Typescript
interface Address {
street: string;
area: string;
landmark: string;
pincode: number;
}
type previewAddress = Pick<Address, 'pincode' | 'area'>;
type previewAddress2 = Omit<Address, 'pincode'>;