Skip to content

Instantly share code, notes, and snippets.

@gabrielbauman
gabrielbauman / RpcDurableObject.ts
Last active October 5, 2023 22:20
RPC-style Cloudflare durable objects
/**
* RpcDurableObject is a base class for DurableObjects that want to be called in an RPC style. Derive your object
* from this class and implement your methods as normal methods. There is no need to implement the fetch method. Then,
* use the buildRpcClient function to create a proxy object and call methods on the durable object as if it were a
* local object!
*
* This hides the complexity of calling a Durable Object from a worker and allows you to focus on the business logic
* of your application. It also allows you to use TypeScript to type your RPC methods; your worker and the proxy object
* should both implement the same interface containing the RPC methods.
*
@gabrielbauman
gabrielbauman / RelationshipModel.ts
Created May 8, 2024 17:50
A stupid module for calculating relationship satisfaction in a couple based on employment differences and jealousy
export module RelationshipModel {
// Constants for the model
const k1 = 0.5; // Influence of self-satisfaction on relationship satisfaction
const k2 = 0.3; // Influence of jealousy/admiration on relationship satisfaction
const k3 = 0.2; // Influence of motivated opportunities on relationship satisfaction
const k4 = 0.6; // Influence of employment success on self-satisfaction
const k5 = -0.4; // Impact of jealousy on self-satisfaction (negative implies reducing self-satisfaction)
const k6 = 0.2; // Impact of opportunities on self-satisfaction
const k7 = 0.5; // Sensitivity of jealousy/admiration to differences in success
const k8 = 0.3; // How desire for success affects jealousy/admiration