Skip to content

Instantly share code, notes, and snippets.

@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 March 29, 2024 10:50
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]"
@nikhilweee
nikhilweee / module-batch.py
Last active July 2, 2019 11:47
Getting started with LSTMs in PyTorch
import random
import torch
num_examples = 128
message_length = 32
def dataset(num_examples):
"""Returns a list of 'num_examples' pairs of the form (encrypted, original).
@nikhilweee
nikhilweee / wtc.sh
Last active November 16, 2016 01:10
random-commit-messages
#! /bin/bash
# You can run this script directly from the terminal
# curl -s https://gist.githubusercontent.com/nikhilweee/75ea15afabdfbb18cda625364a9bf9f9/raw/ > /tmp/wtc.sh ; source /tmp/wtc.sh
# Just use `gitcommit` instead of `git commit -m` to get random commit messages from whatthecommit.com
# start
# checking for conflicts
unalias gitcommit
unalias commitmessage