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 / multiKey.js
Last active July 6, 2021 21:53
Create an object that has multiple keys pointing to the same value. It uses getters and setters to work its magic, but acts perfectly like a regular object, including enumeration, membership testing, and deleting properties.
function multiKey(keyGroups) {
let obj = {};
let props = {};
for (let keyGroup of keyGroups) {
let masterKey = keyGroup[0];
let prop = {
configurable: true,
enumerable: false,
@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 / pixel8.js
Last active April 28, 2020 13:29
Pixel8 is as easy way to get the raw pixel data of an image, canvas, or video from the same domain. It uses the HTML5 Canvas's getImageData method, so Internet Explorer is only supported through FlashCanvas (http://flashcanvas.net). Simply call something like `var data = pixel8(image)` and then use `data.pixelAt(x, y)` to get a specific pixel's …
/*
Copyright (c) 2013 Rohit Vighne
License: The MIT License (MIT)
*/
function pixel8(image, x, y, w, h) {
"use strict";
// Image must be an image, canvas, or video
// For videos: Pixel data of the currently displayed frame will be extracted
@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) {