Skip to content

Instantly share code, notes, and snippets.

View weijuwang's full-sized avatar

Weiju Wang weijuwang

  • 00:52 (UTC -07:00)
View GitHub Profile
@weijuwang
weijuwang / mahjong.rs
Created February 23, 2026 23:40
Riichi mahjong hand interpreter/scorer
use std::cmp::min;
use std::fmt;
use std::fmt::{Display, Formatter};
use std::collections::HashMap;
use std::ops::*;
use std::str::FromStr;
use int_enum::IntEnum;
use bitfields::bitfield;
use tinyset::{Fits64, Set64};
@weijuwang
weijuwang / activate.rs
Created November 5, 2022 06:16
Neural network from scratch in Rust
//! Common activation functions
/// An activation function.
pub type Func = dyn Fn(f64) -> f64;
/// f(x) = x
///
/// This should not be used as an actual activation function. It is only here for testing.
pub fn linear(x: f64) -> f64 {
x
#include <stdio.h>
#include <stdbool.h>
#include <stdint.h>
/**
* @brief Dump the contents of memory at `data`.
*
* @param data Location of memory to dump.
* @param fmt Format for the printed data. THIS IS NOT THE SAME AS A PRINTF FORMAT.
* `fmt` may consist of multiple formats separated by whitespace.
@weijuwang
weijuwang / webserver.c
Created July 29, 2022 04:31 — forked from epshteinmatthew/webserver.c
it needs malloc and better features, but it's something?
#include <sys/types.h>
#include <sys/socket.h>
#include <netdb.h>
#include <stdio.h>
#include <poll.h>
#include <string.h>
#include <unistd.h>
#include <stdlib.h>
#include <sys/sendfile.h>
@weijuwang
weijuwang / intel8080.cpp
Last active July 15, 2022 06:24
Intel 8080 emulator
/**
* @file intel8080.cpp
* @author Weiju Wang (weijuwang@aol.com)
* @brief An emulator for the Intel 8080 microprocessor.
* @version 0.1
* @date 2022-07-14
*
* @copyright Copyright (c) 2022 Weiju Wang.
* This file is part of `intel8080`.
* `intel8080` is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version.
@weijuwang
weijuwang / Midnight.swift
Last active May 29, 2022 03:41
Midnight parser for Swift
//
// Parser.swift
// Midnight
//
// Created by Weiju Wang on 5/26/22.
//
public protocol MNRuleProtocol {
func _match(data: Midnight._ForwardedData) -> Midnight._InternalResult?
}
@weijuwang
weijuwang / Parser.cs
Last active January 16, 2022 07:04
Generic parser
// Parser.cs
/*
Copyright (C) 2022 Weiju Wang.
This program is free software: you can redistribute it and/or modify it under
the terms of the GNU General Public License as published by the Free Software
Foundation, either version 3 of the License, or (at your option) any later
version.
This program is distributed in the hope that it will be useful, but WITHOUT
ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
@weijuwang
weijuwang / totpal_rules.md
Created September 25, 2021 22:25
Two of These People Are Lying: Rules

Two Of These People are Lying - Rules

Two of These People Are Lying (TOTPAL) is a game played between at least three players, invented by the Technical Difficulties on Youtube. One of the players is designated the Guesser. (In this document, the word "players" refers to all players including the Guesser.)

Each player, except for the Guesser, chooses a Wikipedia article that is

  1. not a list (e.g. "List of nuclear accidents") or disambiguation article
  2. not identical to another player’s

and writes the article’s full name on a piece of paper, which is then handed to the Guesser. The Guesser must not see what is written on any player’s paper; players must not read any other player’s article for information.

@weijuwang
weijuwang / Evias.swift
Created May 24, 2021 19:34
Evias: Reference Interpreter
/*
Evias: an interpreter and reference implementation for my esoteric programming language, Evias.
Usage:
Create an instance of `Evias.Interpreter`; to run code, call the `run(code:)`
method, passing in the code you want to run as the argument.
Example:
```
let interpreter = Evias.Interpreter()
@weijuwang
weijuwang / slashes.cpp
Created April 27, 2021 17:14
Interpreter for the Slashes Programming Language
/*
An interpreter for the Slashes esoteric programming language, which you can read about at https://esolangs.org/wiki////
This program was hastily written in the span of precisely one hour. As such, it has definitely been extensively tested
for bugs, and you definitely should not email me at geofspilot@gmail.com if you find any more. Thanks!
Don't look for comments, you won't find any.
Copyright (C) Captain Foxtrot 2020.
This program is free software: you can redistribute it and/or modify