Skip to content

Instantly share code, notes, and snippets.

View DavidEGrayson's full-sized avatar

David Grayson DavidEGrayson

View GitHub Profile
@DavidEGrayson
DavidEGrayson / test_vsnprintf.c
Last active February 9, 2024 21:46
Quick test of vsnprintf to make sure it is standards-compliant
// This is a small C program that tests your version of vsnprintf to see if it is
// compliant with the C99 standard.
//
// The script gives successful results (compliant vsnprintf) on these environments:
// - MSYS2's MINGW64 environment (GCC 13.2.0)
//
// I also expect successful results on Linux, macOS and modern UCRT-based environments
// provided by Microsoft.
//
// From the MSDN documentation of vsnprintf:
@DavidEGrayson
DavidEGrayson / rp2040_msys2.md
Last active September 12, 2023 04:53
Building and debugging RP2040 firmware in Windows with MSYS2 + GCC + GDB + OpenOCD + PicoProbe + SWD

This is an opinionated tutorial that shows you how to set up a development environment for the RP2040 on Windows using only open source tools. You should start at the beginning of this tutorial, but you don't have to follow ALL of the instructions: you can stop after completing any level and leave with something that is useful.

Level 0: Set up MSYS2

Download and install [MSYS2], the best system for developing open source software on Windows.

Use "Edit environment variables for your account" in the Windows Control Panel to add an environment variable for your user named HOME with a value like C:\Users\david (but with david replaced by your actual Windows user name). Do NOT add an extra slash on the end. MSYS2 uses this variable to determine where your home directory is. If you don't set it, MSYS2 defaults to using a home directory like /home/USERNAME which actually lives inside the MSYS2 installation. That is not your true home directory, and you shouldn't get in the habit of storing files t

Submodule URL

There are three locations where git keeps track of submodule URL:

  1. .gitmodules - This is a regular file that is committed in the repository.
  2. .git/config
  3. .git/modules/somepath/config
These commands have an effect on the three URLs:

@DavidEGrayson
DavidEGrayson / advent.rb
Created December 22, 2022 07:00
Advent of code 2022 Day 22
map = ['']
instructions = []
File.foreach('input.txt') do |line|
md = line.match(/\d/)
if md
line.scan(/(\d+|R|L)/) do |m|
if 'LR'.include?(m[0])
instructions << m[0].to_sym
else
instructions << m[0].to_i
@DavidEGrayson
DavidEGrayson / advent.rb
Created December 21, 2022 06:36
Advent of code 2022 Day 20 Part 2
$input = {}
File.foreach('input.txt') do |line|
if md = line.match(/(\w+): (\d+)/)
$input[md[1].to_sym] = md[2].to_i
elsif md = line.match(/(\w+): (\w+) (.) (\w+)/)
$input[md[1].to_sym] = [md[3].to_sym, md[2].to_sym, md[4].to_sym]
else
$stderr.puts "Unrecognized line: #{line}"
exit 1
end
@DavidEGrayson
DavidEGrayson / advent.rb
Last active December 15, 2022 04:55
Advent of Code 2022 Day 14: Falling sand (using recursion)
$width = 1000
$height = 200
$world = (' ' * $width + "\n") * $height
def coords_in_bounds?(coords)
(0...$width).include?(coords[0]) && (0...$height).include?(coords[1])
end
def read(coords)
raise if !coords_in_bounds?(coords)
@DavidEGrayson
DavidEGrayson / vscode_config_from_gcc_command.rb
Created September 12, 2022 22:20
Convert GCC command in VSCode configuration
#!/usr/bin/ruby
# Takes a command line for GCC (or similar) on as a file or on its
# standard input, extracts the preprocessor macros defined and the
# include paths, and outputs them in a format suitable for
# pasting into c_cpp_properties.json so that VSCode can understand
# your C/C++ project better.
require 'json'
input = ARGF.read
@DavidEGrayson
DavidEGrayson / gcc-11-arm-darwin.patch
Created June 11, 2021 21:57
GCC 11 patch for ARM darwin
diff -ur gcc-11.1.0/gcc/config/host-darwin.c gcc-11.1.0-fixed/gcc/config/host-darwin.c
--- gcc-11.1.0/gcc/config/host-darwin.c 2021-04-27 03:00:13.000000000 -0700
+++ gcc-11.1.0-fixed/gcc/config/host-darwin.c 2021-06-11 14:49:13.754000000 -0700
@@ -22,6 +22,10 @@
#include "coretypes.h"
#include "diagnostic-core.h"
#include "config/host-darwin.h"
+#include "hosthooks.h"
+#include "hosthooks-def.h"
+
diff --git a/code/15_hello_triangle.cpp b/code/15_hello_triangle.cpp
index 532520e..31f2bd7 100644
--- a/code/15_hello_triangle.cpp
+++ b/code/15_hello_triangle.cpp
@@ -642,12 +642,15 @@ private:
void drawFrame() {
vkWaitForFences(device, 1, &inFlightFences[currentFrame], VK_TRUE, UINT64_MAX);
+ VkFence waited = inFlightFences[currentFrame];
@DavidEGrayson
DavidEGrayson / bad.c
Created February 26, 2021 03:41
Test code for Vulkan loader issues in MSYS2
// Compile with: gcc -g bad.c -lvulkan -lgdi32 -lglfw3
#define VK_USE_PLATFORM_WIN32_KHR
#include <vulkan/vulkan.h>
#define GLFW_EXPOSE_NATIVE_WIN32
#include <GLFW/glfw3.h>
#include <GLFW/glfw3native.h>
#include <string.h>
#include <stdlib.h>