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 / byte_protocol.rs
Created April 8, 2024 06:28
byte protocols in rust for networks
use std::net::{TcpListener, TcpStream, Shutdown,
ToSocketAddrs, SocketAddr, IpAddr,
Ipv4Addr, Ipv6Addr};
use std::collections::HashMap;
use std::{thread, time};
use std::io::{Read, Write, ErrorKind};
use std::env;
use std::str;
static DEFAULT_ADDR:&'static str = "localhost:12001";
@jweinst1
jweinst1 / main.rs
Created April 6, 2024 19:55
coordinated server cluster in rust
use std::net::{TcpListener, TcpStream, Shutdown,
ToSocketAddrs, SocketAddr, IpAddr,
Ipv4Addr, Ipv6Addr};
use std::collections::HashMap;
use std::{thread, time};
use std::io::{Read, Write, ErrorKind};
use std::env;
use std::str;
//use hello_world::objects::DataObject;
@jweinst1
jweinst1 / hashing_of_hash.c
Created March 31, 2024 08:10
re hashing in C
#include <stdio.h>
#include <stdlib.h>
#include <stdint.h>
#include <string.h>
size_t
hash(const void *str, size_t size)
{
size_t hash = 5381;
unsigned char c;
@jweinst1
jweinst1 / atomics.rs
Created March 17, 2024 07:27
rust basic atomics
use std::sync::atomic::{AtomicU16, AtomicU8, AtomicPtr, Ordering};
fn store_ptr(obj:*mut i32, ptr:&AtomicPtr<i32>) {
ptr.store(obj, Ordering::SeqCst);
}
fn load_ptr(ptr:&AtomicPtr<i32>) -> *mut i32 {
ptr.load(Ordering::SeqCst)
}
@jweinst1
jweinst1 / hazard.cpp
Last active March 12, 2024 07:44
a hazard pointer and ref count combo
#include <atomic>
#include <thread>
#include <chrono>
#include <cstdint>
#include <limits>
#include <cassert>
#include <cstdio>
struct HazardNode {
std::atomic<void*> ptr = nullptr;
@jweinst1
jweinst1 / graph.c
Last active February 26, 2024 02:39
C graph data structure
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <stdarg.h>
#include <stdint.h>
#include <assert.h>
static const char* GRAPH_LABEL_FIELD = "_NLABEL";
static const char* GRAPH_ROOT_NAME = "_RGRAPH";
static const char* GRAPH_ROOT_VAL = "1";
@jweinst1
jweinst1 / type_names.rs
Last active February 9, 2024 05:38
new graph model of vertice and edges.
type GraphEdge = String;
type GraphRelation = String;
type GraphEdgeMap = HashMap<GraphRelation, HashSet<GraphEdge>>;
fn main() {
println!("Hello, world!");
}
use std::rc::Rc;
use std::sync::{RwLock, Arc};
use std::thread;
use std::collections::HashMap;
use std::collections::HashSet;
use std::fmt;
use std::clone::Clone;
fn main() {
@jweinst1
jweinst1 / graphobject.rs
Last active February 2, 2024 10:41
sample graph object in rust
use std::rc::Rc;
use std::sync::{RwLock, Arc};
use std::thread;
use std::collections::HashMap;
use std::collections::HashSet;
use std::fmt;
use std::clone::Clone;
#[derive(Debug)]
@jweinst1
jweinst1 / camera_tricks.html
Created January 26, 2024 07:10
html5 canvas game with camera
<!DOCTYPE html>
<html>
<head>
<title>Runner Game</title>
<style>
canvas { background: #eee;
display: block;
margin: 0 auto;
}
</style>