Skip to content

Instantly share code, notes, and snippets.

View sntran's full-sized avatar

Sơn Trần-Nguyễn sntran

View GitHub Profile
@sntran
sntran / Cactus Kev's Poker Hand Evaluator.md
Last active December 20, 2023 19:14
Cactus Kev's Poker Hand Evaluator (taken from http://suffe.cool/poker/evaluator.html)

A while ago, I decided to take a shot at writing a poker hand evaluator in the programming language "C". There are already numerous evaluators out there, but I had an idea for an algorithm that might be faster than anything already out there. The basic concept is to write a routine that would take a five card poker hand and return it's overall "value". This is extremely valuable in any poker-related software, since the code will constantly be comparing various player's hand with each other to determine the "winner". Here is my concept on how I thought I could write a fast evaluator.


Okay, before we start digging into my algorithm, please read this first. I usually get one or two emails every month from somebody interested in my algorithm or poker code. And they typically ask me if I happen to have a seven-card poker evaluator. The answer is yes. I did indeed write a seven-card hand evaluator a few years after writing the five-card one. It used a completely new algorithm, completely unrelated to my five-

@sntran
sntran / README.md
Created November 20, 2023 16:06
Fshare API v3
@sntran
sntran / build.mjs
Created May 19, 2023 20:38
Esbuild serve and reload
import esbuild from "esbuild";
import { createServer } from "http";
const clients = [];
esbuild
.build({
entryPoints: ["./index.tsx"],
bundle: true,
outfile: "bundle.js",
@sntran
sntran / Chunker.ts
Created February 6, 2023 03:50
A TransformStream that slices into chunks of a given size.
/**
* A TransformStream that slices into chunks of a given size.
*/
export class Chunker extends TransformStream<Uint8Array, Uint8Array> {
constructor(chunkSize: number) {
let partialChunk = new Uint8Array(chunkSize);
let offset = 0;
function transform(chunk: Uint8Array, controller: TransformStreamDefaultController) {
let i = 0;
@sntran
sntran / shell2http.exs
Created December 10, 2021 04:38
HTTP-server to execute shell commands in a single file
#!/usr/bin/env elixir
help = ~S"""
HTTP-server to execute shell commands.
The CLI takes a pair of path and the shell commands and generates the
routing. Upon requests to a matched path, the corresponding shell command
is executed, and the output is responded to the client.
The routing is generated by Plug.Router so it is really fast, and only
@sntran
sntran / calendar.xsl
Created January 29, 2015 14:50
A Calendar in XSLT
<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:template name="calendar">
<xsl:param name="month" select="substring($page-modified-date, $date-modified-length - 7, 2)" />
<xsl:param name="year" select="substring($page-modified-date, $date-modified-length - 4, 4)" />
<!-- Default to an empty node list. -->
<xsl:param name="events" select="/.." />
<xsl:variable name="month-name">
@sntran
sntran / fclone.sh
Last active August 28, 2021 17:46
fclone.sh - rclone wrapper with extra functionality
#!/bin/bash
# fclone.sh v0.4.0
#
# Wrapper around rclone with extra functionality:
#
# - Flag `--drive-service-account-file-path` to take a random service account file from that folder
# - Flag `--drive-service-account-file-path` can also take a URL for a service account credentials.
# - `remote:{ID}` syntax to use the folder with that ID in the remote, instead of full path.
#
# Usage:
@sntran
sntran / decode.exs
Created April 26, 2021 03:00
Erlang's yEnc benchmarks
# Usage: mix run bench/decode.exs [optional switches]
# Optional switches:
# -z, --size <bytes> - Binary size in bytes to decode (default is 76800)
# -s, --sleep <seconds> - warmup time before real benchmark, in seconds (default is 2)
# -j, --jobs <number> - number of processes to be used for each benchmarking job (default is 1)
# -x, --extended_statistics - whether to show extended statistics
#
# Hit Ctrl+C twice to stop it.
{options, _argv, _invalid} = OptionParser.parse(System.argv(),
@sntran
sntran / $.js
Created October 25, 2019 16:28
jQuery-like $
const $ = (selector, parent = document) => Array.from(parent.querySelectorAll(selector));
@sntran
sntran / 2d_component.erl
Created June 25, 2012 05:30
Entity System Prototype in Erlang
-module ('2d_component').
-behaviour(gen_event).
-export([init/1, handle_event/2, terminate/2]).
init({X, Y, Width, Height, Rotation}) ->
{ok, {X, Y, Width, Height, Rotation}}.
handle_event({change, {x, NewX}}, {OldX, OldY, W, H, Rotation}) ->
io:format("Entity moved from (~p, ~p) to (~p, ~p).~n", [OldX, OldY, NewX, OldY]),