Skip to content

Instantly share code, notes, and snippets.

View eric-burel's full-sized avatar
Writing courses at nextjspatterns.com

Eric Burel eric-burel

Writing courses at nextjspatterns.com
View GitHub Profile
@eric-burel
eric-burel / google-colab-anthropic-batch-api-langgraph.py
Created June 27, 2025 17:12
Use LangGraph, SQLite, Google Colab and Google Drive to handle long running Anthropic batch API calls elegantly
# -*- coding: utf-8 -*-
"""LBKE Anthropic batch runner.ipynb
## Demo of calling Anthropic Batch API from a LangGraph graph
Improvements:
- an interrupt should be prefered to ending the chart when the work is pending => currently each new run to check if the batch is there will send a new message to the thread since we re-invoke the chart
- better processing responses, maybe using a MessageState/add reducer to treat the response as an assistant message added to a conversation
- as a bonus, polling the chart on a predefined frequence (useful for a quick run)
- test if it still works after the notebook is closed thanks to gdrive checkpointing
@eric-burel
eric-burel / langgraph-colab-sqlite-checkpoint
Last active June 27, 2025 12:39
LangGraph checkpointer using Google Colab + Google Drive + SQLite
# Commented out IPython magic to ensure Python compatibility.
# %pip install -q langgraph
# %pip install -q langgraph-checkpoint-sqlite
# Demo notebook: https://colab.research.google.com/drive/16V9TpOsLMOuU655ryerni7Hc7mni6hcU?usp=sharing
import os
from google.colab import drive
DRIVE_MOUNT_POINT = "/content/drive"
drive.mount(DRIVE_MOUNT_POINT)
@eric-burel
eric-burel / next-app-router-bleeding-edge.md
Created June 23, 2023 07:03
next-app-router-bleeding-edge
  • Can't mix static layout and dynamic pages, this prevents define common static data requirements in the layout and then optionnally dynamic requirements in some pages below: vercel/next.js#44712 (comment)

  • RSC might be a way to colocate graphql data requirements with components, but it's not very declarative

  • i18n: since "FormattedMessage" tend to be a leaf component, we can't really server-side render it, all i18n messages thus need hydration

  • 404 are delicate because route handlers can be mixed with routes : vercel/next.js#49696, and also when fetching files (you may conflate a file with the first route parameter of your app eg [lang])

const {EditorState} = require("prosemirror-state")
const {EditorView} = require("prosemirror-view")
const {Schema, DOMParser} = require("prosemirror-model")
const {schema} = require("prosemirror-schema-basic")
const {addListNodes} = require("prosemirror-schema-list")
const {exampleSetup} = require("prosemirror-example-setup")
const { inputRules, InputRule } = require("prosemirror-inputrules")
const starRule = new InputRule(/\*(.+)\*/, (state, match, start, end) => {
@eric-burel
eric-burel / mockDbClient.ts
Last active September 18, 2024 09:48
A mock database client that counts the opened connections and store data into $HOME/.mockdb
import fs from "fs";
import os from "os";
import path from "path";
const fsPromises = fs.promises;
// DATA STORE
// In a real project this belongs to the db server code
// We simulate a distant db by storing data in a file
const filePath = path.resolve(os.homedir(), ".mockdb");
async function updateData<TData=any>(data:TData) {
@eric-burel
eric-burel / generateTocFromSections.js
Created July 11, 2022 15:44
Generate toc from sections a Slidev app - to be included in your index.html
/**
* Run this script manually in the console and copy-paste the result to generate
* a TOC based on "section" layout, instead of markdown titles (that are not helpful here)
*
* NOTE: this script is loaded in index.html,
* so you can call generateTocFromSections easily from the slidev app, in the browser console
*
* NOTE: this could also be adapted with Cheerio or an HTML/md parser to parse the markdown directly?
*/
function generateTocFromSections() {
const edits = [
[
"node_modules/ts-invariant/package.json",
{
type: "module",
exports: {
".": "./lib/invariant.esm.js",
"./process/index.js": "./process/index.js",
},
},
@eric-burel
eric-burel / useWarnOnUnsaved.ts
Created May 21, 2021 09:18
Hook to warn user on unwanted page leave
import { useIntlContext } from "@vulcanjs/i18n";
import { useEffect, useRef } from "react";
import { block } from "./block";
import debug from "debug";
const debugTransitions = debug("vn:route-transition");
/**
* Can trigger an alert on unsaved changes
*
* @see https://github.com/ReactTraining/history/blob/master/docs/blocking-transitions.md
@eric-burel
eric-burel / nextConfigDefinePlugin.js
Created February 26, 2021 08:13
Next webpack DefinePlugin
// in next.config.js Webpack field
config.plugins.push(
new options.webpack.DefinePlugin({
  'process.env.NEXT_IS_SERVER': JSON.stringify(options.isServer.toString()),
  })
)
@eric-burel
eric-burel / nextConfigPackageVersion.js
Created February 26, 2021 08:09
next config public app
// in next.config.js
import packageJson from "./package.json"
module.exports = {
env: {
NEXT_PUBLIC_APP_VERSION: packageJson.version
}
}