Skip to content

Instantly share code, notes, and snippets.

@mattboutet
mattboutet / postgres_queries_and_commands.sql
Created May 18, 2020 23:51 — forked from rgreenjr/postgres_queries_and_commands.sql
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%'
@mattboutet
mattboutet / knexPostgresFullTextSearch.js
Created April 24, 2019 17:12 — forked from cameronblandford/knexPostgresFullTextSearch.js
Implement full text search using Knex + Objection
// Because we're using an ORM (Objection), it's a pain to add a tsvector when inserting,
// since tsvectors and FTS aren't supported by Objection. Instead, I've added a hook that
// fires on insert which auto-generates the tsvector field for each newly inserted entry.
// This is an example knex migration file for said behavior.
const addUserIndex = `
ALTER TABLE public.user ADD "document" tsvector;
CREATE FUNCTION my_trigger_function()
RETURNS trigger AS $$
@mattboutet
mattboutet / gist:2882e73ec3d993a3a1477017e90211b0
Created March 24, 2018 13:06 — forked from devinivy/deploy.sh
Publish a hapi pal flavor
# Ensure flavor and pal branch are up-to-date locally
git checkout flavor-<name> # Go to the flavor branch
git merge pal/pal # Ensure we're not squashing irrelevant changes, e.g. to the readme
git push pal flavor-<name> # Push the updated flavor branch

git reset pal/pal # See the changes as they appear on top of the main pal branch
git checkout --detach # Leave the current branch– at this point we dont need to update any branch
git add ... # List updated files
git commit -m "(flavor) <name> v<major>.<minor>.<patch>" # Create the squashed commit
@mattboutet
mattboutet / app.js
Created June 9, 2017 02:02
Strange relate behavior with objection
//From https://www.vincit.fi/en/blog/effortless-eager-loading-nested-inserts-objection-js/
//There's a bunch of code here that's not needed for this example, but I was trying to keep edits to a minimum
//Stick this in a directory, then `npm install objection knex sqlite3`
//to run: node app.js
//Changing reviewerId to reviewer in the code below will cause the problem I'm talking about
'use strict';
const objection = require('objection');

Keybase proof

I hereby claim:

  • I am mattboutet on github.
  • I am mattboutet (https://keybase.io/mattboutet) on keybase.
  • I have a public key ASC8ap5IkUNjGQOhW-kxaRKNS1wid7_nrnmXM5glX98B_Ao

To claim this, I am signing this object: