Skip to content

Instantly share code, notes, and snippets.

View oniani's full-sized avatar
:electron:
4845495741

David Oniani oniani

:electron:
4845495741
View GitHub Profile
@oniani
oniani / plot.py
Created July 11, 2025 23:00
My Matplotlib Plotting Style
#!/usr/bin/env python
import matplotlib.pyplot as plt
import numpy as np
# Set matplotlib style
plt.style.use("tableau-colorblind10")
plt.rcParams.update(
{
"axes.grid": True,
"axes.titleweight": "bold",
@oniani
oniani / cpu_vs_mps.py
Last active January 8, 2025 05:05
CPU vs MPS
#!/usr/bin/env python
import time
import torch
class PerfTimer:
"""A timer for measuring performance using a high-resolution monotonic clock."""
def __init__(self, desc: str = "") -> None:
@oniani
oniani / paper.csv
Last active August 3, 2023 18:19
Papers
venue title url
ACL 2022 Problems with Cosine as a Measure of Embedding Similarity for High Frequency Words https://aclanthology.org/2022.acl-short.45/
ACL 2022 Translation between Molecules and Natural Language https://aclanthology.org/2022.emnlp-main.26/
ICLR 2015 Adam: A Method for Stochastic Optimization https://arxiv.org/abs/1412.6980
ICLR 2019 Decoupled Weight Decay Regularization https://arxiv.org/abs/1711.05101
Nature 2022 Language models can learn complex molecular distributions https://www.nature.com/articles/s41467-022-30839-x
Nature 2023 Foundation models for generalist medical artificial intelligence https://www.nature.com/articles/s41586-023-05881-4
@oniani
oniani / nixos
Created July 1, 2023 21:48
nixos bootstrap via QEMU
#!/usr/bin/env sh
wget -O nixos.iso -nc https://channels.nixos.org/nixos-23.05/latest-nixos-gnome-x86_64-linux.iso
qemu-img create -f qcow2 nixos.img 32G
qemu-system-x86_64 -enable-kvm -m 8G -boot d -cdrom nixos.iso -hda nixos.img
qemu-system-x86_64 -enable-kvm -m 8G -boot a -hda nixos.img
@oniani
oniani / laptop.md
Created January 17, 2023 18:09
Closing Laptop Lid and Power Key

For not logging out on lid closing, open /etc/systemd/logind.conf and add or modify:

HandleLidSwitch=ignore

To disable Fn + Esc functionality add or modify the following to the same file:

HandlePowerKey=ignore
@oniani
oniani / n_way_k_shot.py
Created November 11, 2022 16:08
N-way-K-shot train/test split for Few-Shot Learning (FSL)
import pandas as pd
def n_way_k_shot(path: str, num_samples: int, label_col: str, random_state: int = 0) -> tuple:
"""N-way-K-shot train/test split for Few-Shot Learning (FSL)."""
df = pd.read_csv(path)
fn = lambda lg: lg.sample(num_samples, random_state=random_state)
df_train = df.groupby(label_col, group_keys=False).apply(fn)
@oniani
oniani / arxiv.go
Created September 5, 2022 19:33
arXiv paper scraper
// USAGE: `go run arxiv.go "Depth-wise Separable Convolution"`
package main
import (
"fmt"
"os"
"strings"
"github.com/gocolly/colly"
@oniani
oniani / macros.c
Created December 28, 2021 21:11
Useful C Macros
#include <stdio.h>
#include <stdlib.h>
#define ABS(x) (x < 0) ? -x : x
#define EVEN(x) x % 2 == 0
#define ODD(x) x % 2 == 1
#define MAX(x, y) x < y ? y : x
#define MIN(x, y) x < y ? x : y
@oniani
oniani / exposure.md
Created October 14, 2021 16:40
HD Pro Webcam C920 - Exposure Settings

HD Pro Webcam C920 - Exposure Settings

$ sudo apt install v4l2ucp
$ v4l2ucp

Set Exposure, Auto to Manual Mode and set Exposure (Absolute) to 500.

@oniani
oniani / clang-format
Created April 12, 2021 09:07
Configuration for clang-format
---
# Indentation
ContinuationIndentWidth: 4
IndentCaseLabels: true
IndentWidth: 4
NamespaceIndentation: None
TabWidth: 4
UseTab: Never
# Comments and sorting