Skip to content

Instantly share code, notes, and snippets.

View pmttavara's full-sized avatar

Phillip Trudeau pmttavara

View GitHub Profile
@pmttavara
pmttavara / parsing.cpp
Created July 18, 2022 02:51
Very slow (300 MB/s) syntax highlighter for C++ - WIP from 2019; pulled verbatim from Eden text editor (dead project)
#include "parsing.h"
#include "buffer.h"
#include <ch_stl/time.h>
namespace parsing {
// This is a column-reduction table to map 128 ASCII values to a 11-input space.
// The values in this table are premultiplied with the number of DFA states
// to save one multiply when indexing the state transition table.
#define P (DFA_NUM_STATES)
static const u8 char_type[] = {
@pmttavara
pmttavara / static_site_generator.cpp
Created August 13, 2022 04:06
Static website generator in C++ used to create https://philliptrudeau.com
#include <stdio.h>
#include <stdint.h>
#include <stdlib.h>
#include <assert.h>
#include <string.h>
#include <ctype.h>
#include <stdarg.h>
//template <class F> struct deferrer { F f; ~deferrer() { f(); } };
//struct defer_dummy {};
@pmttavara
pmttavara / tscqpc.h
Last active December 27, 2023 07:55
Obtain RDTSC frequency on Win32 and Linux
// SPDX-FileCopyrightText: © 2022 Phillip Trudeau-Tavara <pmttavara@protonmail.com>
// SPDX-License-Identifier: 0BSD
// https://hero.handmade.network/forums/code-discussion/t/7485-queryperformancefrequency_returning_10mhz_bug/2
// https://learn.microsoft.com/en-us/virtualization/hyper-v-on-windows/tlfs/timers#partition-reference-tsc-mechanism
#include <stdbool.h>
#include <stdint.h>
#define WIN32_LEAN_AND_MEAN
@pmttavara
pmttavara / _readme.md
Last active January 6, 2024 12:41
Spall auto-tracing for MSVC (_penter/_pexit) or Clang (__cyg_profile_func_enter/__cyg_profile_func_exit)
@pmttavara
pmttavara / console_belongs_to_self.c
Last active December 24, 2022 06:25
Check whether the console is owned by the current process in Win32
static bool terminal_belongs_to_self(void) {
DWORD pid = 0; GetWindowThreadProcessId(GetConsoleWindow(), &pid);
return pid == GetCurrentProcessId();
}