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 / ffmpeg_commands.sh
Last active October 5, 2023 16:15
ffmpeg commands to extract AAC audio from an MP4, edit it, and replace it
ffprobe foo.mp4 # Make sure the audio stream is aac.
ffmpeg -i foo.mp4 -vn -acodec copy foo.aac
ffmpeg -i foo.aac -acodec pcm_s16le foo.wav
# Edit foo.wav with audacity, save to foo_edited.wav.
ffmpeg -i foo_edited.wav -acodec aac foo_edited.aac
ffmpeg -i foo.mp4 -codec copy -an foo_silent.mp4
ffmpeg -i foo_silent.mp4 -i foo_edited.aac -shortest -c:v copy -c:a aac foo_edited.mp4
# Reduce file size and remove sounds
ffmpeg -i foo.mp4 -vcodec libx264 -crf 28 -an foo_out.mp4
@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

@DavidEGrayson
DavidEGrayson / serial.c
Last active July 22, 2023 14:25
Simple Windows C program that connects to a serial port and prints out events from it, such as ring signals.
// Lots of code was copied from https://msdn.microsoft.com/en-us/library/ff802693.aspx#serial_topic3
#include <assert.h>
#include <windows.h>
#include <stdio.h>
#include <stdbool.h>
void ReportStatusEvent(HANDLE port, DWORD s)
{
printf("event 0x%lx", s);

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 / README.md
Last active October 24, 2022 14:55
Getting started with midipix
@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