Skip to content

Instantly share code, notes, and snippets.

@joelonsql
joelonsql / meson-rerun-failed-tests.py
Created October 28, 2024 20:05
Script that reruns failed PostgreSQL Meson tests and, if they pass, executes the full test suite.
#!/usr/bin/env python3
import json
import subprocess
import sys
from pathlib import Path
def run_meson_tests(test_names=None, meson_args=None):
"""Run meson tests with the given test names and arguments"""
if meson_args is None:
@joelonsql
joelonsql / Telegram vs Signal.md
Last active August 26, 2024 17:47
Comparison of Telegram vs Signal

Telegram vs Signal

The table highlights key differences between Telegram and Signal, especially in terms of security and privacy.

Feature Telegram Signal
1. End-to-end encrypt conversations by default
2. Uses a standard authenticated encryption mode
3. Encrypted group chats
@joelonsql
joelonsql / half_karatsuba.md
Created April 16, 2024 17:34
The Half-Karatsuba Multiplication Algorithm

Karatsuba Multiplication for factors with significant length disparity.

The Half-Karatsuba Multiplication Algorithm is a specialized case of the normal Karatsuba multiplication algorithm, designed for the scenario where var2 has at least twice as many base digits as var1.

In this case var2 (the longer input) is split into high2 and low1, at m2 (half the length of var2) and var1 (the shorter input), is used directly without splitting.

@joelonsql
joelonsql / enhance_rust_rfcs_with_a_minimal_but_realistic_code_example.md
Created August 30, 2023 12:57
Enhance Rust RFCs with a Minimal but Realistic Code Example

Enhance Rust RFCs with a Minimal but Realistic Code Example

Imagine opening a Rust RFC and, right at the top, before any detailed discussion or jargon kicks in, you're met with a small, relatable code example. This snippet isn't just for show; it clearly demonstrates the existing problem, pinpoints why the current approach feels cumbersome or inelegant, and showcases the elegance introduced by the RFC's proposal.

The Idea: Start every Rust RFC with a succinct real-life code example. This example would:

  1. Spotlight the Issue: Directly show what’s problematic in the current system.
@joelonsql
joelonsql / 0243-trait-based-exception-handling.md
Last active August 30, 2023 13:00
0243-trait-based-exception-handling.md with added Illustrative Example
@joelonsql
joelonsql / flashback_logging.md
Created August 18, 2023 07:14
Flashback Logging

Flashback Logging

NOTE: Post-writing, I discovered a similar concept named Ring Buffer Logging. What sets Flashback Logging apart is its approach to handling the buffer. When a log event matches the standard log level threshold, such as 'INFO', the buffer is cleared. This behavior is based on the rationale that such a log event indicates the system's return to normal operations, eliminating the need to keep previously buffered entries.

Introduction

Flashback Logging is a design pattern in the logging and debugging domain. Its primary goal is to reduce the time spent on debugging by making verbose logs readily available during error occurrences without the storage overhead of always keeping verbose logs.

@joelonsql
joelonsql / etalon.c
Created March 21, 2023 10:10
ETALON v1.0 - The ultimate tool for achieving maximum productivity!
/*
* ETALON v1.0
*
* Introducing Elon's Estimator: ETALON
*
* The ultimate tool for achieving maximum productivity!
*
* With just a single command, you can now estimate the completion date of your
* next big project, just like Elon himself. Say goodbye to endless project
* planning and hello to efficiency!
@joelonsql
joelonsql / 0005-fixed-buf.patch
Last active February 20, 2023 21:49
0005-fixed-buf.patch
diff --git a/src/backend/utils/adt/numeric.c b/src/backend/utils/adt/numeric.c
index a83feea396..dea55847fd 100644
--- a/src/backend/utils/adt/numeric.c
+++ b/src/backend/utils/adt/numeric.c
@@ -301,6 +301,7 @@ struct NumericData
* This is feasible because the digit buffer is separate from the variable.
* ----------
*/
+#define FIXED_BUF_LEN 8
typedef struct NumericVar
@joelonsql
joelonsql / numeric_from_bytes.sql
Created January 23, 2023 19:20
Function to convert non-negative integer represented as a byte array in big-endian order to numeric
CREATE OR REPLACE FUNCTION numeric_from_bytes(bytea)
RETURNS numeric
LANGUAGE plpgsql
AS $$
declare
bits bit varying;
result numeric := 0;
exponent numeric := 0;
bit_pos integer;
begin
@joelonsql
joelonsql / create_or_lookup_function.sql
Last active January 13, 2023 16:41
Content-Addressed Functions in PostgreSQL
--
-- Content-Addressed Functions
--
-- Inspired by Unison's concept of using a hash of a function's syntax tree
-- as its name, sometimes referred to as "content-addressed naming",
-- we can avoid the need to create/drop lots of different temp function,
-- by using the hash of its definition as its name,
-- and simply reuse the function for all tests that need the same function.
--
-- While Unison uses 512-bit SHA3, we use sha224() since the maximum length