Skip to content

Instantly share code, notes, and snippets.

View vhxs's full-sized avatar
🤔
contemplating

Vikram Saraph vhxs

🤔
contemplating
View GitHub Profile
@vhxs
vhxs / bad_asyncio_example.py
Last active January 17, 2022 18:28
How not to use asyncio
import asyncio
import socket
async def alice():
print("started alice")
# alice's task starts: she attempts to connect to Bob's server
while True:
try:
# this is where we try to connect to bob's server
# if the server hasn't started, we try again
@vhxs
vhxs / rgb.c
Created March 13, 2022 19:52
Example program that times non-SIMD vs SIMD on ARM64 architecture
#include <arm_neon.h>
#include <stdio.h>
#include <stdlib.h>
#include <time.h>
#include <stdbool.h>
#include <string.h>
void rgb_deinterleave_c(uint8_t *r, uint8_t *g, uint8_t *b, uint8_t *rgb, int len_color) {
/*
* Take the elements of "rgb" and store the individual colors "r", "g", and "b".
@vhxs
vhxs / check_rlwe_ring_order.sage
Created March 20, 2022 21:48
Checking the cardinality of RLWE rings
# iterate over primes
for i, p in enumerate(Primes()):
# iterate over cyclotomics
for n in range(1, i+1):
# GF(p) is the finite field of order p
S = PolynomialRing(GF(p), 'x')
f = cyclotomic_polynomial(n)
R = QuotientRing(S, f)
assert R.cardinality() == p ** (f.degree())
@vhxs
vhxs / rlwe_rings_are_not_fields.sage
Created March 20, 2022 22:11
Find an RLWE ring that's not a field
for i, p in enumerate(Primes()):
for n in range(1, i+1):
S = PolynomialRing(GF(p), 'x')
f = cyclotomic_polynomial(n)
R = QuotientRing(S, f)
if not R.is_field():
print(f"GF({p}) / ({f}) is not a field!!")
quit()
@vhxs
vhxs / rationals.py
Created March 27, 2022 03:51
This is code that I used to generate and post an award-winning piece of art on DeviantArt over a decade ago...
from tkinter import *
import time
root = Tk()
def n2color(n):
p = 1.1
def f(x):
return p**-x
color = ''
for i in range(1):
bit1 = hex(int(255*f(n)))[2:]
@vhxs
vhxs / mongodb_perf.py
Last active May 8, 2022 22:05
MongoDB index benchmark
from pymongo import MongoClient, UpdateOne
import random
import time
mongo_client = MongoClient()
# drop old stuff
mongo_client['test']['without_index'].drop()
mongo_client['test']['with_index'].drop()
mongo_client['test']['index'].drop()
from pymongo import MongoClient
import random
import time
mongo_client = MongoClient()
query1 = 0
query2 = 0
j = 0
// RocksDB is a Facebook-scale key-value store designed for fast writes to SSD storage.
// How fast does this run?
#include <cassert>
#include <cstdlib>
#include <iostream>
#include <string>
#include <rocksdb/db.h>
using namespace std;
@vhxs
vhxs / docker-compose.yml
Created June 25, 2022 15:31
Minimal working example of setting up elasticsearch and kibana with a docker compose script
services:
elasticsearch:
image: docker.elastic.co/elasticsearch/elasticsearch:8.2.3
volumes:
- data:/usr/share/elasticsearch/data
environment:
- xpack.security.enabled=false
- discovery.type=single-node
ports:
- 9200:9200
#include <stdlib.h>
#include <stdio.h>
#include <cuda.h>
#define N 512
// compile with nvcc add_vectors.cu
// forward declaration of CUDA kernel
__global__ void add_vectors(int* A, int* B, int* C);