Skip to content

Instantly share code, notes, and snippets.

@joelonsql
joelonsql / PostgreSQL-EXTENSIONs.md
Last active May 4, 2024 15:47
1000+ PostgreSQL EXTENSIONs

🗺🐘 1000+ PostgreSQL EXTENSIONs

This is a list of URLs to PostgreSQL EXTENSION repos, listed in alphabetical order of parent repo, with active forks listed under each parent.

⭐️ >= 10 stars
⭐️⭐️ >= 100 stars
⭐️⭐️⭐️ >= 1000 stars
Numbers of stars might not be up-to-date.

@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 / decode_cbor.sql
Last active January 13, 2024 04:36
Decode WebAuthn CBOR Using PostgreSQL Recursive CTE
CREATE OR REPLACE FUNCTION decode_cbor(cbor bytea)
RETURNS TABLE (
item integer,
map_item_count integer,
text_string text,
bytes bytea
)
LANGUAGE sql
AS $$
/*
@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 / hyperloglog-demo.sql
Created June 2, 2021 08:55
HyperLogLog demo
--
-- Here comes some general advise on how to use HyperLogLog
-- for someone who wants to implement a YouTube-like service
-- using the awesome https://github.com/citusdata/postgresql-hll PostgreSQL extension
--
CREATE TABLE counter (
id text NOT NULL,
sketch hll NOT NULL DEFAULT hll_empty(),
PRIMARY KEY (id)
@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 / JOIN FOREIGN.md
Last active February 8, 2023 23:29
SQL language proposal: JOIN FOREIGN

SQL language proposal: JOIN FOREIGN

The idea is to improve the SQL language, specifically the join syntax, for the special but common case when joining on foreign key columns.

The problem

Example below taken from PostgreSQL documentation [1]

In SQL-89, we didn't have any JOIN syntax yet, so queries were written in this way: