Skip to content

Instantly share code, notes, and snippets.

@judell
judell / hn_unnest.hcl
Created September 10, 2024 20:51
hn_unnest
# duckdb
with names as (
select
unnest(string_to_array(?, ',')) as name
),
# sqlite
WITH RECURSIVE names(name, remaining) AS (
@judell
judell / hn_joined_lists.hcl
Created September 10, 2024 20:40
hn_joined_lists
locals {
joined_companies = join(",", local.companies)
joined_languages = join(",", local.languages)
joined_operating_systems = join(",", local.operating_systems)
joined_clouds = join(",", local.clouds)
joined_dbs = join(",", local.dbs)
joined_editors = join(",", local.editors)
}
@judell
judell / hn_mentions.hcl
Created September 10, 2024 20:30
hn_mentions
query "mentions" {
sql = <<EOQ
with names as (
select
unnest( $1::text[] ) as name
),
counts as (
select
name,
(
@judell
judell / hn_languages.hcl
Created September 10, 2024 20:27
hn_languages
languages = [
"C#",
"C\\+\\+",
"Clojure",
"CSS",
"Erlang",
"golang| go 1.| (in|with|using) go | go (.+)(compiler|template|monorepo|generic|interface|library|framework|garbage|module|range|source)",
"Haskell",
"HTML",
"Java ",
@judell
judell / hn_triptych.hcl
Created September 10, 2024 20:22
hn_triptych
container {
chart {
base = chart.languages_base
width = 4
type = "donut"
title = "language mentions: last 24 hours"
query = query.mentions
args = [ local.languages, 0, 1440 ]
}
@judell
judell / create_calendar_weeks.py
Created September 3, 2024 15:41
create calendar weeks
def create_calendar_weeks(year, month, grouped_events):
cal = calendar.monthcalendar(year, month)
calendar_weeks = []
for week in cal:
calendar_week = []
for day in week:
if day == 0:
calendar_week.append((0, []))
@judell
judell / wordpress.spc
Created August 16, 2024 15:59
wordpress.spc
connection "all_wordpress" {
plugin = "wordpress"
type = "aggregator"
connections = ["jon", "newstack"]
}
connection "jon" {
plugin = "wordpress"
endpoint = "https://blog.jonudell.net/wp-json/"
username = "..."
@judell
judell / table_wordpress_post.go
Created August 15, 2024 22:53
table_wordpress_post.go
func listPosts(ctx context.Context, d *plugin.QueryData, _ *plugin.HydrateData) (interface{}, error) {
conn, err := connect(ctx, d)
if err != nil {
return nil, err
}
plugin.Logger(ctx).Debug("WordPress listPosts author", "author", d.Quals["author"])
plugin.Logger(ctx).Debug("WordPress listPosts date", "date", d.Quals["date"])
options := &wordpress.PostListOptions{}
@judell
judell / paginate.go
Created August 15, 2024 22:51
paginate.go
type ListFunc func(context.Context, interface{}, int, int) (interface{}, *wordpress.Response, error)
func paginate(ctx context.Context, d *plugin.QueryData, listFunc ListFunc, options interface{}) error {
perPage := 100
offset := 0
for {
plugin.Logger(ctx).Debug("WordPress paginate", "offset", offset)
// `listFunc`, the passed-in anonymous function, could call the go SDK's `Posts.List` (which wraps the API's
@judell
judell / go.mod
Created August 15, 2024 20:31
go.mod for wordpress plugin
module github.com/judell/steampipe-plugin-wordpress
go 1.21.4
require (
github.com/sogko/go-wordpress v0.0.0-20190616154547-91556a5001c7
github.com/turbot/steampipe-plugin-sdk/v5 v5.8.0
)
replace github.com/sogko/go-wordpress => github.com/robbiet480/go-wordpress v0.0.0-20180206201500-3b8369ffcef3