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 / mqueue.c
Created May 12, 2025 07:27
a disk backed message queue in C with kqueue
#include <stdio.h>
#include <stdlib.h>
#include <stdint.h>
#include <stddef.h>
#include <unistd.h>
#include <fcntl.h>
#include <string.h>
#include <sys/mman.h>
#include <errno.h>
#include <inttypes.h>
@jweinst1
jweinst1 / hostwide.c
Created May 7, 2025 01:15
host wide cpu usage on a mac
#include <stdio.h>
#include <mach/mach.h>
#include <mach/mach_host.h>
int main() {
// Get the host's CPU statistics
host_cpu_load_info_data_t cpu_info;
mach_msg_type_number_t count = HOST_CPU_LOAD_INFO_COUNT;
kern_return_t kr = host_statistics(mach_host_self(), HOST_CPU_LOAD_INFO, (host_info_t)&cpu_info, &count);
@jweinst1
jweinst1 / kqueue_tail.c
Last active May 11, 2025 23:08
Tailing implemented with Kqueue
#include <stdlib.h>
#include <stdio.h>
#include <string.h>
#include <stdint.h>
#include <stddef.h>
#include <limits.h>
#include <assert.h>
#include <sys/event.h>
#include <sys/time.h>
@jweinst1
jweinst1 / fsevents.c
Last active May 2, 2025 00:31
Monitor FSEvents in C with apple library core services
#include <CoreServices/CoreServices.h>
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
void fsevent_callback(
ConstFSEventStreamRef streamRef,
void *clientCallBackInfo,
size_t numEvents,
void *eventPaths,
@jweinst1
jweinst1 / atlas_based_game.swift
Last active May 1, 2025 00:09
img atlas based game swift
//
// GameScene.swift
// FunScape
//
// Created by Joshua Weinstein on 4/26/25.
//
import SpriteKit
import GameplayKit
@jweinst1
jweinst1 / game.swift
Last active April 22, 2025 05:44
playground game of blocks in swift with contacts and jumps and joints
//: A SpriteKit based Playground
import PlaygroundSupport
import SpriteKit
let sceneView = SKView(frame: CGRect(x:0 , y:0, width: 640, height: 480))
class GameOverScene : SKScene {
var label = SKLabelNode(fontNamed: "Chalkduster")
@jweinst1
jweinst1 / match_multi_group.cpp
Created April 3, 2025 23:07
match multiple regex groups in C++
#include <regex>
int main(int argc, char const *argv[])
{
const std::string foo = "hello \n sir \n";
std::vector<EventPos> pairs;
generateEvents(foo, '\n', pairs);
std::printf("%zu\n", pairs.size());
const std::string sample = "remote= bar foo=4 six=bar fhhfghfgdhgdf do=555";
const std::regex sampleRex("([a-zA-Z0-9_]+)\\s*=\\s*([a-zA-Z0-9_]+)");
@jweinst1
jweinst1 / search.cpp
Created April 3, 2025 21:49
events search in C++
#include <string>
#include <filesystem>
#include <vector>
#include <cstdio>
#include <cstdlib>
struct EventPos {
size_t ind = 0;
size_t size = 0;
@jweinst1
jweinst1 / bitunset.rs
Created March 15, 2025 00:50
rust container for mapping to next unset bit.
fn bit_mask_index(mask:u64) -> Option<usize> {
match mask {
0 => None,
1 => Some(0),
2 => Some(1),
4 => Some(2),
8 => Some(3),
16 => Some(4),
@jweinst1
jweinst1 / bitsetorunset.cpp
Created March 14, 2025 23:52
find the unset or set bits of a number in C++
size_t find_unset_bit(size_t num) {
return ~num & (num + 1);
}
size_t find_first_set_bit(size_t num) {
return num & -num;
}