Skip to content

Instantly share code, notes, and snippets.

View Konamiman's full-sized avatar

Néstor Soriano Konamiman

View GitHub Profile
@Konamiman
Konamiman / chgcount.sh
Created November 7, 2025 12:00
Count git changed and deleted lines in the working tree or in the staged files
#!/bin/bash
# chgcount.sh - Count lines added/modified and deleted in git diff
#
# Usage: chgcount.sh [OPTIONS]
#
# Options:
# -p, --pattern PATTERN File pattern to check (default: all files)
# Use **/ prefix for recursive matching in subdirectories
# -f, --files FILES Explicit space-separated list of files to check
@Konamiman
Konamiman / object-cache.php
Created October 28, 2025 14:27
Simple file-based persistent object cache for WordPress. For testing scenarios only.
<?php
/**
* Simple file-based WordPress object cache implementation.
*
* Drop this file in wp-content/ to enable persistent object caching.
* Each cache group stores its data in a separate file using PHP serialization.
* Files will go in WP_CONTENT_DIR . '/cache/object-cache', or if
* no WP_CONTENT_DIR constant is defined, in '/tmp/wp-object-cache'.
*
* This file is provided as-is without warranty of any kind.
@Konamiman
Konamiman / woo-worktrees.sh
Last active October 28, 2025 10:09
A script to easily handle multiple WooCommerce branches using git worktrees
#!/bin/bash
# WooCommerce Worktree Management Script
# By Konamiman (and Claude)
# This script is provided as-is without warranty of any kind.
# It's not officially supported by WooCommerce or Automattic.
# Hint: add it to your ~/.bashrc or equivalent:
# alias wwt='~/woo-worktrees.sh'
@Konamiman
Konamiman / apply_diff.php
Last active May 29, 2025 13:57
PHP function to apply a diff
<?php
/**
* Apply a diff to a text composed of multiple lines.
*
* The diff is expected to be in unified format (https://www.gnu.org/software/diffutils/manual/html_node/Unified-Format.html)
* but for a single file (so there are no file names and the first line starts with "@@" already).
*
* The approach followed is probably not the most efficient possible, but the code is small and gets the job done.
*
@Konamiman
Konamiman / Example.cs
Last active August 3, 2024 14:19
TLS 1.3 key derivation in C#
using System;
using System.Globalization;
using System.Linq;
using System.Numerics;
using System.Security.Cryptography;
class Example
{
public static void Main()
{
@Konamiman
Konamiman / .Z80 relocatable file parser.md
Last active January 26, 2023 16:18
Parser for Z80 relocatable files (generated by M80.COM, processed by L80.COM)

This program will parse and print the structure of a relocatable (.REL) Z80 code file generated with the Macro80 assembler (M80.COM) and processable with Link80 (L80.COM). See ParseRel.cs for build instructions.

More information on Macro80/Link80 and the .REL format: http://www.msxarchive.nl/pub/msx/programming/asm/m80l80.txt

@Konamiman
Konamiman / CH376 connected to Z80.md
Created August 21, 2021 16:35
"Recipe" to connect a CH376 to a Z80 via I/O port

How to connect a CH376 to a Z80 via I/O ports 20h and 21h (compatible with Rookie Drive):

Z80 74HC688 CH376
5V 5V 5V
GND GND GND
D7...D0 D7...D0
RD RD
WR WR
A0 A0
/**
* Skeleton for a USB device implementation with a CH372/375/376.
*
* No real device functionality is implemented,
* only the standard USB requests over the control endpoint.
*/
#include "constants.h"
@Konamiman
Konamiman / Nextor-v3-driver-migration-guide.md
Last active August 5, 2020 20:49
Nextor v3 driver structure proposal

Nextor v3 driver migration guide

This guide explains how to migrate a Nextor driver from v2 to v3. The reader is expected to have experience with Nextor v2 driver development.

Only the changes relative to the structure of the driver for v2 are mentioned here. You can see the skeleton for a full v3 driver in the Nextor-v3-driver.asm in this same gist, and the skeleton for a full v2 driver in the Nextor repository.

1. Change the hardcoded flags (DRV_FLAGS, 410Eh)

The driver flags byte needs to be changed to the fixed value 83h. Bit 7 indicates that the driver is a v3 driver, bits 0 and 1 need to be set for consistency with the meaning they had in Nextor v2.

@Konamiman
Konamiman / How to build stunnel for Raspberry Pi.md
Last active March 27, 2021 03:25
How to build stunnel for Raspberry Pi

How to build stunnel for Raspberry Pi

This document explains how to stunnel for the Raspberry Pi (or more precisely, for the ARM architecture). All the information here has been gathered, and adapted where needed, from these blog posts: "Cross compiling for ARM with Ubuntu 16.04 LTS" and "Cross-compile OpenSSL for your Raspberry Pi". I needed to do that in order to be able to use my Raspberry Pi to provide Internet via WiFi for my Ethernet-only MSX. The OS I used as the building host is Linux Mint 18.3.

This is just a concise recipe and I'm not going to explain the details, feel free to take a look at the linked blog posts for more information.

First we are going to create a temporary directory for all the dirty work.

cd ~/