Skip to content

Instantly share code, notes, and snippets.

@bantmen
bantmen / bench.py
Created December 29, 2025 09:33
Make torch.compile rmsnorm faster
import torch
from triton.testing import do_bench
def bench(M, N=128, dtype=torch.bfloat16):
x = torch.randn(M, N, device="cuda", dtype=dtype)
w = torch.randn(N, device="cuda", dtype=dtype)
eps = 1e-6
with torch.inference_mode():
@bantmen
bantmen / dijsktra.scala
Last active December 20, 2021 14:12
Dijkstra's algorithm implemented in Scala - used to solve https://adventofcode.com 2021 - Day 15
import scala.collection.mutable
object Dijsktra {
type Grid = Array[Array[Int]]
def neighbours(
coord: (Int, Int),
rows: Int,
cols: Int

Firing up LaTex on macOS 🔥

As I'm writing this small tutorial, I assume you've read my previous one about setting up macOS, so if for any tool I'll use without explanation, look to that other article.

MacTex

The full version IS NOT MANDATORY, as in the tutorial that follows I installed the smaller version of MacTeX and proceded installing every needed dependency. Installing the complete package is about ~3.5GB of download and ~5GB on disk, the smaller one is just about 80MBs.

Click here to download the complete version or here to download the smaller version.

Gnuplot

@bantmen
bantmen / install_mosh_locally.sh
Created September 28, 2016 19:31 — forked from xiaom/install_mosh_locally.sh
install mosh locally
#!/bin/sh
# this script does absolutely ZERO error checking. however, it worked
# for me on a RHEL 6.3 machine on 2012-08-08. clearly, the version numbers
# and/or URLs should be made variables. cheers, zmil...@cs.wisc.edu
mkdir mosh
cd mosh
import urllib2
from bs4 import BeautifulSoup
from time import sleep
base = "https://www.reddit.com/user/{0}/"
def get_subreddits(username):
url = base.format(username)
soup = get_next(url)
@bantmen
bantmen / domain_finder.py
Created December 30, 2015 21:20 — forked from stepchowfun/domain_finder.py
Generates domain names according to a Markov chain trained on the English dictionary and checks their availability.
#!/usr/bin/python -O
from collections import defaultdict
from random import random, choice
from string import ascii_lowercase
from subprocess import Popen, PIPE
from time import time, sleep
# get a list of words with only ASCII characters
words = [w.strip().lower() for w in open("/usr/share/dict/words").readlines()]
words = [w for w in words if all([c in ascii_lowercase for c in w])]
;(function ($, window) {
var intervals = {};
var removeListener = function(selector) {
if (intervals[selector]) {
window.clearInterval(intervals[selector]);
intervals[selector] = null;
}
@bantmen
bantmen / A2 mytest
Created February 26, 2015 02:10
A2 mytest
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <sys/types.h>
#include <sys/mman.h>
#include "smalloc.h"
#define SIZE 4096 * 64
/*
made_change = True
While made_change: # continue while any change is possible
made_change = False # see if any changes are still possible
For all edges (u,v) in E:
If u in S AND v in T AND f(u,v)<c(u,v):
S = S ∪ {v} # move v from T to S
T = T - {v}
made_change = True
Else If u in T AND v in S AND f(u,v)>0:
S = S ∪ {u} # move u from T to S