Skip to content

Instantly share code, notes, and snippets.

View Tostino's full-sized avatar

Adam Brusselback Tostino

  • Retired, for now.
  • Tampa, FL
View GitHub Profile
@Tostino
Tostino / refresh_where.md
Last active April 17, 2026 01:23
Making Postgres materialized view refreshes O(delta) instead of O(total)

Making Postgres materialized view refreshes O(delta) instead of O(total)

Many developers assume PostgreSQL materialized views handle incremental updates out of the box. They do not. If you have a materialized view with millions of rows and a single underlying record changes, both native refresh options process the entire dataset.

Because of this limitation, anyone needing immediate maintenance or working with large datasets must abandon materialized views entirely. The standard workaround is to manually maintain a standard table using custom database triggers or application logic.

I've been working on a patch to fix this. It adds an optional WHERE clause to the REFRESH MATERIALIZED VIEW command, letting you scope a refresh to exactly the rows that changed. The patch is currently under review on the pgsql-hackers mailing list.

This approach requires two things. First, the materialized view must have a unique index (the same requirement as REFRESH MATERIALIZED VIEW ... CONCURRENTLY). Second, the

@Tostino
Tostino / demo.sql
Last active April 9, 2026 21:26
Postgres MV Partial Refresh Demo
-- demo.sql
-- Materialized view, triggers, and test cases.
-- Requires PostgreSQL with WHERE clause support on REFRESH MATERIALIZED VIEW.
-- Run setup.sql first.
----------------------------------------------------------------------
-- TEARDOWN: Clean slate for re-runnability
----------------------------------------------------------------------
-- 1. Drop the Materialized View (Cascade handles attached indexes)
DROP MATERIALIZED VIEW IF EXISTS invoice_totals CASCADE;
@Tostino
Tostino / inkbot-summary-of-summaries.txt
Last active March 22, 2026 08:56
Generate a summary-of-summaries prompt example
<#meta#>
- Date: 2023-10-05
- Task: summary
<#system#>
Your main objective is to condense the content of the document into a concise summary, capturing the main points and themes.
<#chat#>
<#user#>
To craft a Final Summary:
1. Read Summarized Sections: Carefully review all the summarized sections of the document. Ensure that you have a clear understanding of the main points, key details, and essential information presented in each section.
@Tostino
Tostino / inkbot-chunked-summary.txt
Last active March 22, 2026 08:55
Generate a chunked summary prompt example
<#meta#>
- Date: 2023-10-05
- Task: summary
<#system#>
Your main objective is to condense the content of the document into a concise summary, capturing the main points and themes.
<#chat#>
<#user#>
Please read the provided Original section to understand the context and content. Use this understanding to generate a summary of the Original section, incorporating relevant details and maintaining coherence with the Prior Summary.
Notes:
Dear Representative Bilirakis,
I am writing to you as a concerned constituent regarding recent developments at the Department of the Treasury. The reported situation with the Department of Government Efficiency (DOGE) having access to the Bureau of the Fiscal Service's payment systems raises grievous constitutional concerns about the separation of powers and Congress's fundamental role in our government.
This is not merely a technical matter of administrative access – it represents a fundamental threat to Congress's constitutional authority. The Bureau of the Fiscal Service controls the distribution of over $6 trillion in payments annually, including Social Security benefits, federal salaries, and other critical disbursements that Congress has specifically authorized. Allowing DOGE to access these payment systems effectively places a private organization between Congress and its constitutionally mandated power to direct federal spending, creating an unprecedented breach in the separation of powers that our
@Tostino
Tostino / inkbot_kg_2.txt
Last active February 1, 2025 09:37
Inkbot knowledge graph (2)
<#meta#>
- Date: 2023-05-16
- Task: kg
<#system#>
You are an AI assistant who will help the user with all their information requests.
<#chat#>
<#user#>
Your task is to construct a comprehensive Temporal Knowledge Graph
1. Read and understand the Document: Familiarize yourself with the essential elements, including (but not limited to) ideas, events, people, organizations, impacts, and key points, along with any explicitly mentioned or inferred dates or chronology
- Pretend the date found in 'Date' is the current date
@Tostino
Tostino / inkbot-one-shot.txt
Last active November 20, 2024 16:28
Generate a one-shot summary prompt example
<#meta#>
- Date: 2023-10-05
- Task: summary
<#system#>
Your main objective is to condense the content of the document into a concise summary, capturing the main points and themes.
<#chat#>
<#user#>
Please read the provided Original section to understand the context and content. Use this understanding to generate a summary of the Original section. Separate the article into chunks, and sequentially create a summary for each chunk. Focus on summarizing the Original section, ignoring any details about sponsorships/advertisements in the text.
Summarized Sections:
@Tostino
Tostino / summary-training-data.jsonl
Created November 14, 2024 05:29
summary_training_data
{"id": 8132, "part": 2, "prompt_date": "2016-10-22", "task": "summary", "system_prompt": "A user will share a document with you. Your task is to generate a brief summary that retains the core message and essence of the original content.", "instruction": "Please read the provided Original section to understand the context and content. Use this understanding to generate a summary of the Original section, incorporating relevant details and maintaining coherence with the Prior Summary.\n\nNotes:\n- The Prior Summary was created from the chunk of the document directly preceeding this chunk.\n- Ignore the details already included in the Prior Summary when creating the new Summary.\n- Focus on summarizing the Original section, taking into account the context provided by the Prior Summary.\n- Ignore any details about sponsorships/advertisements in the text.", "user_context": "Prior Summary:\nIn this episode of \"Out of the Trenches,\" Indy Neidell answers questions about the First World War. One viewer asks about the
@Tostino
Tostino / word_token_to_character_token.py
Last active September 20, 2024 20:02
Teach model to decompose word-level tokens into the constituant characters
import json
import random
import string
from typing import List, Dict, Tuple, Callable, Optional, Any
from dataclasses import dataclass, field
import logging
from collections import defaultdict, Counter
from typing import Tuple
from sentence_transformers import SentenceTransformer
import faiss
@Tostino
Tostino / questions_opportunity_ai.md
Last active August 23, 2024 14:58
Questions for opportunity.ai

Questions for opportunity.ai Interview

Relationship with brainstems.ai

  • What is the exact nature of your relationship with brainstems.ai? Are you a subsidiary, partner, or customer?
  • How does brainstems.ai's blockchain and ML technology specifically apply to your food service solutions?
  • To what extent are you dependent on brainstems.ai for your core technology and operations?

Technology and Implementation

  • Can you provide a detailed explanation of how your ML models work in the context of food service optimization?
  • How do you gather and process data from various stakeholders (manufacturers, operators, brokers, distributors) while ensuring data isolation and privacy?