Skip to content

Instantly share code, notes, and snippets.

View Andersama's full-sized avatar

Alex Anderson Andersama

View GitHub Profile
@Andersama
Andersama / utf8_validate.h
Last active July 16, 2023 14:08
Simple c++ sub nanosecond/byte utf8 validator
#pragma once
#include <cstdint>
#include <intrin.h>
#include <string_view>
namespace utf8 {
// see: https://github.com/BobSteagall/utf_utils/blob/master/src/utf_utils.h
enum char_class : uint8_t {
ILL = 0, //- C0..C1, F5..FF ILLEGAL octets that should never appear in
// a UTF-8 sequence
//see: https://www.romu-random.org/romupaper.pdf
#include <cstdint>
struct romu192_random_t {
uint64_t xstate;
uint64_t ystate;
uint64_t zstate;
};
constexpr uint64_t romu64_random_r(romu192_random_t *rng) {
@Andersama
Andersama / table.h
Created March 19, 2021 19:42
A rough c like language transition table
#include <cstdint>
namespace lexer {
enum char_id : uint8_t {
c_start,
c_other = c_start,
c_zero,
c_one,
c_oct,
c_digit,
c_hex,
#pragma once
#if __has_include(<span>)
#include <span>
#else
#include "span.hpp"
namespace std {
using tcb::span;
}
#endif
#pragma once
#include <memory>
#include <functional>
#include <vector>
#include <string>
#include <compare>
#include <array>
#include <type_traits>
#include <intrin.h>
#include <immintrin.h>
#include <iostream>
#include <string>
#include <algorithm>
#include <deque>
#include <vector>
#include <array>
#include <set>
#include <thread>
#include <future>
#include <execution>
@Andersama
Andersama / regex_analysis.hpp
Last active October 3, 2019 05:26
compile time calculation of the least and most amount of characters a regex may match
#pragma once
//requires c++17
//see: https://github.com/hanickadot/compile-time-regular-expressions/blob/master/single-header/ctre.hpp
//specifically: https://github.com/hanickadot/compile-time-regular-expressions/blob/96de8f7a519b61abd4ef53ec37cd89565880aa50/single-header/ctre.hpp
#include <string_view>
#include "ctre.hpp"
namespace regex::analyzer {
//issues w/o unicode (regex fails to compile), these are the (?: .. etc patterns that change how a group capture functions
uniform float4x4 ViewProj;
uniform texture2d image;
uniform float elapsed_time;
uniform float2 uv_offset;
uniform float2 uv_scale;
uniform float2 uv_pixel_interval;
sampler_state textureSampler {
Filter = Linear;
#!/user/bin/python
import re, sys, getopt, os
def main(argv):
inputfile = ''
outputfile= ''
try:
opts, args = getopt.getopt(argv, "hi:o",["ifile=","ofile="])
except getopt.GetoptError:
duniform float4x4 ViewProj;
uniform texture2d image;
uniform float elapsed_time;
uniform float2 uv_offset;
uniform float2 uv_scale;
uniform float2 uv_pixel_interval;
sampler_state textureSampler {
Filter = Linear;