Skip to content

Instantly share code, notes, and snippets.

View wpcarro's full-sized avatar

William Carroll wpcarro

  • internet
View GitHub Profile
@wpcarro
wpcarro / form.tsx
Created March 29, 2023 17:25
Custom encoder/decoder with react-hook-form and zod.
import React from "react";
import { useForm } from "react-hook-form";
import { z } from "zod";
import { zodResolver } from "@hookform/resolvers/zod";
import DimensionID from "lib/quality/DimensionID";
////////////////////////////////////////////////////////////////////////////////
// Main
////////////////////////////////////////////////////////////////////////////////
@wpcarro
wpcarro / config.yaml
Created February 18, 2023 02:26
Debugging benthos pipeline
input:
sql_raw:
driver: mssql
dsn: sqlserver://${USER}:${PASS}@some.place.com
query: |
select * from blah
output:
file:
path: '/tmp/stuff/${! json("filename") }'
@wpcarro
wpcarro / metric.json
Created February 16, 2023 20:36
Debugging stacking "version graph" in Datadog.
{
"series": [
{
"metric": "corp.service.heartbeat",
"type": 3,
"points": [
{
"timestamp": timestamp_unix(),
"value": 1,
}
@wpcarro
wpcarro / pipeline.yaml
Created February 13, 2023 19:37
Troubleshooting benthos
input:
file:
paths:
- /tmp/versions.json
codec: all-bytes
processors:
- jq:
query: '.[] | select( .Name | contains("Needle") ) | {"name": .Name, "key": .Key}'
- unarchive:
format: json_array
@wpcarro
wpcarro / examples.txt
Created February 13, 2023 03:27
Example input (#benthos)
- cmd: man passwd
when: 1653257918
- cmd: sudo passwd
when: 1653257918
- cmd: passwd
when: 1653257918
- cmd: sudo vim /etc/nixos/configuration.nix
when: 1653257918
@wpcarro
wpcarro / backfill.yaml
Created February 12, 2023 21:57
benthos definition to backfill one year's worth of logs
http:
enabled: false
input:
file:
paths:
- /tmp/errors.json
codec: all-bytes
processors:
- unarchive:
@wpcarro
wpcarro / compileSort.js
Last active January 23, 2023 17:35
Simple DSL for composing sorting logic
// Convert a sorting expressions (e.g. "Outflow DESC; Date ASC; Category ASC")
// into a function that can be passed to Array.prototype.sort.
function compileSort(expr) {
if (expr === '') {
return function(x, y) { return 0; };
}
return expr.split(/\s*;\s*/).reverse().reduce((acc, x) => {
const [k, dir] = x.split(/\s+/);
if (dir === 'ASC') {
return function(x, y) {
@wpcarro
wpcarro / command.yaml.tmpl
Created January 6, 2023 02:33
Dispatch command to k8s
apiVersion: batch/v1
kind: Job
metadata:
name: foo-command
spec:
ttlSecondsAfterFinished: 60
template:
spec:
containers:
- name: foo-command
@wpcarro
wpcarro / config.yaml
Created December 30, 2022 20:14
YNAB -> SQL with benthos.dev
input:
label: ynab_api
generate:
mapping: root = ""
interval: '@every 5m'
processors:
- cache:
operator: get
resource: pagination
key: latest
@wpcarro
wpcarro / example.yaml
Created December 30, 2022 17:16
Caching with benthos (example)
# Proof-of-concept caching with benthos:
# - read from cache (with default on first run)
# - log value
# - write random value to cache
# - repeat
input:
generate:
mapping: root = ""
processors: