Skip to content

Instantly share code, notes, and snippets.

View ritobanrc's full-sized avatar

Ritoban Roy-Chowdhury ritobanrc

View GitHub Profile
"basics": {
"name": "Ritoban Roy-Chowdhury",
"email": "ritobanrc@gmail.com",
"additionalInfo": "rroychowdhury@ucsd.edu"
},
"education": [
{
"startDate": "2022-09",
"endDate": "2026-06",
@ritobanrc
ritobanrc / eigenvectors.py
Last active November 22, 2022 20:44
Algorithm for finding eigenvectors from Hubbard & Hubbard's Linear Algebra book
eps = 1e-6
max_newton_iters = 1000
def vec(arr):
return [[a] for a in arr]
def matmul(A, B):
assert len(A[0]) == len(B)
r = [[0 for _ in range(len(B[0]))] for _ in range(len(A))]
@ritobanrc
ritobanrc / particles.rs
Created March 8, 2022 18:22
A struct that supports dynamically storings several arrays for particle simulation data. I ended up not using this because of difficulties with the Rust borrow checker (in particular, not being able to easily access multiple arrays simultaneously if one of them was mutable).
use crate::math::*;
/// The `Particles` struct, used to store particle data.
pub struct Particles<Idx> {
pub(crate) float_data: Vec<Vec<T>>,
pub(crate) vector_data: Vec<Vec<TV>>,
pub(crate) matrix_data: Vec<Vec<Mat>>,
idx: std::marker::PhantomData<Idx>,
}
@ritobanrc
ritobanrc / minimal_gtk_cairo_example.py
Last active July 17, 2024 17:22
A minimal example for using Cairo in a GTK `DrawingArea` in Python
"""
A minimal example for using Cairo with GTK
"""
import cairo
import gi
gi.require_version('Gtk', '3.0')
from gi.repository import Gtk, Gdk, GLib
@ritobanrc
ritobanrc / init.vim
Created December 23, 2020 18:49
My neovim vimrc file
scriptencoding utf8
" Arch defaults
runtime! archlinux.vim
call plug#begin('~/.local/share/nvim/plugged')
Plug 'junegunn/fzf.vim'
Plug 'junegunn/goyo.vim'
Plug 'neoclide/coc.nvim', {'branch': 'release'}
@ritobanrc
ritobanrc / aoc_lib.rs
Created November 17, 2020 17:30
A short script to easily handle the functions for advent of code.
/// The `main` function for each day is in `dayXX.rs`, called `dayXX_main()`. To
/// run all the solutions, simply run `cargo test`. Inputs should be placed in a folder
/// input/dayXX.txt. This also requires the `paste = "0.1.0"` and `anyhow = "1.0.0"` crates
/// for creating the function names and handing errors, respectively.
use std::io;
pub fn load_input(day: usize) -> io::Result<String> {
use std::fs::read_to_string;
@ritobanrc
ritobanrc / sin_cos_approx.py
Created October 22, 2020 01:10
A surprisingly good recursive approximation of sin and cos using double angle theorem.
from math import sqrt, pi, sin, cos
def my_sin(x):
if x < 0.01:
return x
return 2 * my_sin(x/2) * my_cos(x/2)
def my_cos(x):
if x < 0.01:
s = my_sin(x)
@ritobanrc
ritobanrc / twelve_days_christmas.py
Created October 12, 2020 19:12
A short script to print the lyrics to the 12 Days of Christmas
lyrics = ["Twelve drummers drumming", "eleven pipers piping",
"Ten lords a leaping", "nine ladies dancing", "eight maids a milking",
"Seven swans a swimming", "six geese a laying", "five gold rings",
"Four calling birds", "three French hens",
"Two turtle doves", "a partridge in a pear tree"]
lyrics.reverse()
ordinals = ["first", "second", "third", "fourth", "fifth", "sixth", "seventh", "eigth", "ninth", "tenth", "eleventh", "twelveth"]
@ritobanrc
ritobanrc / setbg.sh
Created September 14, 2020 23:20
My old wallpaper setting script
#!/bin/bash
[ -f "$2" ] && cp "$2" ~/.config/wall.png && notify-send -i "$HOME/.config/wall.png" "Wallpaper changed."
[ -d "$2" ] && cp "$(find "$2" -name "*.jpg" -o -name "*.jpeg" -o -name "*.png" -type f | shuf -n 1)" ~/.config/wall.png && notify-send -i "$HOME/.config/wall.png" "Random Wallpaper chosen."
xwallpaper --zoom ~/.config/wall.png
@ritobanrc
ritobanrc / reddit_wallpaper.py
Created September 13, 2020 19:55
A script to help me easily download and organize wallpapers from reddit.
#/usr/bin/python3
from PIL import Image, ImageTk
from io import BytesIO
import praw
import json
import re
import requests
import tkinter as tk
import tkinter.ttk as ttk