Skip to content

Instantly share code, notes, and snippets.

@dillonstreator
dillonstreator / postgres-jsonb-path-query.sql
Created November 17, 2021 17:31
postgres jsonb path query retrieve field in object with field that is array of objects
SELECT
id,
jsonb_path_query(json_field::jsonb, '$.arrayfield[*] ? (@.fieldid == $fieldid)', '{"fieldid": "field-id-value-to-find"}')->>'fieldvalue' as field_value
FROM table
WHERE json_field::jsonb->'arrayfield' @> '[{"fieldid": "field-id-value-to-find"}]';
@dillonstreator
dillonstreator / go-concurrent-job-processing.go
Last active October 7, 2021 14:16
concurrently process items with a bounded channel with storing job results, graceful shutdown, pickup where left off, and capturing of all errors
package main
import (
"context"
"encoding/json"
"fmt"
"io/ioutil"
"log"
"math/rand"
"os"
@dillonstreator
dillonstreator / port-to-pid.md
Last active October 7, 2021 01:01
find PID running on a port utility shell function

Find PID running on a port

# .zshrc

port-to-pid() {
        lsof -i:$1 -Fp | sed 's/^p//' | head -n 1
}
@dillonstreator
dillonstreator / crumby.js
Last active January 29, 2022 16:10
Javascript generate breadcrumb array from url pathname
const titleizeWord = (str) => `${str[0].toUpperCase()}${str.slice(1)}`;
const kebabToTitle = (str) => str.split("-").map(titleizeWord).join(" ");
const toBreadcrumbs = (pathname, { rootName = "Home", nameTransform = s=>s } = {}) =>
pathname
.split("/")
.filter(Boolean)
.reduce(
(acc, curr, idx, arr) => {
acc.path += `/${curr}`;