Skip to content

Instantly share code, notes, and snippets.

A metatable can be defined like

local t = setmetatable({}, {
  __tostring = function() return 'custom tostring behavior!' end
})

Here are the metamethods that you can define, and their behavior

Operators

@matheusoliveira
matheusoliveira / json_manipulator.sql
Last active February 17, 2024 15:14
Simple PostgreSQL functions to manipulate json objects. (Note: performance is not a concern for those functions)
CREATE OR REPLACE FUNCTION public.json_append(data json, insert_data json)
RETURNS json
IMMUTABLE
LANGUAGE sql
AS $$
SELECT ('{'||string_agg(to_json(key)||':'||value, ',')||'}')::json
FROM (
SELECT * FROM json_each(data)
UNION ALL
SELECT * FROM json_each(insert_data)
@domenic
domenic / after-thrawn.md
Last active November 28, 2023 20:06
What next after the Thrawn Trilogy?

What to Read After The Thrawn Trilogy?

The first post-Return of the Jedi book series anyone should read is The Thrawn Trilogy: namely Heir to the Empire, Dark Force Rising, and The Last Command, all by Timothy Zahn. They are an excellent introduction to the "New Republic era" of the Star Wars Expanded Universe (EU), and notably they were the first books written in real-world time to explore this era.

But after that, what should you read?

Background: The Eras of the Expanded Universe

First, be aware that the post-Return of the Jedi EU is broken up into three main eras:

@rgreenjr
rgreenjr / postgres_queries_and_commands.sql
Last active September 19, 2024 05:47
Useful PostgreSQL Queries and Commands
-- show running queries (pre 9.2)
SELECT procpid, age(clock_timestamp(), query_start), usename, current_query
FROM pg_stat_activity
WHERE current_query != '<IDLE>' AND current_query NOT ILIKE '%pg_stat_activity%'
ORDER BY query_start desc;
-- show running queries (9.2)
SELECT pid, age(clock_timestamp(), query_start), usename, query
FROM pg_stat_activity
WHERE query != '<IDLE>' AND query NOT ILIKE '%pg_stat_activity%'