Skip to content

Instantly share code, notes, and snippets.

View rvighne's full-sized avatar

Rohit Vighne rvighne

View GitHub Profile
@rvighne
rvighne / justwatch2letterboxd.js
Last active November 27, 2023 22:35
Bookmarklet to scrape a list of titles on Justwatch into a CSV that can be imported into Letterboxd.
(function() {
// https://www.justwatch.com/us/lists/my-lists?content_type=movie&inner_tab=seenlist&list_layout=card
// https://www.justwatch.com/us/lists/my-lists?content_type=movie&inner_tab=watchlist&list_layout=card
// https://www.justwatch.com/us/lists/my-lists?content_type=movie&inner_tab=likelist&list_layout=card
// https://letterboxd.com/about/importing-data/
const total = parseInt(document.querySelector('.titles-count').textContent, 10)
const titles = document.getElementsByClassName('title-card-heading')
console.assert(titles.length === total, 'please scroll down until all titles are loaded')
return Array.prototype.reduce.call(
titles,
@rvighne
rvighne / FugitiveFiles.vim
Created May 24, 2022 05:11
fzf.vim is great, but its :GFiles always assumes that .git is in a particular place. It can be made more robust to this and other edge cases by integrating with Fugitive, which already abstracts the details of interacting with Git.
" Alternative to GFiles: integrate with Fugitive to work better in edge cases
" Completion should actually be pathspec, not file, but close enough
command -bang -nargs=* -complete=file FugitiveFiles
\ call fzf#run(fzf#wrap('gfiles', fzf#vim#with_preview({
\ 'source': FugitiveShellCommand('ls-files', '-z', '--', <f-args>),
\ 'options': '--read0 --multi --no-clear --prompt=' . shellescape('FugitiveFiles> ')
\ }), <bang>0))
@rvighne
rvighne / resflix.sh
Last active November 16, 2021 20:06
Download the list of titles currently available on UCLA's Resflix streaming service.
#!/bin/sh
# Must be on UCLA's campus network (e.g. using VPN)
curl https://movies.reslife.ucla.edu/jsonapi/GetAllContent | jq -r '.[].Title' | sort
@rvighne
rvighne / extensions.txt
Created February 26, 2021 09:19
iptables source code reading assignments
Gautam libarpt_mangle.c
Gautam libebt_dnat.c
Gautam libebt_mark_m.c
Gautam libebt_stp.c
Gautam libip6t_dst.c
Gautam libip6t_icmp6.c
Gautam libip6t_NETMAP.c
Gautam libip6t_SNPT.c
Gautam libipt_ECN.c
Gautam libipt_realm.c
@rvighne
rvighne / index.js
Created January 11, 2021 00:20
Demo of man-in-the-middle attack against a proxy script loaded insecurely
const http = require('http')
// The malicious proxy configuration script
// Replaces the real script
// Directs all requests to malicious proxy server
function FindProxyForURL(url, host) {
return "PROXY ::1:8080";
}
// The man in the middle
@rvighne
rvighne / shortcuts.sh
Created July 28, 2017 02:17
Bash shortcuts that I always find useful. Source it from your .bashrc so it is always available (on Ubuntu, you can simply name it ~/.bash_aliases)
# When the given command terminated, run it again unless interrupted
retry() {
while :; do
"$@"
tput bold; tput setaf 1
echo "Retrying $1 (Ctrl-C to cancel)"
tput sgr0
sleep .5
@rvighne
rvighne / opencv-install.sh
Created January 31, 2017 05:50
Instructions to download, build, and install OpenCV. For C/C++ development. Compiles with V4L libraries (suitable for most cameras).
# Make sure everything is up to date (optional)
sudo apt-get update
sudo apt-get dist-upgrade -y
# Prerequisites
sudo apt-get install build-essential git cmake make pkg-config v4l-utils libv4l-0 libv4l-dev -y
# Download OpenCV
git clone https://github.com/opencv/opencv.git
@rvighne
rvighne / Loader.js
Created November 11, 2016 20:39
Very simple interface for loading resources (esp. images, audio for e.g. game sprites) asynchronously, attaching callbacks to individual resources, and waiting for all queued resources to be loaded.
"use strict";
/* Simple async resource loader */
class Loader {
constructor() {
this.promises = [];
}
get(src, type = Image) {
@rvighne
rvighne / randInt.js
Created September 11, 2016 00:38
Get a random integer in the widest possible range of positive integers.
function randInt() {
return Math.trunc(Math.random() * Number.MAX_SAFE_INTEGER);
}
@rvighne
rvighne / watchKeys.js
Created September 10, 2016 19:54
Returns an object whose keys are keyboard key names and whose values are booleans indicating whether the key is pressed or not.
function watchKeys(target = document) {
const watcher = {};
target.addEventListener('keydown', function (e) {
watcher[e.key] = true;
});
target.addEventListener('keyup', function (e) {
watcher[e.key] = false;
});