Skip to content

Instantly share code, notes, and snippets.

View yashsavani's full-sized avatar

Yash Savani yashsavani

View GitHub Profile
@yashsavani
yashsavani / life_snippets.py
Last active September 14, 2022 20:51
Useful code snippets for everyday life
# Code to test myself on powers of 2 from 2^1 to 2^11
# 2^[0-3,10] (easy), 2^4 = 4^2 = 16, 2^5 = 32 (3+2=5), 2^6 = 64 ("6"4), 2^7 = 128 (8-1=7), 2^8 = 256 (2+6=8), 2^9 = 2^(10-1) = 512
[("-"*20).join((lambda x: (f"{x:3d}",str(1<<x)))(random.randint(1,11))) for _ in range(100)]
# Code to test myself on hex and binary for nibbles
# 0-4,7,8 (easy), 5 = 0b101 (10>>1), 6 = 0b110 (4+2), 9 = 0b1001 (8+1), 10 = 0xa (characters look similar), 11 = 0xb (stem of b char),
# 12 = 0xc (the hook of the 2 is similar to c) = 0b1100 (8+4), 13 = 0xd (three somewhat = dee) = 0x1101 (01 similar to d),
# 14 = 0xe (four + e = free) = 0b1110 = (0xf-0x1), 15 = 0xf ("F"ive) = 0b1111
[(lambda x: f"{x:>3d}"+"-"*20+hex(x)+"-"*20+bin(x))(random.randint(1,15)) for _ in range(100)]
@yashsavani
yashsavani / resnet_cifar10.py
Last active July 17, 2022 22:45
Train ResNet on CIFAR10 in a single file using PyTorch
"""Train ResNet on CIFAR10 in a single file using PyTorch."""
import argparse
import json
import os
import pandas as pd
import time
import torch
import torch.optim as optim
@yashsavani
yashsavani / main.tex
Last active November 21, 2021 23:41
Latex Skeleton
\documentclass{article}
\usepackage{ysavani}
\title{}
\author{
Yash Savani \\
Computer Science Department \\
Carnegie Mellon University \\
Pittsburgh, PA 15213 \\
@yashsavani
yashsavani / patch_cascadia.py
Created June 22, 2021 08:19
Download the latest Cascadia Code font, patch it with Nerd Fonts, and finally combine the italics fonts with the regular ones so they are all part of the same family.
import fontforge
from pathlib import Path
import os
import re
import requests
response = requests.get(
"https://api.github.com/repos/microsoft/cascadia-code/releases",
{"Accept": "application/vnd.github.v3+json"}
)
@yashsavani
yashsavani / newwords.hs
Created February 1, 2020 23:25
Reimplemented words function from haskell Data.Char
import Data.Char (isSpace)
words' :: String -> [String]
words' [] = []
words' ls = tail (foldr step [] (' ':ls))
where
step x (y:ys)
| isSpace x = if null y then []:ys else []:y:ys
| otherwise = (x:y):ys
step x _
@yashsavani
yashsavani / haskellFunctions.hs
Last active August 12, 2022 15:07
List of Useful Haskell Functions and their Python counterparts
-- General purpose Haskell functions to remember (Note I have ommited the typeclasses here for simplicity)
-- Bryan O'Sullivan, Don Stewart, and John Goerzen. Real World Haskell, O'Reilly Media, 2008
-- Length of list
-- O(n)
-- ✅(empty list) -> total / safe
-- Python: len(list)
length :: [a] -> Int
-- Tells if a list is empty
@yashsavani
yashsavani / grahamScan.hs
Last active January 31, 2020 01:24
Attempting Graham Scan problem from real world haskell
import Data.List (sortBy)
import Data.Function (on)
type Vector = (Double, Double)
data Direction
= LeftDir
| RightDir
| ForwardDir
| NoDir