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 / 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 / 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 / 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 / mini_locking_server_client.c
Created October 25, 2023 08:55
polling based locking server and client in C.
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <stdint.h>
#include <signal.h>
#include <sys/stat.h>
#include <sys/socket.h>
#include <sys/stat.h>
#include <arpa/inet.h>
#include <netinet/in.h>
@jweinst1
jweinst1 / poll_tcp_server_client.c
Last active June 2, 2024 04:57
a polling and tcp based server and client in C
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <stdint.h>
#include <signal.h>
#include <sys/stat.h>
#include <sys/socket.h>
#include <sys/stat.h>
#include <arpa/inet.h>
#include <netinet/in.h>
@jweinst1
jweinst1 / full_canvas_gravity_game.html
Created February 20, 2023 08:15
A full mini game engine for html5 canvas
<!DOCTYPE html>
<html>
<head>
<title>Runner Game</title>
<style>
canvas { background: #eee;
display: block;
margin: 0 auto;
}
</style>
@jweinst1
jweinst1 / unixsocket.c
Last active August 28, 2022 04:03
sample unix client and server program
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <assert.h>
#include <signal.h>
#include <errno.h>
#include <unistd.h>
#include <sys/un.h>
#include <sys/socket.h>
@jweinst1
jweinst1 / sprite_game.html
Created June 20, 2022 15:04
Sample JS canvas sprite game in html
<!DOCTYPE html>
<html>
<head>
<title>Runner Game</title>
<style>
canvas { background: #eee;
display: block;
margin: 0 auto;
}
</style>
@jweinst1
jweinst1 / time_cachedb.cpp
Last active April 5, 2022 12:18
experimental time caching db
#include <thread>
#include <chrono>
#include <atomic>
#include <cstdio>
#include <assert.h>
#include <condition_variable>
#include <mutex>
#include <sys/mman.h>
#include <new>
@jweinst1
jweinst1 / mmap_place_new.cpp
Created October 31, 2021 12:22
C++ way of doing placement new on an mmap buffer
#include <cstdlib>
#include <cstdio>
#include <cstdint>
#include <sys/mman.h>
#include <new>
#include <atomic>
template<class T>
struct memory_ptr {
std::atomic<bool> in_use;