Skip to content

Instantly share code, notes, and snippets.

View worldOneo's full-sized avatar
🤗
Trying new things

worldOneo

🤗
Trying new things
View GitHub Profile
@worldOneo
worldOneo / main.zig
Created October 15, 2023 11:41
Epoll based Event Loop chat application
const std = @import("std");
// primitive of the event loop.
// Ctx is typically a pointer to *This and data a pointer to the Users data.
// destroyData is called after the event has finished and must clean up the event to avoid leaks.
const Event = struct {
ctx: *anyopaque,
data: *anyopaque,
name: []const u8,
destroyData: *const fn (*anyopaque, *anyopaque) void,
@worldOneo
worldOneo / themap.go
Last active October 20, 2023 21:35
Concurrent (almost) constant O(1) HashMap for Go
package themap
import (
"runtime"
"sync"
"sync/atomic"
)
type Hashable interface {
comparable
@worldOneo
worldOneo / subprocess.js
Created March 17, 2023 09:44
NodeJS simple subprocess shell
const {spawn} = require('child_process');
const child = spawn('/bin/bash');
process.stdin.on('data', function(data) {
child.stdin.write(data);
});
child.stdout.on('data', function(data) {
process.stdout.write(data);
});
@worldOneo
worldOneo / calculator.rs
Created November 15, 2022 15:20
A simple calculator. First input is formula like `10*@log(x)+a` second input are variables like `x=2 a=4`
use std::{
collections::{HashMap, VecDeque},
io,
ops::{Add, Mul},
};
#[derive(Debug)]
enum AST {
Const(f64),
Func(String, Box<AST>),
@worldOneo
worldOneo / printhex.S
Created October 16, 2022 20:47
print hex numbers in AT&T ASM
.global main
.set print_hex_msb4mask, 0xf000000000000000
.data
print_hex_chars:
.ascii "0123456789abcdef"
.text
syscall4:
movq %rax, %rax
@worldOneo
worldOneo / Handler.cs
Created August 28, 2022 12:31
Unity procedural voxel generator
using System;
using System.Collections.Generic;
using System.Linq;
using UnityEngine;
[RequireComponent(typeof(MeshFilter))]
public class GameHandler : MonoBehaviour
{
Mesh mesh;
@worldOneo
worldOneo / table.c
Created May 11, 2022 16:12
Simple (hash) table written in C ~10ns lookups
#include <stdint.h>
#include <stdlib.h>
#include <stdbool.h>
typedef uint64_t u64;
typedef struct Table
{
u64 nullValue;
bool hasNull;
@worldOneo
worldOneo / generator.js
Created March 4, 2022 15:32
Simple UID generator for JavaScript with logic to ensure uniqueness.
const chars = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz1234567890+@".split("");
const maxBase = n => {
let r = "";
while (n) {
r += chars[n & 63];
n = n/64|0;
}
return r;
};
@worldOneo
worldOneo / ngram.rs
Created February 17, 2022 19:11
Simple, fast ngram index written in rust
use std::collections::BinaryHeap;
use std::fmt::Debug;
use std::vec;
use std::{collections::HashMap, io, time::Instant};
#[derive(Debug)]
struct NGramMeta<T: Clone + PartialEq> {
bind: T,
document: Vec<String>,
freq: f64,
@worldOneo
worldOneo / fuzzy.rs
Last active February 15, 2022 22:46
FuzzySearch engine using BK-Tree written in Rust.
use std::fmt::Debug;
use std::io::{stdout, Write};
use std::{collections::HashMap, env, fs, io, time::Instant};
#[derive(Debug)]
struct FuzzyNode<T>
where
T: Clone,
{
value: Option<(String, T)>,