modified version of http://bl.ocks.org/curran/01aa2685f083b6c1b9fb with the map's bounding box on the globe
original readme follows:
--
Pan and zoom in the map on the left to rotate the globe.
Click and drag the globe to pan on the map.
| <!DOCTYPE html> | |
| <html> | |
| <head> | |
| <title>CartoDB + Leaflet interactivity example | CartoDB.js</title> | |
| <meta name="viewport" content="initial-scale=1.0, user-scalable=no" /> | |
| <meta http-equiv="content-type" content="text/html; charset=UTF-8"/> | |
| <link rel="shortcut icon" href="http://cartodb.com/assets/favicon.ico" /> | |
| <style> | |
| html, body, #map { | |
| height: 100%; |
| WITH deltas as ( | |
| SELECT | |
| st_distance(the_geom::geography, lag(the_geom::geography, 1) over(order by timestamp)) as ddist, | |
| timestamp - lag(timestamp, 1) over(order by timestamp) as dt | |
| from out_2 offset 1000 | |
| ) | |
| select avg(ddist/dt) as speed from deltas |
modified version of http://bl.ocks.org/curran/01aa2685f083b6c1b9fb with the map's bounding box on the globe
original readme follows:
--
Pan and zoom in the map on the left to rotate the globe.
Click and drag the globe to pan on the map.
| CREATE OR REPLACE FUNCTION public.CDB_Delayed_TableMetadata_Trigger() | |
| RETURNS trigger AS $$ | |
| DECLARE upd timestamp; | |
| BEGIN | |
| IF TG_RELID = 'cartodb.CDB_TableMetadata'::regclass::oid THEN | |
| RETURN NULL; | |
| END IF; | |
| SELECT updated_at INTO upd | |
| FROM cartodb.CDB_TableMetadata WHERE tabname = TG_RELID::regclass; | |
| IF upd IS NOT NULL AND (now() - upd) > '20m'::interval THEN |
| -- Source code from https://github.com/CartoDB/crankshaft/blob/develop/src/pg/sql/30_dot_density.sql | |
| CREATE OR REPLACE FUNCTION cdb_dot_density(geom geometry , no_points Integer, max_iter_per_point Integer DEFAULT 1000) | |
| RETURNS GEOMETRY AS $$ | |
| DECLARE | |
| extent GEOMETRY; | |
| test_point Geometry; | |
| width NUMERIC; | |
| height NUMERIC; | |
| x0 NUMERIC; | |
| y0 NUMERIC; |
The following are examples of the four types rate limiters discussed in the accompanying blog post. In the examples below I've used pseudocode-like Ruby, so if you're unfamiliar with Ruby you should be able to easily translate this approach to other languages. Complete examples in Ruby are also provided later in this gist.
In most cases you'll want all these examples to be classes, but I've used simple functions here to keep the code samples brief.
This uses a basic token bucket algorithm and relies on the fact that Redis scripts execute atomically. No other operations can run between fetching the count and writing the new count.
| CREATE OR REPLACE FUNCTION tile (z integer, x integer, y integer, query text) RETURNS TABLE(id int8, geom geometry) | |
| AS $$ | |
| DECLARE | |
| sql TEXT; | |
| BEGIN | |
| sql := 'with _conf as ( | |
| select | |
| CDB_XYZ_resolution(' || z || ') as res, | |
| 1.0/CDB_XYZ_resolution(' || z || ') as invres, | |
| st_xmin(CDB_XYZ_Extent(' || x || ',' || y || ',' || z ||')) as tile_x, |
What makes OpenClaw powerful is surprisingly simple: it's a gateway that connects an AI agent to your messaging apps, gives it tools to interact with your computer, and lets it remember who you are across conversations.
The complexity comes from handling multiple channels simultaneously, managing persistent sessions, coordinating multiple agents, and making the whole thing reliable enough to run 24/7 on your machine.
In this post, I'll start from scratch and build up to OpenClaw's architecture step by step, showing how you could have invented it yourself from first principles, using nothing but a messaging API, an LLM, and the desire to make AI actually useful outside the chat window.
End goal: understand how persistent AI assistants work, so you can build your own.