Skip to content

Instantly share code, notes, and snippets.

@neelsomani
neelsomani / gaussian_adversary.py
Last active July 12, 2026 17:17
Adversarial image test (embedded text)
import numpy as np
from PIL import Image, ImageDraw, ImageFont
def get_text_mask(text, font, size):
"""Create a mask showing where text pixels are."""
mask = Image.new('L', size, 0)
draw = ImageDraw.Draw(mask)
letters = [
['H', 'E', 'Y', 'C'],
@neelsomani
neelsomani / repro_bracket_mismatch.py
Created November 22, 2025 01:41
Repro: csp_yolo2 gives the wrong output for bracket matching
"""
Reproduce bracket-counting mismatch on csp_yolo2: model predicts ']' instead of ']]' on the first viz sample.
Run from repo root:
source .venv/bin/activate
GAO_ONLINE=1 python circuit_sparsity/repro_bracket_mismatch.py
"""
from __future__ import annotations
@neelsomani
neelsomani / ssh-tunnel-to-a-docker-container-on-a-remote-server.md
Created April 11, 2025 00:20
How to SSH tunnel to a Docker container on a remote server

How to SSH Tunnel to a Docker Container on a Remote Server

Neel Somani - May 4, 2017

Docker makes it easy to ensure that your project has all of the dependencies that it needs. It makes sense to run your web server within a Docker container, but you might want to access the web server via your browser (i.e., map a port on your machine to a port within the Docker container). Moreover, you might want to run the web server within a Docker container on a remote server, and map a port on your local machine to the web server. This tutorial explains how you can do so easily.


1) Expose the Port Within Your Docker Container to the Remote Server

@neelsomani
neelsomani / asyncio-example.py
Created April 11, 2025 00:17
Executing HTTP requests in parallel with asyncio
import asyncio
import aiohttp
async def fetch(session, url):
"""
Asynchronously fetch the content of a URL using an aiohttp session.
:param session: An aiohttp ClientSession instance.
:param url: The URL to fetch.
:return: The text content of the response.
@neelsomani
neelsomani / basictex.md
Last active April 11, 2025 00:13 — forked from caoool/basicTexSetupMacOS.md
[macOS minimal latex support setup] setup and use macOS LaTeX environment with the minimal BasicTeX

How to get MacTeX faster: Easily using BasicTeX Neel Somani - April 15, 2016

If you type equations regularly, you've probably heard of LaTeX. But the OSX distribution (MacTeX) is huge -- the 3 GB file can take forever to download, and it takes up a lot of space. BasicTeX is a much smaller alternative, but it's intimidating to new users. This tutorial sets you up with BasicTeX in no time, so you can easily get started.

  1. Installing BasicTeX I used Homebrew to install BasicTeX, since I can later use it to easily uninstall BasicTeX if needed. You install BasicTeX via brew cask:
brew install brew-cask
@neelsomani
neelsomani / jargon.py
Created March 24, 2025 07:27
Tech Jargon Generator
import random
def generate_jargon():
structures = [
"Capitalize on the {ADJ} {NOUN}. That's how you maximize the potential of {NOUN}.",
"Think about {NOUN}. It's highly relevant in the context of {NOUN}.",
"I would definitely {VERB} at this point. It's important to think {ADJ}.",
"If you don't {VERB}, you are setting your {NOUN} up for disaster - hands down.",
"Probably the most {ADJ} {NOUN} can be derived from the industry of {NOUN}.",
"Alright, but if you don't incorporate the {ADJ} {NOUN}, then what is attracting the {NOUN}?",
@neelsomani
neelsomani / generator.py
Created March 24, 2025 07:21
Reddit Front Page Generator Script
import requests
from bs4 import BeautifulSoup
import random
import os
import json
def get_popular_subreddits():
base_url = "https://www.reddit.com/best/communities/"
subreddits = []
@neelsomani
neelsomani / decode_msgpack.py
Created March 14, 2025 02:51
Decode msgpack in Python
import msgpack
import binascii
def decode_msgpack_from_bytes(encoded_data):
"""
Decodes a MessagePack-encoded binary string and prints the result.
Args:
encoded_data (bytes): MessagePack-encoded binary data.
@neelsomani
neelsomani / cdpcurl.py
Created January 28, 2025 04:09
Implementation of Coinbase's cdpcurl in Python
import argparse
import json
import os
import jwt
import requests
from datetime import datetime, timedelta
from cryptography.hazmat.primitives.asymmetric import ec
from cryptography.hazmat.primitives import serialization
from cryptography.hazmat.backends import default_backend
@neelsomani
neelsomani / elo.py
Last active February 13, 2025 07:44
Comparison of different ranking algorithms
import numpy as np
import random
import math
import logging
N_PLAYERS = 5
LOGGER = logging.getLogger('elo')