Skip to content

Instantly share code, notes, and snippets.

View assyrianic's full-sized avatar
💻
CompEng courses

Kevin Yonan assyrianic

💻
CompEng courses
View GitHub Profile
@assyrianic
assyrianic / parsetargetpath.sp
Created November 16, 2019 19:40
parses a target path
public bool ParseTargetPath(const char[] key, char[] buffer, int buffer_len)
{
/// parse something like: "root.section1.section2.section3.\\..dotsection"
int i = strlen(key) - 1;
while( i > 0 ) {
/// Patch: allow keys to use dot without interfering with dot path.
/// check if we hit a dot.
if( key[i]=='.' ) {
/// if we hit a dot, check if the previous char is an "escape" char.
if( key[i-1]=='\\' )
@assyrianic
assyrianic / lexing_tools.c
Last active November 20, 2019 15:54
a few code to help lexing.
static bool is_alphabetic(const int c)
{
return( (c>='a' && c<='z') || (c>='A' && c<='Z') || c=='_' || c=='$' || c=='@' || c < -1 );
}
static bool is_possible_id(const int c)
{
return( is_alphabetic(c) || (c>='0' && c<='9') );
}
@assyrianic
assyrianic / recalloc.h
Last active January 14, 2024 18:13
realloc that works like calloc.
/**
recalloc
Copyright 2020 Kevin Yonan aka Nergal
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOF
@assyrianic
assyrianic / deque.go
Last active August 28, 2023 16:34
implements an array-based deque
/*
* Author: Kevin Yonan
* License: MIT
*/
package deque
type (
QNode[T any] struct {
Next, Prev int
@assyrianic
assyrianic / interface_size.go
Last active June 14, 2021 17:13
getting the type size of an interface
package main
import (
"fmt"
"unsafe"
)
type (
any interface{}
ptr unsafe.Pointer
goIface struct {
@assyrianic
assyrianic / ordmap.hpp
Created July 14, 2021 03:00
cache friendly, order-preserving hash table.
/**
* ordered map for SourcePawn.
* Author: Kevin Yonan, (C) 2021.
* License: MIT
*/
#ifndef ORDMAP_INCLUDED
# define ORDMAP_INCLUDED
#include <inttypes.h>
@assyrianic
assyrianic / flat_string.c
Last active November 11, 2023 19:17
packs an "array" of strings into a flattened string "array" with supporting offset array to get each string.
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <stdarg.h>
/**
* returns a string that contains multiple strings.
* 'offsets' is used to store the offset of each string.
* 'len' is the number of strings and offsets written.
*/
/// Bresenham's algorithm in simplistic C
void drawline(int const x0, int const y0, int const x1, int const y1) {
int const dx = x1 - x0;
int const dy = y1 - y0;
int p = 2 * dy - dx;
for( int x = x0, y = y0; x < x1; x++ ) {
if( p >= 0 ) {
putpixel(x, y, 7);
y++;
p += 2 * dy - 2 * dx;
#ifndef BITSTACK_INCLUDED
# define BITSTACK_INCLUDED
#ifdef __cplusplus
extern "C" {
#endif
#include <stdio.h>
#include <stdbool.h>
#include <inttypes.h>
@assyrianic
assyrianic / errdiagnostic.go
Last active May 16, 2023 17:03
Recreates Rust's Compiler Error reporting style in Golang.
// colorful strings for printing.
const (
COLOR_RED = "\x1B[31m" // used for errors.
COLOR_GREEN = "\x1B[32m"
COLOR_YELLOW = "\x1B[33m"
COLOR_BLUE = "\x1B[34m"
COLOR_MAGENTA = "\x1B[35m" // used for warnings.
COLOR_CYAN = "\x1B[36m"
COLOR_WHITE = "\x1B[37m"
COLOR_RESET = "\033[0m" // used to reset the color.