Skip to content

Instantly share code, notes, and snippets.

@ryanguill
ryanguill / postgres-merge-arrays.sql
Created December 21, 2016 16:41
in postgres, there currently isnt a function to combine two arrays and remove duplicates - this will do that.
CREATE OR REPLACE FUNCTION mergeArrays (a1 ANYARRAY, a2 ANYARRAY) RETURNS ANYARRAY AS $$
SELECT ARRAY_AGG(x ORDER BY x)
FROM (
SELECT DISTINCT UNNEST($1 || $2) AS x
) s;
$$ LANGUAGE SQL STRICT;
@ryanguill
ryanguill / postgres-pivot.md
Last active June 29, 2022 14:08
Example of postgres pivot using jsonb_object_agg for variable columns in output. To play with this yourself in an online repl, click here: https://dbfiddle.uk/?rdbms=postgres_14&fiddle=39e115cb8afd6e62c0101286ecd08a3f
/*
================================================================================
Pivot example with variable number of columns in the output.
================================================================================

example data is straight forward, imagine a table with a customer identifier, 
an invoice date and an amount.
*/
DROP FUNCTION IF EXISTS calculate_time_range();
CREATE OR REPLACE FUNCTION calculate_time_range (uom varchar, qty integer, startTs timestamptz DEFAULT (current_timestamp at time zone 'utc')::timestamptz) RETURNS tstzrange AS $$
BEGIN
IF uom IS null THEN RETURN null; END IF;
IF qty IS null THEN RETURN null; END IF;
CASE UPPER(uom)
WHEN 'TIME_MS' THEN
RETURN TSTZRANGE(startTs, startTs + (qty || ' milliseconds')::INTERVAL, '[)');
SELECT
	  pri.lorem
	, pri.ipsum
	, pri.dolar orci
	, pri.sit
	, pri.amet
	, CASE
		WHEN erat = 'vitae'
 THEN 'suscipit'
CREATE OR REPLACE FUNCTION pctDisplay (pct numeric, ch text = '|', length int = 20, includeLabel boolean = TRUE) RETURNS text AS $$
DECLARE x TEXT;
BEGIN
IF length < 1 OR length > 100 THEN
length = 20;
END IF;
IF pct < 0 THEN
pct = 0;

Roam Capture Bookmarklet

Building on the work of the +Roam bookmarklet, here is a version that allows you to capture text from webpages and articles in a few different ways:

  • It will copy the text automatically. A red "copied!" pill will show in the top right of the page to let you know it worked.
  • If you do not select anything it will give you only a markdown link to the page
  • If you select something it will give you the selected text in italics with a markdown link to the page
  • If you select more than one thing (firefox only I believe) it will give you a markdown link to the page with the selected text as child blocks nested underneath.

To try it, drag this link to your bookmarks and then select text on a page and then click the bookmark.

Roam Snippet Bookmarklet

Building on the work of the +Roam bookmarklet, here is a version that allows you to capture text from webpages and articles in a few different ways:

  • It will copy the text automatically. A red "copied!" pill will show in the top right of the page to let you know it worked.
  • If you do not select anything it will give you only a markdown link to the page
  • If you select something it will give you the selected text in italics with a markdown link to the page
  • If you select more than one thing (firefox only I believe) it will give you a markdown link to the page with the selected text as child blocks nested underneath.
  • If you select things, your selection will be restored after copying.
@ryanguill
ryanguill / base62.cfc
Created July 31, 2014 16:02
coldfusion component; allows you to encode an integer as a base62 string using [a-zA-Z0-9] - useful for url shortening. should handle from 0 to 9,223,372,036,854,775,807
component {
variables.ALPHABET = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789";
variables.BASE = bigInt(len(ALPHABET).toString());
private any function bigInt (required string input ){
return createObject("java", "java.math.BigInteger").init(input);
}
private any function stringBuilder (string input = "") {
<cfscript>
/*
this is what im actually working on, but isnt really the point of this discussion,
but for clarity, I have a process where I am needing to (conditionally) map
from one uuid to another, so I am making a litle closure to keep track. If
I ask for an ID that hasnt been seen yet then it just creates a new uuid for me and
then keeps track of it going forward.
*/
function makeIdMapper () {

Preface

This guide is one section of a larger guide to installing a cent 6.x server in virtual box for development purposes with different applications. The top level guide with links to all of the sections is here: https://gist.github.com/ryanguill/5149058 Some instructions in this guide may assume a configuration from other parts of the guide.

#Install Railo ColdFusion - manual installation

These instructions assume you are starting with a new VM cloned from your template

##Install httpd