Skip to content

Instantly share code, notes, and snippets.

View sahilatahar's full-sized avatar
:octocat:
I am Free

Sahil Atahar sahilatahar

:octocat:
I am Free
View GitHub Profile
@sahilatahar
sahilatahar / scrollToEndOfContainer.js
Last active June 15, 2024 09:13
Implementing Scrolling/Infinite Scrolling to Dynamically Load Data on Webpages or Containers
// Scroll to end of container
// If you have id of container then replace #id with your container id (e.g. #imagesContainer)
// If you have class of container then replace #id with your container class (e.g. .imagesContainer)
const container = document.querySelector("#id")
const scrollToEnd = () => {
container.scrollIntoView({
// behavior: "smooth",
block: "end",
@sahilatahar
sahilatahar / RenameJSFilesToTS.md
Last active June 15, 2024 09:11
This guide provided commands and steps to rename JavaScript and JSX files to TypeScript and TypeScript React files using PowerShell, Bash, and VS Code terminal. By following these instructions, you can efficiently migrate your project from JavaScript to TypeScript, ensuring proper file extensions and compatibility with TypeScript and TypeScript …

How to Rename JavaScript and JSX Files to TypeScript and TypeScript React Files in VS Code

When migrating a JavaScript project to TypeScript, you may need to rename your JavaScript and JSX files to TypeScript and TypeScript React files. This guide provides commands to rename .js files to .ts and .jsx files to .tsx using PowerShell in Windows, Bash in Linux/MacOS/Git Bash, and VS Code terminal.

Using Commands in VS Code Terminal:

  1. Open VS Code: Launch Visual Studio Code.

  2. Open Terminal in VS Code:

@sahilatahar
sahilatahar / extractImageURLsFromWebpage.js
Created June 15, 2024 09:52
This JavaScript script extracts URLs of images from the current webpage and copies them to the clipboard when run in the browser console (F12). It filters URLs by common image file extensions and handles potential lazy loading scenarios, ensuring extracted URLs are unique before copying.
// This script fetches all image URLs from the current webpage and copies them to the clipboard.
// To use, open the webpage, open the browser console (F12), paste this script, and run it.
// Ensure you allow clipboard access when prompted by the browser.
// The script can be customized to filter URLs based on common image extensions or other criteria.
// It can also be adjusted to extract URLs from <img> tags with lazy loading.
// Function to filter URLs based on common image extensions
const filterURLs = (urls) => {
const keywords = [".jpg", ".jpeg", ".png", ".gif", ".webp"]
let filteredURLs = urls.filter((url) =>
@sahilatahar
sahilatahar / downloadImagesFromURLs.js
Created June 15, 2024 10:20
This script processes a single file containing image URLs, removes duplicates, and downloads the images to a specified output folder. Simply replace inputFilePath and outputFolderPath with your desired file path and folder path. Ensure you have the axios package installed (npm install axios) to handle HTTP requests for image downloads.
// This script processes a single file containing image URLs and downloads the images to a specified folder.
// To use, replace the inputFilePath and outputFolderPath with your desired paths.
// Make sure to install the axios package using npm install axios.
// The script reads the file, extracts image URLs, removes duplicates, and downloads the images.
const fs = require("fs")
const path = require("path")
const axios = require("axios")
// Function to extract image URLs from a file
@sahilatahar
sahilatahar / console_api_examples.js
Created June 15, 2024 10:49
This JavaScript code demonstrates essential console APIs (log, warn, error, info, table) for debugging JavaScript applications in the browser. It includes examples for logging messages, handling warnings and errors, formatting data, and measuring execution time. Each method illustrates practical use cases to enhance debugging efficiency and appl…
// Console APIs provide developers with powerful tools to debug JavaScript code, output information, and interact with the browser environment. Here are some practical use cases of console APIs along with examples:
// 1. Logging Messages (console.log())
// Description: Output debug information, variables, or state of an application.
// Special Use Cases: Logging variables, objects, or messages for debugging purposes.
// Example:
let name = 'John';
let age = 30;
console.log(`User ${name} is ${age} years old.`);
@sahilatahar
sahilatahar / consoleASCIIStylingExamples.js
Last active June 15, 2024 11:40
This script demonstrates the use of ANSI escape codes to style text output in the console. It includes examples of various text styles such as foreground and background colors, as well as text formatting options like bold, italic, underline, strikethrough, and more.
// ANSI escape codes for styling
const styles = {
reset: "\x1b[0m",
bright: "\x1b[1m",
dim: "\x1b[2m",
underscore: "\x1b[4m",
blink: "\x1b[5m",
reverse: "\x1b[7m",
hidden: "\x1b[8m",
fgBlack: "\x1b[30m",
@sahilatahar
sahilatahar / ConsoleStyling.md
Created June 15, 2024 11:59
This gist demonstrates how to style text in the browser console using JavaScript and CSS. It includes 100 examples like gradient text, neon effects, and more.

To style text in the browser console using JavaScript, you can use CSS styling within the console.log function. Here's a step-by-step guide on how to do it:

Follow these steps:

  1. Open Browser Console:

    • Open your web browser (Chrome, Firefox, etc.).
    • Right-click anywhere on the webpage and select "Inspect" or press Ctrl + Shift + I (Cmd + Option + I on macOS) to open the Developer Tools.
    • Navigate to the "Console" tab.