Skip to content

Instantly share code, notes, and snippets.

@ejrh
ejrh / words.txt
Created May 25, 2023 22:56
Python to find sequence of words from long to short, removing 1 letter each time
# From http://www.mieliestronk.com/wordlist.html
aardvark
aardwolf
aaron
aback
abacus
abaft
abalone
abandon
abandoned
@ejrh
ejrh / soma.py
Created May 25, 2023 22:54
Python to generate pieces of Soma cube puzzle (WIP)
DIMENSIONS = 2
SCALE = 3
OUTER_SCALE = SCALE + 2
STEPS = tuple(OUTER_SCALE**x for x in reversed(range(DIMENSIONS)))
def generate_all_cells():
def do_slice(offset, depth):
if depth == DIMENSIONS - 1:
for i in range(1, SCALE + 1):
yield offset + i
@ejrh
ejrh / bloat.sql
Last active May 4, 2023 05:22
PostgreSQL bloat report
with v as (select version() as ver),
constants(relkind, block_size, header_size, max_align, fill_factor, nonleaf_fill_factor, page_overhead, row_overhead) as (
values (
'r',
current_setting('block_size'),
CASE WHEN SUBSTRING((select ver from v),12,3) IN ('8.0','8.1','8.2') then 28 else 24 end,
CASE WHEN (select ver from v) ~ 'mingw32|64' THEN 8 ELSE 4 end,
1.0,
null,
32,
@ejrh
ejrh / busplan.py
Last active November 24, 2021 01:15
import itertools
import math
import random
import time
DEPENDENCIES = {
'wires': {'copper'},
'green circuits': {'iron', 'wires'},
'red circuits': {'plastic', 'wires', 'green circuits'},
WITH RECURSIVE t AS
(
SELECT id, '{}'::int[] AS parents, 0 AS level
FROM z_msg WHERE in_reply_to IS NULL
UNION ALL
SELECT c.id, parents || c.in_reply_to, level+1
FROM t JOIN z_msg AS s c ON t.id = c.in_reply_to
),
t2 AS
@ejrh
ejrh / chocolate-bread.txt
Created December 18, 2016 09:47
Grandma's chocolate bread
04/09/2013
2 cups of flour, sifted with:
1/2 teaspoon salt
1 heaped tablespoon cocoa
1 level teaspoon baking powder
1 level tspn soda
Put in blender 1 cup dates (check for stones),
#include <boost/shared_ptr.hpp>
#include <boost/make_shared.hpp>
class Message {
};
class Receiver {
public:
virtual ~Receiver() { }
virtual void receive(Message *msg) = 0;
CREATE OR REPLACE FUNCTION public.forecast_base_1_part_trig_func()
RETURNS trigger AS
$BODY$
DECLARE
v_count int;
v_partition_name text;
v_partition_timestamp timestamptz;
BEGIN
IF TG_OP = 'INSERT' THEN
v_partition_timestamp := date_trunc('day', NEW.nwp_analysis_at_date);
@ejrh
ejrh / gist:6e9c74bd65220fe656f8
Created March 22, 2016 08:33
Btree vs trigram index for short prefixes
filesys=# \d file
Table "public.file"
Column | Type | Modifiers
----------+-----------------------------+---------------------------------------------------
id | integer | not null default nextval('file_id_seq'::regclass)
name | character varying | not null
size | bigint | not null
modified | timestamp without time zone |
md5 | character(32) |
Indexes:
CREATE TABLE forecast_base_0
(
nwp_analysis_at_date timestamp without time zone NOT NULL,
nwp_analysis_at_time_period smallint NOT NULL,
nwp_analysis_prognosis integer NOT NULL,
issued_prognosis integer NOT NULL,
valid_from_date timestamp without time zone NOT NULL,
valid_from_time_period smallint NOT NULL,
location_id bigint NOT NULL,