Skip to content

Instantly share code, notes, and snippets.

@mohammedrahman-e2x
mohammedrahman-e2x / detect-url-change.js
Created August 15, 2023 13:02
Detect when URL changes in an SPA from externally injected script
// Set up a mutation observer to watch for url change to detect navigation
var previousUrl = location.href;
var observer = new MutationObserver(function(mutations) {
// If URL changes...
if (location.href !== previousUrl) {
previousUrl = location.href;
// Close popup
removeBanner();
@ueaner
ueaner / [slug].js
Created April 14, 2022 19:49 — forked from agungjk/[slug].js
Crawler example on Vercel using Puppeteer and NextJS API routes
const puppeteer = require('puppeteer-core');
const cheerio = require('cheerio');
const chrome = require('chrome-aws-lambda');
export default async (req, res) => {
const slug = req?.query?.slug;
if (!slug) {
res.statusCode = 200
res.setHeader('Content-Type', 'application/json')
res.end(JSON.stringify({ id: null }))
@eyecatchup
eyecatchup / calc-sapisidhash.js
Last active November 5, 2026 04:30
Calculate SAPISIDHASH
// Generates the SAPISIDHASH token Google uses in the Authorization header of some API requests
async function getSApiSidHash(SAPISID, origin) {
function sha1(str) {
return window.crypto.subtle.digest("SHA-1", new TextEncoder("utf-8").encode(str)).then(buf => {
return Array.prototype.map.call(new Uint8Array(buf), x=>(('00'+x.toString(16)).slice(-2))).join('');
});
}
const TIMESTAMP_MS = Date.now();
const digest = await sha1(`${TIMESTAMP_MS} ${SAPISID} ${origin}`);
@mandiwise
mandiwise / Count lines in Git repo
Last active December 27, 2025 13:49
A command to calculate lines of code in all tracked files in a Git repo
// Reference: http://stackoverflow.com/questions/4822471/count-number-of-lines-in-a-git-repository
$ git ls-files | xargs wc -l
@erikreagan
erikreagan / mac-apps.md
Created August 4, 2012 19:18
Mac developer must-haves

Mac web developer apps

This gist's comment stream is a collection of webdev apps for OS X. Feel free to add links to apps you like, just make sure you add some context to what it does — either from the creator's website or your own thoughts.

— Erik