Skip to content

Instantly share code, notes, and snippets.

@MadLittleMods
MadLittleMods / reverse-iterate.zig
Created November 4, 2023 06:38
Reverse iterate over a array/list in Zig
const std = @import("std");
pub fn main() void {
var list = [_]u8{ 1, 2, 3, 4, 5, 6, 7, 8, 9 };
// `i = i -% 1` is wrapping subtraction.
// `i -%= 1`
var i: u32 = list.len - 1;
while (i < list.len) : (i -%= 1) {
std.log.debug("i: {d} list[{d}] -> {d}", .{ i, i, list[i] });
@MadLittleMods
MadLittleMods / split-long-string-across-multiple-lines.zig
Last active October 13, 2023 01:35
Break-up long string across multiple lines in Zig (combine strings)
const std = @import("std");
// See "a ++ b" in the Zig docs: https://ziglang.org/documentation/master/#Operators
pub fn main() void {
std.log.debug(
"We can split up a really long string across multiple lines in Zig using " ++
"the ++ operator which works on comptime known arrays. Since comptime " ++
"strings look like `[100:0]const u8` indicating a null terminated array of " ++
"integers that is 100 characters long, this works just fine.",
.{},
const std = @import("std");
const expect = std.testing.expect;
const expectEqual = std.testing.expectEqual;
const expectEqualSlices = std.testing.expectEqualSlices;
// Tested with Zig 0.11.0
// `zig run x11-flexible-array-member-parsing.zig`
// This is a barebones example from zigx and the code to parse the connection setup buffer,
// https://github.com/marler8997/zigx/blob/a313162bdac3182c7fc38a31dfa952c68ff861f9/x.zig#L2386-L2481
@MadLittleMods
MadLittleMods / write_log.txt
Last active August 9, 2023 07:07
Example log for https://github.com/MadLittleMods/vga-simulator - Log format: `current_sim_time time_units: hs vs red green blue`
This file has been truncated, but you can view the full file.
10 ns: U U UUU UUU UU
30 ns: U U UUU UUU UU
50 ns: 1 1 000 000 00
70 ns: 1 1 000 000 00
90 ns: 1 1 000 000 00
110 ns: 1 1 000 000 00
130 ns: 1 1 000 000 00
150 ns: 1 1 000 000 00
170 ns: 1 1 000 000 00
190 ns: 1 1 000 000 00
@MadLittleMods
MadLittleMods / fix-hallmark-card-studio-on-windows-10.md
Last active December 23, 2022 04:48
Fix Hallmark Card Studio failing to launch on Windows 10 - Exception: Unable to load the native components of SQL Server Compact

Problem

If you have an old version of Hallmark Card Studio and recently upgraded to Windows 10, you might be running into the following error when launching the program. The specific program I ran into this with was Hallmark Home Card Studio version 22/hcs.

A problem was encountered accessing the SQL database. Exception: Unable to load the native components of SQL Server Compact corresponding to the ADO.NET provider of version 8080. Install the correct version of SQL Server Compact. Refer to KB article 974247 for more details

@MadLittleMods
MadLittleMods / oc-cross-project-logs.md
Created September 1, 2022 18:49
View logs across projects in Red Hat OpenShift

With Red Hat OpenShift, here's how to view logs of a pod in a different project than the one currently active:

oc logs -n <project> <pod>

Option as documented but obscure and hard to follow because the option is namespace but oc always references them as projects everywhere else:

@MadLittleMods
MadLittleMods / sort-google-photos-dump.md
Last active July 29, 2022 03:08
Fix photos sorted in maddening wrong order by date

Problem

We were dealing with an out of order dump of photos from a Google photos album and wanting to upload to Facebook. It consisted of jpg and heic photos from a iPhone 8 and Pixel 4a so the metadata was different.

Sorting by Date Created in the macOS finder was out of order and Facebook seemed to sort in the same way. It didn't make any sense because we were seeing 4:55am photos sorted below 4:56pm photos (same day). Regardless of Italian timezone, they shouldn't be sorting like that (it's only GMT+2 vs my local GMT-6) which is an 8 hour difference compared the 12 hour difference shown in the photo date/times. Even looking at the exif metadata, it didn't make any sense what it was pulling from to make it sort that way.

Solution

This uses exiftool to read and do the file manipulation.

@MadLittleMods
MadLittleMods / golang-escape-forward-slash-in-test-name.md
Last active November 5, 2021 21:13
Golang: Escape forward slash in test name when using `-run` regex

How to escape a forward slash in a test name when using -run to run a single Go test?

I don't think it's possible. The following are some other articles/blog posts reiterating this point.

The key seems to just not use any forward slashes in test names so you can target them individually no matter what.

Go Subtest Tips by Frew Schmidt