Skip to content

Instantly share code, notes, and snippets.

@yoadsn
yoadsn / pregel_task_limited_parallelism.py
Created July 21, 2025 10:21
Limiting the parallel degree of Langgraph pregel task execution
max_parallel_degree = 2
check_every_secs = 1
@entrypoint
async def limited_parallel_execution(input_state: dict[any, any], config: RunnableConfig):
items = range(10)
all_tasks = []
for item in items:
t_future = process_item(item) # process_item is a @task
all_tasks.append(t_future)
@yoadsn
yoadsn / bot-type-processor.js
Last active September 3, 2018 17:29
AppInsights - Bot Type Processor
const appendUserAgent = (envelope, context) => {
if (envelope.data.baseType === 'RequestData') {
// headers are available on the context - but are not reported
const ua = context['http.ServerRequest'].headers['user-agent'];
if (ua) {
// Extract the bot type (google only in that case)
const botType = getGoogleBotType(ua);
if (botType) {
// The reporting would not include the bot type data point with the request.
envelope.data.baseData.properties['bot-type'] = botType;
@yoadsn
yoadsn / appinsights-setup.js
Last active July 16, 2018 11:13
App Insights Processors Simple Example
import * as appInsights from 'applicationinsights';
const avoidMongodbAdmin = (envelope, context) => {
if (envelope.data.baseType === 'RemoteDependencyData') {
const { type, target } = envelope.data.baseData;
// Do not monitor calls to the admin DB
if (type === 'mongodb' && target === 'admin') {
return false;
}
}
{
"name": "rankedRand",
"text": {
"weights": {
"name": 5
}
},
"functions": [
{
"fieldName": "randCoord",
{
"name": "randomRanked",
"text": null,
"functions": [
{
"fieldName": "randCoords",
"freshness": null,
"interpolation": "linear",
"magnitude": null,
"distance": {
const center = {
lat: 0,
lng: 0
};
const angle = (Math.random() - 0.5) * 360;
const distance = Math.random() * 50;
const point = getPointOnRadius(center, distance, angle);
@yoadsn
yoadsn / randomPointOnRadius.js
Last active October 10, 2017 06:25
Calculate a random geo point on a circle radius
const R = 6371e3; // Earth radius in meters (approximated)
const fromRadians = (rad) => rad / (Math.PI / 180);
const toRadians = (deg) => deg * (Math.PI / 180);
const getPointOnRadius = (center, radius, angle) => {
const phi1 = toRadians(center.lat);
const lambda1 = toRadians(center.lng);
const theta = toRadians(angle);
const d = radius;

Keybase proof

I hereby claim:

  • I am yoadsn on github.
  • I am yoad (https://keybase.io/yoad) on keybase.
  • I have a public key ASCVYF1k9xLsTm6Xvo9ZIP-BtdjEjatYyAdyd_qpqcUGqQo

To claim this, I am signing this object:

@yoadsn
yoadsn / mt.js
Last active July 9, 2018 21:29
GQL - Multi Tenant Idea
const tenantsConfig = [
{ name: 't1', connStr: 'mongodb://...' },
{ name: 't2', connStr: 'mongodb://...' }
];
let tenantConns = tenantsConfig.map(tenant => ({
...tenant,
conn: mongoose.createConnection(tenant.connStr))
});
import Prismic, { Document } from 'prismic.io';
...
let api = await Prismic.api("http://wescover-repo.prismic.io/api");
let document = await api.getByUID('homepage', 'homepage');
let asJson = JSON.stringify(document);
let asObject = JSON.parse(asJson);
let backToDoc = new Document(
asObject.id,
asObject.uid,
asObject.type,