Skip to content

Instantly share code, notes, and snippets.

@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
@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 / 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 / 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 / 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 / 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 / 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 / registration_info.py
Last active February 25, 2024 14:12
Get vehicle info from an Indian registration number
import sys
import requests
from bs4 import BeautifulSoup, SoupStrainer
home_url = 'https://parivahan.gov.in/rcdlstatus/'
post_url = 'https://parivahan.gov.in/rcdlstatus/vahan/rcDlHome.xhtml'
# Everything before the last four digits: MH02CL
first = sys.argv[1]
# The last four digits: 0555
second = sys.argv[2]
@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")