Skip to content

Instantly share code, notes, and snippets.

@mvark
mvark / transform.js
Created April 16, 2024 03:06
If you have products on a web page in a grid layout and you want it as a list, here's code that ChatGPT generated that you can use in the Developer Tools console for the required transformed output. Change the class or HTML attribute names as relevant to your case.
// Find all div elements with class "gallery-item"
const products = document.querySelectorAll('div.gallery-item');
// Array to store product list items
const productListItems = [];
// Iterate over each product
products.forEach(product => {
// Extract the hyperlink
const hyperlink = product.querySelector('a.block-wrapper-link').getAttribute('href');
@mvark
mvark / expenses.csv
Last active April 16, 2024 03:02
Pritesh Kakani tweeted that expenses for a family of 4 in a Metro city in India is ~20 lakh per year & gave a break-down of the expenses - https://twitter.com/pritesh_kakani/status/1779388591132566013 . You may disagree with the expenses he has posted and if you want to customize the numbers to estimate your expenses, use this CSV file
Thing Monthly Cost Yearly Cost
Rent/EMI for home 35000 420000
Child School+Extracurriculars 400000
Car EMI+Maintainance+Insurance 200000
1 Asia/India Trip 150000
Food 10000 120000
Apparels/ Footwear/ Accessories 10000 120000
Healthcare 8000 96000
Car + Bike Petrol 5350 64200
Electronics(Laptop, Mobile, AC, TV, Washing Machine) 50000
@mvark
mvark / ReverseClockBookmarklet.js
Created February 21, 2024 12:03
Reverse Clock Bookmarklet - This handy tool counts down the time you set, helping you stay focused and improve your estimation skills for tasks like reading articles, watching videos, or completing online assignments.
javascript:(function() {
var t, ts, h, m, s, u, c, tmr, f = document.createElement("div");
f.id = "revClock";
f.style.cssText = "position: fixed; top: 10px; right: 10px; background-color: rgba(0, 0, 0, 0.5); padding: 10px; z-index: 9999; text-align: center; font-size: 20px; color: white;";
document.body.appendChild(f);
t = prompt("Enter number of minutes:");
if (t === null || isNaN(t) || t < 0) {
alert("Invalid input. Please enter a positive number for minutes.");
return;
@mvark
mvark / Tags
Created February 15, 2024 03:44
This PowerShell script is based on a script by MotoX80. It fetches all the tags listed on Microsoft Q&A along with their hyperlinks to construct this web page - https://codepen.io/mvark/full/zYbyLgd
1..15 | foreach {
$page = Invoke-WebRequest "https://learn.microsoft.com/en-us/answers/tags/?orderBy=Popular&page=$($_)"
$page.AllElements | Where-Object -Property Class -eq 'card-title' | ForEach-Object {
"<li><a href=`"https://learn.microsoft.com$($_.href)`" target=`"_blank`">$($_.innerText)</a></li>"
}
}
<!DOCTYPE html>
<html lang="en">
<head>
<!-- Based on this HTML5 QR Code Reader sample by Minhaz https://blog.minhazav.dev/research/html5-qrcode.html -->
<meta name="viewport" content="width=device-width, initial-scale=1, minimum-scale=1, maximum-scale=5">
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<title>NutriScan</title>
<style>
#desc {
<!DOCTYPE html>
<html lang="en">
<head>
<!-- Based on this HTML5 QR Code Reader sample by Minhaz https://blog.minhazav.dev/research/html5-qrcode.html -->
<meta name="viewport" content="width=device-width, initial-scale=1, minimum-scale=1, maximum-scale=5">
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<title>OFF Barcode Scanner</title>
</head>
<body>
<!DOCTYPE html>
<html lang="en">
<head>
<!-- Based on this HTML5 QR Code Reader sample by Minhaz https://blog.minhazav.dev/research/html5-qrcode.html -->
<meta name="viewport" content="width=device-width, initial-scale=1, minimum-scale=1, maximum-scale=5">
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<title>OFF Bar Code Scanner</title>
</head>
<body>
@mvark
mvark / location.html
Created January 9, 2024 07:35
Simple JavaScript code sample to detect location through an API call to IPAPI web service
<!DOCTYPE html>
<html>
<head>
<title>Location Detection</title>
</head>
<body>
<div id="userDetails"></div>
<script>
@mvark
mvark / SnippetsCompact.js
Last active January 2, 2024 17:08
This is compact code version of Snippets Bookmarklet that saves snippets you need with custom names & retrieves them with a single click
javascript:(function(){function g(t){return prompt(t)}d=localStorage;a=g('Enter "get" or "set": ');if(a=="get"){k=d.length?[...Array(d.length)].map(i=>d.key(i)).filter(k=>k.startsWith('z_')):[];k=g("Keys: "+k+"\nEnter key:");if(d.getItem(k))document.getElementById("prompt-textarea").value=d.getItem(k);else alert("Key does not exist!")}else if(a=="set"){k="z_"+g("Enter new key: ");v=g("Enter value to store:");d.setItem(k,v)}else alert("Invalid action")})()
@mvark
mvark / snippets.js
Created January 2, 2024 16:35
Snippets Bookmarklet saves snippets you need with custom names & retrieves them with a single click
javascript:(function(){
//The getInput function is defined to prompt the user for input.
function getInput(text){return prompt(text)}
//the localStorage will be used to store & retrieve keys and values.
d = localStorage;
//The user is prompted to enter either "get" or "set" to choose the action.
a = getInput('Enter "get" or "set": ');