Skip to content

Instantly share code, notes, and snippets.

View vhxs's full-sized avatar
💻
coding or mathing

Vikram Saraph vhxs

💻
coding or mathing
View GitHub Profile
@vhxs
vhxs / draw_2d.py
Created November 5, 2022 21:01
Draw a 2-dimensional simplicial complex in matplotlib
# modified from this:
# https://github.com/iaciac/py-draw-simplicial-complex/blob/master/Draw%202d%20simplicial%20complex.ipynb
import networkx as nx
import itertools
import matplotlib.pyplot as plt
import numpy as np
np.random.seed(10)
@vhxs
vhxs / standard_chromatic.py
Created November 2, 2022 01:58
The standard chromatic subdivision visualized
# The standard chromatic subdivision is a mathematical operator in combinatorial topology that takes a chromatic
# simplicial complex and subdivides in a fractal-like manner. It represents all states of a distributed system after
# processes participate in an immediate snapshot.
# Immediate snapshots are a theoretical synchronization primitive, equivalent to atomic registers up to computational
# equivalence. They are used extensivelty in computability proofs within the context of distributed computing.
# This code draws the third standard chromatic subdivision of the 2-simplex (vertices are not colored).
from tkinter import *
# Attempt 1 at implementing compare-and-swap (CAS) using Redis transactions.
# This attempt fails since pipeline.get can't be evaluated within the scope
# of a transaction. Its return value cannot be used within a transaction,
# so we cannot conditionally invoke pipeline.set based on what is returned by pipeline.get.
# Below, current_value isn't actually None, but a reference to a pipeline.get operation
# to be queued into the transaction.
import redis
from multiprocessing import Process
import time
@vhxs
vhxs / ceil_inequality.py
Created October 23, 2022 01:47
testing ceiling inequality
# The following inequality doesn't hold for all x, y \in \mathbb{R}. Does it hold for x, y \in mathbb{N}?
# Here's a bruteforce test for 1 <= x, y <= 1000
import math
for x in range(1, 1000):
for y in range(1, 1000):
assert y >= math.ceil(x / math.ceil(x / y))
@vhxs
vhxs / index.html
Last active October 16, 2023 21:06
states I've visited
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<script src="https://d3js.org/d3.v3.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/queue-async/1.0.7/queue.min.js"></script>
<style type="text/css">
/* states I've visited
ripped and modified from here: http://bl.ocks.org/travisdoesmath/fc945804e31bf35f3ba7ddd4f659429c
@vhxs
vhxs / votedem_classifier.py
Last active September 25, 2022 23:13
Quick example of using a pre-trained huggingface model for sentimental classification of streamed r/votedem comments
from transformers import pipeline
import praw
import os
reddit = praw.Reddit(
client_id=os.environ['REDDIT_ID'],
client_secret=os.environ['REDDIT_SECRET'],
password=os.environ['REDDIT_PASS'],
user_agent="script by u/vsaraph",
username="vsaraph"
@vhxs
vhxs / App.js
Last active August 29, 2022 02:12
simplest nontrivial example I could come up with of using websockets to push data from server to client
// *really* simple example of browser client subscribing the reddit comments via websocket
// this is how a server can push state to a web client
// things like push notification etc
// use create-react-app to create a React application
// replace src/App.js with the contents of this file
// then run the app with `npm start` and `ws_server.py` running
// and open a web console. You should see reddit comments printed live in the console
// ripped and modified from here: https://stackoverflow.com/a/60161181
@vhxs
vhxs / hello.s
Created August 24, 2022 01:54
arm64 assembly example
/*
Hello world in arm64
https://peterdn.com/post/2020/08/22/hello-world-in-arm64-assembly/
as -o hello.o hello.s
ld -s -o hello hello.o
./hello
*/
.data
(* Coq is a proof assistant. Not a theorem prover. *)
(* also github has syntax highlighting for Coq, wow. *)
Require Import Ring.
Require Import Arith.
Theorem simply_poly : forall (x : nat), (x + 1) * (x + 2) = x * x + 3 * x + 2.
Proof. intros. ring. Qed.
@vhxs
vhxs / main.go
Last active August 5, 2022 23:48
Using CAS in golang
// Using compare-and-swap synchronization primitive to atomically update a shared counter
package main
import (
"fmt"
"sync"
"sync/atomic"
)