Skip to content

Instantly share code, notes, and snippets.

Avatar

J. Bryan Scott jbryanscott

View GitHub Profile
@jbryanscott
jbryanscott / json_compliant_postgres.sql
Created Mar 23, 2018
Hack for extracting compliant JSON from Postgres
View json_compliant_postgres.sql
WITH base AS (
SELECT
'{"id": 26770, "name": "hello world"}'::jsonb AS some_json
)
SELECT
pg_typeof(some_json),
/* non-compliant, pseudo-JSON */
some_json AS pseudo_json,
/* use ::text cast to product compliant JSON */
some_json::text AS compliant_json
@jbryanscott
jbryanscott / convox_instance_ssh_copy.sh
Created Oct 28, 2017
Copy files via SSH command text when you don't have direct access to the host, e.g. in a bastion or virtual setup like Convox
View convox_instance_ssh_copy.sh
#!/usr/bin/env bash
if [[ "${BASH_SOURCE[0]}" != "${0}" ]]; then
echo "Fatal: Sourcing detected. Cannot source ${BASH_SOURCE[0]}."
return
exit 1
fi
set -e
set -o pipefail
script_root="$(cd $(dirname ${BASH_SOURCE[0]}) && pwd)"
cd "$script_root"
@jbryanscott
jbryanscott / display_sigfig.py
Created Apr 5, 2017
Displaying proper significant figures in Python
View display_sigfig.py
from math import floor, log10
def display_sigfig(x, sigfigs=2) -> str:
'''
Suppose we want to show 2 significant figures. Implicitly we want to show 3 bits of information:
- The order of magnitude
- Significant digit #1
- Significant digit #2
'''