Skip to content

Instantly share code, notes, and snippets.

View airhorns's full-sized avatar
🎯
Workin' on Gadget at https://gadget.dev

Harry Brundage airhorns

🎯
Workin' on Gadget at https://gadget.dev
View GitHub Profile
/* eslint-disable no-console */
import type { AgentAction, AgentFinish } from "@langchain/core/agents";
import { BaseCallbackHandler } from "@langchain/core/callbacks/base";
import type { Document } from "@langchain/core/documents";
import type { Serialized } from "@langchain/core/load/serializable";
import {
AIMessage,
AIMessageChunk,
BaseMessage,
ChatMessage,
// what would be really annoying to do
const result = await gpt4oMini.withConfig({callbacks: [BraintrustCallbackHandler]}).withStructuredOutput( //...
// what would be much better
export const gpt4oMini = new ChatOpenAI({
model: "gpt-4o-mini",
callbacks: [BraintrustCallbackHandler],
...retryConfig,
});
const strictSchemaCache = new WeakMap<ZodSchema, ZodSchema>();
const strictZodSchema = (schema: ZodSchema): ZodSchema => {
if (schema instanceof ZodObject) {
const shape = schema.shape;
const newShape: any = {};
for (const key in shape) {
const fieldSchema = shape[key];
if (key == "default" && fieldSchema instanceof ZodOptional && fieldSchema.unwrap() instanceof ZodAny) {
continue;
function toast(text, delay){
var div = document.createElement("div");
div.style.position = "fixed";
div.style.maxWidth = "80%";
div.style.color = "white";
div.style.boxSizing = "border-box";
div.style.background = "rgba(0,0,0,0.76)";
div.style.padding = "0.8em 2.618em";
div.style.bottom = '9%';
div.style.left = '3%';
rip" "-dynamiclib" "-Wl,-dylib" "-nodefaultlibs" "--ld-path=/nix/store/cg869jlpzrh5xgc0hcll7risc5gsk611-mold-2.1.0/bin/mold"
> = note: clang-11: error: unsupported option '--ld-path=/nix/store/cg869jlpzrh5xgc0hcll7risc5gsk611-mold-2.1.0/bin/mold'
>
>
> error: could not compile `jsonpath_lib` (lib) due to previous error
> warning: build failed, waiting for other jobs to finish...
@airhorns
airhorns / terse-default.js
Last active May 16, 2023 18:32
Gadget nextgen code snippets
import { assignInputs, validateAndSave } from "gadget";
/**
* Run Action code for create on post
* @param { import("gadget").CreatePostActionContext } context - Everything for running this action handler, like the api client, current record, params, etc. More on effect context: https://docs.gadget.dev/guides/extending-with-code#effect-context
*/
export async function run({ api, record, inputs }) {
assignInputs(record, inputs);
await validateAndSave(record);
}
00:56:50 Encountered an error:
module 'isolate_proto' has no attribute 'RegisterCronResult'
00:56:50 Traceback (most recent call last):
File "/Users/airhorns/Library/Caches/pypoetry/virtualenvs/warehouse-ACxaxuaC-py3.9/lib/python3.9/site-packages/dbt/main.py", line 136, in main
results, succeeded = handle_and_check(args)
File "/Users/airhorns/Library/Caches/pypoetry/virtualenvs/warehouse-ACxaxuaC-py3.9/lib/python3.9/site-packages/dbt/main.py", line 206, in handle_and_check
task, res = run_from_args(parsed)
File "/Users/airhorns/Library/Caches/pypoetry/virtualenvs/warehouse-ACxaxuaC-py3.9/lib/python3.9/site-packages/dbt/main.py", line 233, in run_from_args
task = parsed.cls.from_args(args=parsed)
File "/Users/airhorns/Library/Caches/pypoetry/virtualenvs/warehouse-ACxaxuaC-py3.9/lib/python3.9/site-packages/dbt/task/base.py", line 163, in from_args
@airhorns
airhorns / vite.config.js
Created January 4, 2023 20:51
Final vite.config.js code for Gadget + Shopify CLI app
import { defineConfig } from "vite";
import { dirname } from "path";
import { fileURLToPath } from "url";
import react from "@vitejs/plugin-react";
if (process.env.npm_lifecycle_event === "build" && !process.env.CI && !process.env.SHOPIFY_API_KEY) {
console.warn(
"\nBuilding the frontend app without an API key. The frontend build will not run without an API key. Set the SHOPIFY_API_KEY environment variable when running the build command.\n"
);
}
@airhorns
airhorns / Updating Gadgetized CLI App For Shopify Public App Store.md
Last active January 4, 2023 20:56
Guide for upgrading a Shopify CLI generated app to set correct iframe security headers

This document explains how to update a Shopify CLI generated application from the setup Gadget previously recommended before Dec 21, 2022, to the new setup Gadget recommends.

Why

Previously, Gadget recommended removing the web/package.json and web/shopify.web.toml files, stripping away the node.js server that served the frontend application in web/frontend. Most web hosts have functionality to serve static files in the same manner this node.js application does, as well as set up redirects and headers. Since Gadget handles the majority of the backend, this node.js backend largely duplicates Gadget functionality.

That said, it is annoying to set up each different frontend hosting provider's tooling to meet Shopify's strict iframe security requirements for apps destined for the Public App Store. Shopify requires that each application is served to the embedded app iframe with the Content-Security-Policy header set to a secure value. Read more about Shopify's iframe security requirements [her

@airhorns
airhorns / retryShopifyCall.ts
Last active June 22, 2022 20:17
Wrapper code for making calls to Shopify using `shopify-api-node` that get automatically retried when the rate limit is exceeded
import pRetry from "p-retry";
import { isArray, isNil, isObject, isString } from "lodash";
const responseFromError = (error: any): Response | undefined => {
if ("response" in error) {
const response = error.response;
if (response && "body" in response) {
return response as Response;
}
}