Skip to content

Instantly share code, notes, and snippets.

@ttfkam
ttfkam / graphile-computed-columns.ts
Created December 31, 2022 19:01
Enhance Postgraphile compatibility with PostgREST
import type { Plugin, Build } from "graphile-build";
import type { PgClass, PgProc } from "./PgIntrospectionPlugin";
export const getComputedColumnDetails = (
build: Build,
table: PgClass,
proc: PgProc
) => {
if (proc.isVolatile) return null;
if (proc.namespaceId !== table.namespaceId) return null;
@ttfkam
ttfkam / pgcrypto.js
Created April 12, 2017 17:05
Simpler constant list entry, aka, I love multiline strings
const NAMES = `admintools
auth_delay
auto_explain
bloom
btree_gin
btree_gist
chkpass
citext
cube
dblink
@ttfkam
ttfkam / slice.sql
Last active December 16, 2016 04:00
Array slice for PostgreSQL
-- Copyright 2016, Miles Elam <miles@geekspeak.org>
-- MIT License, http://www.opensource.org/licenses/mit-license.php
CREATE OR REPLACE FUNCTION splice(target anyarray, start integer, to_insert anyarray)
RETURNS anyarray LANGUAGE 'sql' IMMUTABLE LEAKPROOF STRICT AS $$
SELECT target[0:start - 1]
|| to_insert
|| target[start:array_length(target, 1)]
$$;
@ttfkam
ttfkam / terminal-icon.svg
Created September 4, 2016 18:52
Someone said something about a file size strawman...
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
@ttfkam
ttfkam / pg_geolite2_csv.sql
Last active April 18, 2023 03:44
GeoLite2 for PostgreSQL
-- GeoLite2 CSV files for use with PostgreSQL 9+
-- by Miles Elam <miles@geekspeak.org>
-- THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
-- "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
-- LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
-- A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
-- OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
-- SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
-- LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
using namespace std;
struct Node {
int value;
node* left;
node* right;
}
boolean findSum(Node* ref, int prev, int target) {
if (!ref) {
@ttfkam
ttfkam / async_defer_script.js
Last active May 19, 2016 18:34 — forked from fearphage/async_defer_script.js
Added check for Opera, loading on DOMContentLoaded instead of load. Event only added if Opera has no native support. Replacing script child instead of insert/remove.
// ==UserScript==
// @name defer/async for Opera
// @namespace http://d.hatena.ne.jp/edvakf/
// @license Public Domain
// Updated by Miles Elam <miles@geekspeak.org>
// ==/UserScript==
(function(window, document, opera) {
function load_script(script, attr) {