Skip to content

Instantly share code, notes, and snippets.

View thesmart's full-sized avatar

John Smart thesmart

View GitHub Profile
@jhurliman
jhurliman / stacktrace.php
Created July 20, 2012 00:03
Pretty print stack trace in PHP
function stackTrace() {
$stack = debug_backtrace();
$output = 'Stack trace:' . PHP_EOL;
$stackLen = count($stack);
for ($i = 1; $i < $stackLen; $i++) {
$entry = $stack[$i];
$func = $entry['function'] . '(';
$argsLen = count($entry['args']);
@rgreenjr
rgreenjr / postgres_queries_and_commands.sql
Last active July 22, 2024 09:57
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%'
@thesmart
thesmart / hid_generate.sql
Created May 5, 2020 17:25
Generates ordered, base36 alpha-numeric ids similar to Slack's ID scheme. Suitable for use as primary key.
-- This function generates ordered, base36 alpha-numeric ids similar to Slack's ID scheme.
--
-- I wanted a primary key scheme that had the following features:
-- 1) Lexical order, so that `ORDER BY` works as expected.
-- 2) Prevents sampling an auto-incrementing primary key to determine growth over time.
-- 3) Shorter and more human-friendly than BIGINT and UUID keys.
-- 4) Has a prefix such that table can be inferred from any record's primary or foreign key.
--
-- It is suitable for use as primary key, provided a few assumptions are true:
-- 1) You do not attempt to genereate more than 10M hids per second (system-time).