Skip to content

Instantly share code, notes, and snippets.

View karnawhat's full-sized avatar

Ayush Karnawat karnawhat

View GitHub Profile
@karnawhat
karnawhat / Description
Last active November 24, 2025 15:08
Sample ML Problem
You are developing a recommendation system for a financial platform that predicts
whether a user will click on a merchant offer. The dataset contains interactions
between users and merchant offers, including features such as user ID, merchant
offer ID, timestamp of interaction, and a binary label indicating whether the user
clicked on the offer (1 for click, 0 for no click).
Additionally, it contains the past history of the user's click through rate (measured
by number of clicks over total impressions over the time period specified). Each
view/click is measured once per session, meaning if a user clicked on an offer multiple
times, it would only be counted once.
@karnawhat
karnawhat / compress.md
Last active March 5, 2024 13:49
Compress pdfs with ghostscript + nix

Compressing PDFs using Ghostscript

Storing/sharing large PDFs can be cumbersome. What if we could trade off some quality to save some space? This is exactly the idea behind (lossy) compression.

Installing Ghostscript

You can install ghostscript (gs) via the official site, via homebrew brew install ghostscript (on MacOS), or nix-shell using the shell.nix

@karnawhat
karnawhat / symbolize.py
Last active July 5, 2020 19:12
Given a string, find all possible combinations in which you can represent it using the periodic table of element symbols
import typing as tp
SYMBOLS = [
"H", "He", "Li", "Be", "B", "C", "N", "O", "F", "Ne", "Na", "Mg", "Al", "Si",
"P", "S", "Cl", "Ar", "K", "Ca", "Sc", "Ti", "V", "Cr", "Mn", "Fe", "Co",
"Ni", "Cu", "Zn", "Ga", "Ge", "As", "Se", "Br", "Kr", "Rb", "Sr", "Y", "Zr",
"Nb", "Mo", "Tc", "Ru", "Rh", "Pd", "Ag", "Cd", "In", "Sn", "Sb", "Te", "I",
"Xe", "Cs", "Ba", "La", "Ce", "Pr", "Nd", "Pm", "Sm", "Eu", "Gd", "Tb",
"Dy", "Ho", "Er", "Tm", "Yb", "Lu", "Hf", "Ta", "W", "Re", "Os", "Ir", "Pt",
@karnawhat
karnawhat / basictex.md
Created October 22, 2019 17:18
Tutorial on installing BasicTeX

Installing BasicTeX

This is a barebones setup to using TeX with matplotlib. Since the whole MacTeX package is ~4GB, and includes a lot of unnecessary binaries, it is better to install BasicTeX and install the packages as you seem fit.

The easiest way to install is by running brew cask install basictex and run which pdflatex to check whether it is installed. This should return a path with the location of the filepath. If it doesn't, then check if the /Library/TeX folder exists.

Finally, add the following to your ~/.bashrc or ~/.bash_profile filepath: export PATH="/Library/TeX/texbin/:$PATH"

Adding packages

@karnawhat
karnawhat / matplotlib_fonts.md
Last active November 26, 2019 21:54
Installing custom matplotlib fonts (on OSX) for different environments

Custom Matplotlib Fonts

This is a small tutorial on how to install custom matplotlib fonts (on OSX) in each environment seperately.

Downloading fonts

First, we need to install our custom fonts. Note: Matplotlib expects a font in True Type format (.ttf). For example, if we want to add the Helvetica font, we need to check if we have the font in .ttf format installed on our system otherwise we need to download it and install it.

One easy way to install fonts (with .ttf extension) is to use 1001fonts. Search for the font you want, and download away.