Skip to content

Instantly share code, notes, and snippets.

@night-fury-rider
night-fury-rider / typescript-generics.tsx
Created September 28, 2025 14:22
TypeScript - Generics
import React from "react";
import { Select, MenuItem, FormControl, InputLabel, Box } from "@mui/material";
interface MovieFilterProps<T extends string | number> {
primaryOptionLabel?: string;
primaryOptionValue?: T;
options: T[];
selectedFilter: T;
setSelectedFilter: React.Dispatch<React.SetStateAction<T>>;
title: string;
@night-fury-rider
night-fury-rider / performance-throttling.js
Created May 16, 2025 03:30
Performance - Throttling
// Make sure we have a input field with id "inputData" in our DOM.
const inputData = document.getElementById("inputData");
const getDataFromServer = (name) => {
console.log(`${name} :: getting Data from Server...........`);
};
const throttle = (callback, delay) => {
delay = delay || 2000;
@night-fury-rider
night-fury-rider / performance-debounce.js
Created May 16, 2025 03:17
Performance - Debounce
// Make sure we have a input field with id "inputData" in our DOM.
const inputData = document.getElementById("inputData");
const getDataFromServer = (name) => {
console.log(`${name} :: getting Data from Server...........`);
};
const debounce = (callback, delay) => {
delay = delay || 2000;
@night-fury-rider
night-fury-rider / design-pattern-memoization.js
Created May 16, 2025 01:43
Design Pattern - Memoization
const memoize = (func) => {
const cache = {};
return (...args) => {
const key = args.toString();
if (cache[key]) {
console.log(`Getting from the cache for ${key}`);
return cache[key];
} else {
@night-fury-rider
night-fury-rider / design-pattern-async-iterator.js
Created May 16, 2025 01:35
Design Pattern - Async Iterator
class MyAsyncIterator {
constructor() {
this.queue = []; // To hold actual values
this.waitlist = []; // To hold the callbacks
}
/**
* If the waitlist contains an item, remove it and execute it.
* Otherwise, add the value to the queue.
*/
@night-fury-rider
night-fury-rider / design-pattern-observable.js
Created May 16, 2025 00:49
Design Pattern - Observable
class Stock {
constructor(symbol) {
this.symbol = symbol;
this.price = 0;
this.observers = [];
}
// Subscribe to stock price changes
subscribe(observer) {
this.observers.push(observer);
@night-fury-rider
night-fury-rider / styles.css
Last active May 13, 2025 03:14
CSS - Common Styles
body {
background-color: skyblue;
margin: 20px;
height: 90%;
}
.flex_center {
display: flex;
align-items: center;
justify-content: center;
@night-fury-rider
night-fury-rider / vscode-mac-snippets-html.json
Last active May 13, 2025 02:53
Visual Studio Code - Mac - HTML Boilerplate Snippets
// Make these changes in the ~/Library/Application Support/Code/User/snippets/html.json
// Place your snippets for html here. Each snippet is defined under a snippet name and has a prefix, body and
// description. The prefix is what is used to trigger the snippet and the body will be expanded and inserted. Possible variables are:
// $1, $2 for tab stops, $0 for the final cursor position, and ${1:label}, ${2:another} for placeholders. Placeholders with the
// same ids are connected.
// Example:
// "Print to console": {
// "prefix": "log",
// "body": [
// "console.log('$1');",
@night-fury-rider
night-fury-rider / design-pattern-pubsub.js
Last active May 13, 2025 02:31
Design Pattern - Pub/Sub
class PubSub {
constructor() {
this.events = {};
}
subscribe(eventName, callback) {
if (!this.events[eventName]) {
this.events[eventName] = [];
}
this.events[eventName].push(callback);
@night-fury-rider
night-fury-rider / vscode-keybindings.json
Last active October 27, 2025 12:38
Visual Studio Code - Keyboard Shortcuts Customization_
// Place your key bindings in this file to override the defaults
[
{
"key": "shift+cmd+f",
"command": "editor.action.formatSelection",
"when": "editorHasDocumentSelectionFormattingProvider && editorTextFocus && !editorReadonly"
},
{
"key": "cmd+k cmd+f",
"command": "-editor.action.formatSelection",