Skip to content

Instantly share code, notes, and snippets.

View bnsh's full-sized avatar

Binesh Bannerjee bnsh

View GitHub Profile
@bnsh
bnsh / Dockerfile
Created August 17, 2023 04:15
Why is chown not working within Docker? It _used_ to..?
FROM ubuntu:22.04
RUN mkdir /tmp/blah && chown www-data /tmp/blah && ls -ld /tmp/blah
# When it's building I see
# drwxr-xr-x 2 www-data root 4096 Aug 17 04:12 /tmp/blah
# Why when I run this with docker container run user/image /bin/ls -ld /tmp/blah
# do I see
# drwxr-xr-x 2 root root 4096 Aug 17 04:12 /tmp/blah
@bnsh
bnsh / Dockerfile
Created June 21, 2023 21:32
KMeans fails with sklearn.cluster.KMeans if passed init=np.array.
FROM python:3.11
COPY main.py /tmp/main.py
COPY requirements.txt /tmp/requirements.txt
RUN python3 -m pip install -r /tmp/requirements.txt
CMD ["python3", "/tmp/main.py"]
@bnsh
bnsh / pizza_verify_fixed.py
Created June 8, 2022 04:52
This is the fixed version of pizza_verify.py
#! /usr/bin/env python3
# vim: expandtab shiftwidth=4 tabstop=4
"""
Hi.
We're trying to implement this code at https://bitcoin.stackexchange.com/a/32308/235711 in python with the
ecdsa library. Unfortunately, we're not clear on what language this code below is written in.. C++? C#?
const QByteArray xx ( QByteArray::fromHex ( "01000000018dd4f5fbd5e980fc02f35c6ce145935b11e284605bf599a13c6d41"
@bnsh
bnsh / pizza_verify.py
Last active June 2, 2022 01:00
This is our (failed) attempt to replicate the pizza transaction in python.
#! /usr/bin/env python3
# vim: expandtab shiftwidth=4 tabstop=4
"""
Hi.
We're trying to implement this code at https://bitcoin.stackexchange.com/a/32308/235711 in python with the
ecdsa library. Unfortunately, we're not clear on what language this code below is written in.. C++? C#?
We'd like to verify using python, but it doesn't seem to work. Can someone tell us what we're doing wrong?
@bnsh
bnsh / average_of_averages_based_on_windows.sql
Last active February 6, 2022 07:52
I have a set of ranges, and a set of data with positions, and I'd like to create averages of a specific window size (I'm using 3 in this example) of every possible sub range within these left and right positions... (I can't actually think of a good way of describing it, so here's a demo I made to perhaps make it clearer.)
create or replace table data (
pos int not null,
val float not null,
constraint data_pk primary key (pos)
);
insert into data (pos, val) values
(1, 2), (2, 3), (3, 5), (4, 7), (5, 11), (6, 13), (7, 17), (8, 19),
(9, 23), (10, 29), (11, 31), (12, 37), (13, 41), (14, 43), (15, 47), (16, 53),
(17, 59), (18, 61), (19, 67), (20, 71), (21, 73), (22, 79), (23, 83), (24, 89),
@bnsh
bnsh / Dockerfile
Created January 5, 2022 03:52
This demonstrates my problem with running 'matplotlib.use("TkAgg")'
FROM continuumio/anaconda3
LABEL maintainer="Binesh B."
ENV TZ=US/Eastern DEBIAN_FRONTEND=noninteractive
RUN ln -snf /usr/share/zoneinfo/$TZ /etc/localtime && echo $TZ > /etc/timezone
RUN \
groupadd -r binesh -g 1000 \
&& useradd -m -s /bin/bash -g binesh -u 1000 binesh \
&& apt-get update -y \
@bnsh
bnsh / hadamard.py
Created October 2, 2021 23:30
Hadamard multiplication of a sparse matrix and a dense matrix?
#! /usr/bin/env python3
# vim: expandtab shiftwidth=4 tabstop=4
"""Hadamard multiplication of a sparse times a dense."""
import torch
from torch_sparse import SparseTensor
def main():
dense = torch.randn(5, 7)
@bnsh
bnsh / graphlet_demo.py
Created September 23, 2021 20:36
This relates to CS224W on graphlet features.
#! /usr/bin/env python3
# vim: expandtab shiftwidth=4 tabstop=4
"""Find graphlets"""
from collections import Counter
def assign_triplet_to_graphlet(adjacency_list, graphlets, triplet):
assert len(triplet) == 3
reverse_graphlets = {tuple(sorted(graphlet.items())): name for name, graphlet in graphlets.items()}
@bnsh
bnsh / transformer_test.py
Created August 26, 2021 05:59
This program fails the assertion "edge_attr is not None", but edge_attr is in fact _not_ None
#! /usr/bin/env python3
# vim: expandtab shiftwidth=4 tabstop=4
"""This fails with a message that says that edge_attr is None. But, edge_attr is _not_ None"""
import argparse
import torch
import torch_geometric
import torch_scatter
import torch_sparse
@bnsh
bnsh / graph_test.py
Last active August 26, 2021 04:10
This program succeeds if run with --device="cpu", but fails with the error "RuntimeError: CUDA error: invalid configuration argument" if run with --device="cuda".. Why?
#! /usr/bin/env python3
# vim: expandtab shiftwidth=4 tabstop=4
"""Why does this fail when run with --device cuda?"""
import argparse
import torch
import torch_geometric
import torch_scatter
import torch_sparse