Skip to content

Instantly share code, notes, and snippets.

View midnight-wonderer's full-sized avatar

Sarun Rattanasiri midnight-wonderer

View GitHub Profile
@midnight-wonderer
midnight-wonderer / main.md
Created April 5, 2026 14:24
COBS Encoding

Consistent Overhead Byte Stuffing (COBS) is a clever way to prepare data for transmission so that a specific byte (usually 0x00) never appears in the message body, allowing it to be used reliably as a "end of packet" marker. Unlike traditional "escape-character" stuffing, which can double the size of your data in the worst case, COBS has a guaranteed maximum overhead of only 1 byte for every 254 bytes of data.

How COBS Encoding Works

COBS breaks your data into "code blocks." Each block starts with a code byte that tells the receiver how many bytes to skip to reach the next code byte.

Step-by-Step Process

  1. Append a "Phantom" Zero: Conceptually, treat the end of your data as if there is a zero byte there.
  2. Scan for Zeroes: Look at the first 254 bytes of your data.
cat /usr/lib/systemd/system/tor@default.service
@midnight-wonderer
midnight-wonderer / popular-domain-suggestion.ts
Created June 1, 2023 08:09
Email domain suggestion for typo prone user segments
@midnight-wonderer
midnight-wonderer / random_code.rb
Last active June 10, 2022 14:41
Random code with Ruby
# frozen_string_literal: true
require 'securerandom'
class RandomCode
class NotSupported < ::StandardError
end
class P_Single < ::StandardError
end
@midnight-wonderer
midnight-wonderer / README.md
Created October 5, 2021 08:04
How do I resolve the certificate expiration error that I receive when Lambda invokes dependencies for a Let's Encrypt certificate?

I get an SSL error when AWS Lambda invokes dependencies that use a Let's Encrypt certificate.

Short description

Some AWS Lambda .NET Core and Ruby runtimes are experiencing certificate errors due to an expired Let's Encrypt cross-signed DST Root CA X3. For compatibility purposes, Let's Encrypt certificates default to using a certificate chain that's cross-signed by the DST Root CA X3 certificate that expired on September 30, 2021. OpenSSL versions 1.0.2 and earlier return an error when one of the verification paths is invalid, which prevents the successful establishment of SSL/TLS connections.

The following resolution removes the expired CA from the CA bundle and forces the system to use the file provided by the layer instead of the file packaged with the base system. OpenSSL versions 1.0.2 and earlier are forced to validate Let's Encrypt certificates using the alternate path provided in the environment variables.

Important: The system's trust store is frequently updated to include new CA root cer

@midnight-wonderer
midnight-wonderer / README.md
Created October 4, 2021 14:55
BLAKE3 vs BLAKE2 for short input message

BLAKE3 vs BLAKE2 benchmark for short input

Observed result

blake3 : 335251.50 per second
blake2s: 715722.22 per second
blake2b: 663446.58 per second

Conclusion from the result

@midnight-wonderer
midnight-wonderer / note.txt
Last active February 22, 2022 03:50
Higher apt repo priority
path:
/etc/apt/preferences.d
command:
apt policy
apt-cache policy package-name
content:
Package: *
Pin: release o=RepoNameFromPolicyCommand
# start session
ssh-agent $SHELL
ssh-add ./destination-key
ssh -i ./intermediate-key -A -t user@intermediate.example.com ssh -A user@destination.example.com
@midnight-wonderer
midnight-wonderer / sudoers
Created June 30, 2020 01:01
Allow a user to run privilege commands
# Cmnd alias specification
Cmnd_Alias FIREWALL = /usr/sbin/ufw
# User privilege specification
username ALL=NOPASSWD: FIREWALL
@midnight-wonderer
midnight-wonderer / sigrok-checklist.md
Last active December 7, 2019 02:08
Sigrok checklist
  • Firmware in place
  • udev rules