Skip to content

Instantly share code, notes, and snippets.

View jweinst1's full-sized avatar
🎯
Focusing

Josh Weinstein jweinst1

🎯
Focusing
View GitHub Profile
@jweinst1
jweinst1 / graph_processing.rs
Last active July 27, 2024 17:55
graph processing in rust
use std::fmt;
use std::clone::Clone;
use std::cmp::Eq;
#[derive(Debug)]
#[derive(Eq, Hash, PartialEq)]
struct Value(String);
impl Clone for Value {
fn clone(&self) -> Self {
@jweinst1
jweinst1 / trie_benchmark.cpp
Created July 22, 2024 02:03
A bench mark of a database trie index in C++
#include <cstdio>
#include <cstring>
#include <cstdint>
#include <stdlib.h>
#include <vector>
#include <chrono>
#include <unordered_set>
#include <string>
#include <sys/stat.h>
#include <assert.h>
#include <stdio.h>
#include <stdint.h>
#include <stdlib.h>
#include <string.h>
#include <limits.h>
#include <sys/mman.h>
#include <sys/stat.h>
#include <sys/socket.h>
#include <sys/stat.h>
#include <sys/time.h>
#include <stdio.h>
#include <stdint.h>
#include <stdlib.h>
#include <string.h>
#include <limits.h>
#include <sys/mman.h>
#include <sys/stat.h>
#include <sys/socket.h>
#include <sys/stat.h>
#include <arpa/inet.h>
@jweinst1
jweinst1 / memory_buffer.c
Last active June 29, 2024 07:13
memory mapped buffer in C
#include <stdio.h>
#include <stdint.h>
#include <stdlib.h>
#include <string.h>
#include <limits.h>
#include <sys/mman.h>
#include <sys/stat.h>
#include <sys/socket.h>
#include <sys/stat.h>
#include <arpa/inet.h>
@jweinst1
jweinst1 / inlace_rehash.py
Created June 21, 2024 03:39
in place rehash of hash table in Python
import sys
import random
import string
def rand_str(n):
return ''.join(random.choice(string.ascii_uppercase + string.digits) for _ in range(n))
def rand_str_set(n, amount):
return {rand_str(n) for i in range(amount)}
#include <stdio.h>
#include <stdlib.h>
#include <stdint.h>
#include <time.h>
#include <assert.h>
static const size_t MIN_ROW_SIZE = sizeof(size_t) * 2;
int storage_row_empty(const char* row) {
return row[0] == '\0';
import sys
import socket
import os
import json
class Lock:
def __init__(self, owner, member_set):
self.owner = owner
@jweinst1
jweinst1 / nonblockunix.py
Created June 8, 2024 22:07
non blocking unix sockets in python
>>> import socket
>>> server = socket.socket(socket.AF_UNIX, socket.SOCK_STREAM)
>>> server.setblocking(False)
>>> server.bind("foo.sock")
>>> server.listen(1)
>>> connection, client_address = server.accept()
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/Library/Frameworks/Python.framework/Versions/3.11/lib/python3.11/socket.py", line 293, in accept
fd, addr = self._accept()
@jweinst1
jweinst1 / unix_lib.cpp
Last active June 6, 2024 08:12
unix sockets simplified programming
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <assert.h>
#include <signal.h>
#include <errno.h>
//--------system headers -------//
#include <unistd.h>
#include <sys/un.h>
#include <fcntl.h>