This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
///usr/bin/env ccache gcc -Wall -Wextra -Werror -O3 -std=gnu17 "$0" -o /tmp/a -lm && /tmp/a "$@"; exit | |
#include <stdint.h> | |
#include <stdio.h> | |
/* | |
Self Describing Error Code Enum Macro (Or other status tracking variables) V2 | |
Author: Brian Khuu (2024) | |
This is an idea I got for easier management of error codes and other enums. | |
The benefit of this approach is that it provides a way of having self |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* | |
Self Describing Error Code Enum Macro (Or other status tracking variables) In C | |
Author: Brian Khuu (2024) | |
This is an idea I got for easier management of error codes and other enums. | |
The benefit of this approach is that it provides a way of having self | |
documenting enumerated values which would be useful for debug loggers. | |
Ergo, your debug log could print the meaning of an error or status message. | |
*/ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/tcc -run | |
// Bounded Value Macros (Useful for guarding against invalid integer ranges) | |
#define clamp_upper(value, max) ((value) < (max) ? (value) : (max)) | |
#define clamp_lower(value, min) ((value) > (min) ? (value) : (min)) | |
#define clamp_range(value, min, max) clamp_lower(min, clamp_upper(value, max)) | |
#define is_above_bound(value, max) ((value) > (max)) | |
#define is_below_bound(value, min) ((value) < (min)) | |
#define is_within_bound(value, min, max) ((value) >= (min) && (value) <= (max)) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# GNU Make 4.3 | |
# Built for x86_64-pc-linux-gnu | |
# Copyright (C) 1988-2020 Free Software Foundation, Inc. | |
# License GPLv3+: GNU GPL version 3 or later <http://gnu.org/licenses/gpl.html> | |
# This is free software: you are free to change and redistribute it. | |
# There is NO WARRANTY, to the extent permitted by law. | |
# Make data base, printed on Sun Oct 27 22:42:28 2024 | |
# Variables |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env python3 | |
# KiCADv8 Style Prettify S-Expression Formatter (sexp formatter) | |
# By Brian Khuu, 2024 | |
# This script reformats KiCad-like S-expressions to match a specific formatting style. | |
# Note: This script modifies formatting only; it does not perform linting or validation. | |
# Context: Compact element settings are added to support KiCAD-specific handling for readability, e.g., PCB_PLUGIN::formatPolyPts. | |
import os | |
import argparse | |
from pathlib import Path |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env python3 | |
# digikey_api_v4_product_search.py | |
# Digikey Basic Product Search Script (Targeting Digikey API v4) | |
# By Brian Khuu 2024 | |
# This is a digikey api v4 script that is focused only on just the flow needed to get product information. | |
# Recommend Reading: | |
# - https://developer.digikey.com/documentation | |
# - Section "OAuth 20: 2 Legged Flow" has good information on basic authnetic |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env python3 | |
# Autogenerated Documentation For Justfiles | |
# This was created to support this issue ticket https://github.com/casey/just/issues/2033#issuecomment-2278336973 | |
import json | |
import subprocess | |
from typing import Any | |
# just --dump --dump-format json --unstable | jq > test.json | |
json_output = subprocess.run( | |
["just", "--dump", "--dump-format", "json", "--unstable"], |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def escape_markdown_inline_code(value_string): | |
# Find the longest contiguous sequence of backticks in the string then | |
# wrap string with appropriate number of backticks required to escape it | |
max_backticks = max((len(match.group(0)) for match in re.finditer(r'`+', value_string)), default=0) | |
inline_code_marker = '`' * (max_backticks + 1) | |
# If the string starts or ends with a backtick, add a space at the beginning and end | |
if value_string.startswith('`') or value_string.endswith('`'): | |
value_string = f" {value_string} " |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Usage: generate_markdown_toc "AS 3000-2018 Wiring Rules.pdf" 3 | |
generate_markdown_toc() { | |
local pdf_file="$1" | |
local max_level="$2" | |
pdftk "$pdf_file" dump_data | awk -v max_level="$max_level" '/BookmarkTitle:/ {gsub("BookmarkTitle: ", ""); title=$0} /BookmarkPageNumber:/ {gsub("BookmarkPageNumber: ", ""); page=$0} /BookmarkLevel:/ {gsub("BookmarkLevel: ", ""); level=$0; if (level <= max_level) printf("%s- [ ] %s (Page %s)\n", sprintf("%" level*2 "s", ""), title, page)}' | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <stdio.h> | |
#include <string.h> | |
char *strtok_escaped(char *str, const char *delim) { | |
// Tokenise a string from a single char deliminator | |
// (strtok can deal with a deliminator string but for my purpose of splitting a psv table I only need one char) | |
// (There are better ways to optimise this, but just wanted something to work for now) | |
// https://gist.github.com/mofosyne/81c94740c0f33259606afa823562914c | |
static char *last_token_end = NULL; |
NewerOlder