Skip to content

Instantly share code, notes, and snippets.

View mattfysh's full-sized avatar
🌐

Matt mattfysh

🌐
View GitHub Profile
@mattfysh
mattfysh / paginate.ts
Created May 18, 2024 09:22
Drizzle `withPagination`
import invariant from 'tiny-invariant'
import type { PgColumn, PgSelect } from 'drizzle-orm/pg-core'
import type { SQL } from 'drizzle-orm'
import { desc, gt, lt, eq, and, or } from 'drizzle-orm'
// using `asc` or `desc` outside this function obscures the
// original column name, so they must be applied internally
type Order = 'desc' | 'asc'
type OrderColumn = PgColumn | [PgColumn, Order]
type Options = {
@mattfysh
mattfysh / express.js
Last active May 11, 2024 02:47
Express as miniflare wrapper
const express = require('express')
const { text } = require('node:stream/consumers')
const { Writable } = require('node:stream')
const { Miniflare, Log } = require('miniflare')
const app = express()
const mf = new Miniflare({
script: `addEventListener("fetch", (event) => {
event.respondWith(new Response("Hello Miniflare!"));
@mattfysh
mattfysh / delta_log.py
Created April 4, 2024 00:58
read delta table as a stream
import os
import json
from typing import Any
SKIP_OPERATIONS = ["OPTIMIZE", "VACUUM START", "VACUUM END"]
def is_subset(a: dict[str, Any], b: dict[str, Any]):
sub = a.items()
full = b.items()
@mattfysh
mattfysh / frankenstein.js
Created March 18, 2024 12:09
declaring drizzle types for a table defined elsewhere
import {
SQLiteTableWithColumns,
SQLiteTextBuilderInitial,
SQLiteTextJsonBuilderInitial,
SQLiteIntegerBuilderInitial,
SQLiteColumnBuilderBase,
} from 'drizzle-orm/sqlite-core'
import type { BuildColumns, HasDefault, NotNull } from 'drizzle-orm'
@mattfysh
mattfysh / frankenstein.js
Created March 14, 2024 04:06
using push-generated statements in `generate:sqlite`
import { get, patch, wrapImports } from './rewire'
const push = get('logSuggestionsAndReturn2')
const move = patch('_moveDataStatements', function (tableName, json) {
// set dataLoss=false to generate copy statements
return move.call(this, tableName, json, false)
})
wrapImports('init_migrate', {
@mattfysh
mattfysh / kafka.py
Created March 13, 2024 01:04
bytewax KafkaBuilder
from typing import Dict, List
from bytewax import operators as op
from bytewax.dataflow import Dataflow, Stream
from bytewax.connectors.kafka import operators as kop
from bytewax.connectors.kafka.serde import SchemaDeserializer
class KeyDeserializer(SchemaDeserializer[bytes, str]):
def de(self, data):
return data.decode()
const mf = new Miniflare({
script: `
export default {
async fetch(request, env, ctx) {
let id = env.DOO.idFromName('foo')
return await env.DOO.get(id).fetch(request)
}
}
const SECONDS = 1000
@mattfysh
mattfysh / pulumi.ts
Last active February 8, 2024 05:41
Pulumi Kubernetes - deployment preview error
import * as k8s from '@pulumi/kubernetes'
const provider = new k8s.Provider('k8s-provider', {
context: 'docker-desktop',
namespace: 'testns',
})
const ns = new k8s.core.v1.Namespace(
'ns',
{ metadata: { name: 'testns' } },
@mattfysh
mattfysh / index.ts
Last active December 17, 2023 03:13
Pulumi deploy k8s redpanda + console
import * as k8s from '@pulumi/kubernetes'
import dedent from 'dedent'
new k8s.apps.v1.Deployment('redpanda', {
metadata: {
labels: {
appClass: 'redpanda',
},
},
spec: {
@mattfysh
mattfysh / policy.json
Created December 12, 2023 22:44
Danger, Will Robinson!
{
"Version": "2012-10-17",
"Statement": [
{
"Effect": "Allow",
"Action": [
"iam:*",
"eks:*",
"ec2:*",
"autoscaling:*",