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 / 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;
}
@jweinst1
jweinst1 / hash bench.rs
Created March 11, 2025 23:06
hash map rust bench
use std::collections::HashMap;
fn add_rand_strings(keys:&mut Vec<String>, amnt:usize, l:usize) {
const CHARSET: &[u8] = b"ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789";
let mut rnd = 548324;
for i in 0..amnt {
let mut s = String::new();
for j in 0..l {
#include <string>
#include <cstring>
#include <filesystem>
#include <string>
#include <iostream>
#include <regex>
#include <vector>
#include <unordered_map>
#include <cstdio>
#include <cstdlib>
@jweinst1
jweinst1 / hash_merge_tree.cpp
Last active March 10, 2025 02:07
hash merge tree
#include <map>
#include <unordered_map>
#include <string>
#include <vector>
#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <cstdint>
#include <ctime>
#include <optional>
@jweinst1
jweinst1 / unordered_map_bucket.cpp
Last active February 24, 2025 10:25
playing with unordered buckets in c++
int main(int argc, char const *argv[])
{
std::unordered_map<std::string, std::string> fooMap;
const std::string s1 = "foobar";
const std::string s2 = "doobar";
const std::string s3 = "loobar";
const std::string s4 = "4oobar";
const std::string s5 = "77oobar";
std::printf("Bucket count is %zu\n", fooMap.bucket_count());
@jweinst1
jweinst1 / bloom_hash.cpp
Created February 22, 2025 09:50
A hash map that doesn't resolve collisions and tries to be a bloom filter but gives location and membership info
#include <map>
#include <string>
#include <vector>
#include <cstdio>
#include <cstdlib>
#include <cstdint>
#include <ctime>
#include <optional>
#include <chrono>
#include <memory>