Skip to content

Instantly share code, notes, and snippets.

Avatar
📚
Not coding actively anymore. Doing math instead.

Eklavya Sharma sharmaeklavya2

📚
Not coding actively anymore. Doing math instead.
View GitHub Profile
@sharmaeklavya2
sharmaeklavya2 / linreg.py
Last active December 12, 2022 21:37
Linear regression on 1 variable with confidence intervals
View linreg.py
#!/usr/bin/env python3
"""
Takes a CSV file as input and performs linear regression on the data.
"""
import sys
import ast
import argparse
import numpy as np
@sharmaeklavya2
sharmaeklavya2 / float2frac.py
Last active November 24, 2022 23:23
float to nearest fraction
View float2frac.py
#!/usr/bin/env python3
"""
Convert a float to the nearest fraction.
"""
import math
import ast
import argparse
from fractions import Fraction as F
@sharmaeklavya2
sharmaeklavya2 / time-chart.py
Last active January 26, 2023 17:18
Track how a noisy quantity changes over time (e.g. my body weight)
View time-chart.py
#!/usr/bin/env python3
"""
Visualize how a quantity varies with time.
Reads a CSV file where first column is timestamp.
Plots the data points and a weighted average of a sliding window.
"""
import csv
import math
@sharmaeklavya2
sharmaeklavya2 / latex-dark.tex
Created May 18, 2022 00:51
latex dark mode
View latex-dark.tex
\usepackage{xcolor}
\usepackage{hyperref}
\definecolor{textColorDark}{HTML}{bdc1c6}
\definecolor{bgColorDark}{HTML}{202124}
\definecolor{blueDark}{HTML}{8ab4f8}
\definecolor{redDark}{HTML}{f9968b}
\pagecolor{bgColorDark}
\color{textColorDark}
@sharmaeklavya2
sharmaeklavya2 / download-latex-files.py
Last active October 5, 2022 03:09
Downloads style/class files necessary to compile a LaTeX paper.
View download-latex-files.py
#!/usr/bin/env python3
"""Downloads style/class files necessary to compile a LaTeX paper."""
import sys
import os
from os.path import join as pjoin
import argparse
from urllib.request import urlopen
from zipfile import ZipFile
@sharmaeklavya2
sharmaeklavya2 / total_last_column.py
Created September 25, 2021 04:14
Extract the longest numeric suffix from each line in stdin and output the sum.
View total_last_column.py
#!/usr/bin/env python
"""Extract the longest numeric suffix from each line in stdin and output the sum."""
from __future__ import print_function
import sys
import argparse
numstr = '.0123456789'
@sharmaeklavya2
sharmaeklavya2 / .gitignore
Created July 12, 2021 17:30
LaTeX gitignore
View .gitignore
*.aux
*.bbl
*.blg
*.log
*.out
*.toc
*.pdf
*.brf
*.lot
*.lof
@sharmaeklavya2
sharmaeklavya2 / slides.svg
Last active May 6, 2021 07:52
slides.svg
View slides.svg
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
View jinjait.py
#!/usr/bin/env python3
"Takes a Jinja2 template file and a JSON context file as input. Returns rendered output."
import json
import argparse
import jinja2
def render(template_path, context_path, output_path):
with open(template_path) as tfp:
@sharmaeklavya2
sharmaeklavya2 / bp1.context.json
Last active March 2, 2021 08:09
SVG BP1 animation
View bp1.context.json
{
"W": 640,
"H": 480,
"binW": 200,
"binH": 120,
"items": [
{"size": 0.5, "cumSize": 0.0, "packBin": 0, "packPos": 0.0},
{"size": 0.4, "cumSize": 0.5, "packBin": 1, "packPos": 0.0},
{"size": 0.3, "cumSize": 0.9, "packBin": 0, "packPos": 0.5},
{"size": 0.3, "cumSize": 1.2, "packBin": 1, "packPos": 0.4},