Skip to content

Instantly share code, notes, and snippets.

@nikhilweee
nikhilweee / querygen.html
Last active August 14, 2024 06:03
Search Query Generator
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>Google Search Query Generator</title>
<style>
body {
font-family: Arial, sans-serif;
margin: 0;
@nikhilweee
nikhilweee / nested_search.js
Last active August 3, 2024 05:21
Search for nested values in a JS object
function search(obj, string) {
const maxDepth = 10;
const excludeKeys = ["_root"];
function isObject(val) {
return typeof val === "function" || typeof val === "object";
}
function traverse(obj, depth, path) {
// Guard clause
@nikhilweee
nikhilweee / workday_add_time.py
Created February 25, 2024 06:51
Add time on workday using Selenium
import os
import time
import getpass
import argparse
import logging
from selenium import webdriver
from selenium.webdriver.common.by import By
from selenium.webdriver.common.keys import Keys
from selenium.webdriver.support.wait import WebDriverWait
@nikhilweee
nikhilweee / spotify_dedup.py
Created February 25, 2024 06:38
Remove duplicates from Spotify
import os
import json
import spotipy
from tqdm import tqdm
from spotipy.oauth2 import SpotifyOAuth
def get_client():
"""Get Spotify Client."""
@nikhilweee
nikhilweee / instagram_shortcuts.js
Created February 24, 2024 20:57
Instagram Web Keyboard Shortcuts
document.addEventListener('keydown', function(event) {
// Map the "." key with previous image in post.
if (event.keyCode === 188) {
let backButton = document.querySelector('button[aria-label="Go back"]');
if (backButton) {
backButton.click();
}
}
// Map the "," key with next image in post.
@nikhilweee
nikhilweee / zotero.js
Last active February 19, 2024 06:04
Zotero re-download missing PDFs
async function replacePDF(item) {
// filter annotations, attachments, notes
if (!item.isRegularItem()) {
return;
}
let fileExists = [];
let oldPDF = null;
// filter multiple or existing PDFs
const attachmentIDs = item.getAttachments();
for (let itemID of attachmentIDs) {
@nikhilweee
nikhilweee / unlock_readonly.py
Last active March 5, 2024 03:08
Unlock readonly form fields in a PDF
# pip install pypdf
from pypdf import PdfReader, PdfWriter
from pypdf.generic import NameObject, NumberObject
from pypdf.constants import FieldDictionaryAttributes as FA
MIN_HEIGHT = 30
reader = PdfReader("locked.pdf")
@nikhilweee
nikhilweee / workday_log_time.py
Last active August 27, 2022 14:48
Log time on Workday
import os
import time
import getpass
import argparse
import logging
from selenium import webdriver
from selenium.webdriver.common.by import By
from selenium.webdriver.common.keys import Keys
from selenium.webdriver.support.wait import WebDriverWait
@nikhilweee
nikhilweee / dummy_gpu.py
Created April 24, 2022 20:28
Run dummy GPU job whenever usage drops below 5%
import torch
import subprocess
import time
import logging
# Takes about 8GB
ndim = 25_000
logging.basicConfig(format='[%(asctime)s] %(filename)s [%(levelname).1s] %(message)s', level=logging.DEBUG)
def get_gpu_usage():
@nikhilweee
nikhilweee / statement-to-excel.py
Last active June 11, 2024 10:23
Convert HDFC Bank Credit Card statements from PDF to Excel
# This script is designed to convert bank statements from pdf to excel.
#
# It has been tweaked on HDFC Bank Credit Card statements,
# but in theory you can use it on any PDF document.
#
# The script depends on camelot-py,
# which can be installed using pip
#
# pip install "camelot-py[cv]"