Skip to content

Instantly share code, notes, and snippets.

@jbryanscott
jbryanscott / convox_instance_ssh_copy.sh
Created October 28, 2017 03:06
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
#!/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 / json_compliant_postgres.sql
Created March 23, 2018 23:42
Hack for extracting compliant JSON from Postgres
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 / display_sigfig.py
Created April 5, 2017 00:54
Displaying proper significant figures in Python
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
'''