Skip to content

Instantly share code, notes, and snippets.

View mrchrisadams's full-sized avatar

Chris Adams mrchrisadams

View GitHub Profile
@mrchrisadams
mrchrisadams / devcontainer.json
Last active November 13, 2024 09:25
codespaces do not seem to respect new features added when building. this is me troubleshooting
{
"// filepath-in-my-repo": ".devcontainer/devcontainer.json",
"image": "mcr.microsoft.com/devcontainers/universal:2",
"features": {
"ghcr.io/jsburckhardt/devcontainer-features/uv:1": {},
"ghcr.io/eitsupi/devcontainer-features/just:0": {}
}
}
@mrchrisadams
mrchrisadams / local-llm-with-ollama.md
Last active October 13, 2024 20:21
Experimenting with getting a chat interface running with a local LLM using Marimo. Run with marimo edit `local-llm-with-ollama.py`
title marimo-version width
Local Llm With Ollama
0.9.1
medium
import marimo as mo
import llm
import markdown
@mrchrisadams
mrchrisadams / sizes-of-mariadb-tables.sql
Last active July 14, 2023 10:26
This command, when run in a MySQL compatible database like MariaDB will return a list of all the tables, in descending order of tables size in megabyes.
select table_schema as database_name,
table_name,
round(
sum((data_length + index_length + data_free)) / power(1024, 2),
2
) as table_size
from information_schema.tables
where table_schema = 'table_name' -- put your database name here
and table_type = 'BASE TABLE'
group by table_schema,
@mrchrisadams
mrchrisadams / README.md
Last active November 29, 2023 12:50
How to do application level scale to zero with Gunicorn

What's this?

This is an experiment with making gunicorn gracefully scale down to zero after X seconds, as a way to do application-level scale-to-zero behaviour in applications that use a webserver like Gunicorn. The idea here is that you do not need to mess too much internal logic of an existing application, nor put it in a container if you use this.

Instead you use the web server's own support for handling SIGTERM signals, to allow gracefully scaling down of processes when they are not in use.

If you're using Linux to run a server, the chances of Systemd being used to manage your processes is fairly high, as it's the default option for a number of linux distributions now.

It also means you might not need a complicated "serverless" system to orchestrate scaling up and down, to reclaim memory on a server for us in other tasks if you have a website or webservice that isn't continually serving traffic.

Grace for submission to the Regent House under Special Ordinance A (ii) 5 (fossil fuel industry ties)

21 July 2022

The Council has received the following Grace, which has been initiated under Special Ordinance A (ii) 5 by 84 members of the Regent House:

The University of Cambridge has a strong, stated commitment to addressing the climate crisis and to keeping global heating below a 1.5 degrees Celsius increase from pre‐industrial levels.

The University currently maintains research funding partnerships with major fossil fuel companies, including Shell and BP (https://www.cam.ac.uk/about‐research/energy‐sector‐partnerships).

@mrchrisadams
mrchrisadams / scion_optimise_for_co2.yml
Last active March 23, 2021 15:19
thought experiments for CO2 based opimised routing
co2_optimising_example:
- options:
- greenband
- latency_then_bandwidth
# optimise for carbon intensity. Choose ASs which have advertise
# a carbon intensity per hour of less than 300 grams of CO2 per
# KwH, either by being in a place where the grid is green (Iceland),
# or where they are bringing down their grid average by sourcing power
# from renewables, or a charged battery to avoid drawing power when
@mrchrisadams
mrchrisadams / if_only.py
Created January 24, 2021 16:24
SCION internet python pseudo code sample
import scion
scion.init()
paths = scion.get_paths(my_destination)
print(f'Got {len(paths)} paths')
my_path = my_choose_path(paths) # implement whatever you need
with scion.connect(my_destination, my_path) as s:
s.write(b'Hello SCION!')
<html>
<body>
<h1>Hello {{var:first_name:""}},</h1>
<p>
Welcome to Mailjet. This is an example of a templating
language message. This message contains variables and
nested loops (for .. endfor)! You could also embed
conditions (if .. else ..).
</p>
<ul>
@mrchrisadams
mrchrisadams / tea-arduino-and-dynamic-demand.md
Created May 15, 2020 10:19
Tea, Arduino and Dynamic Demand

It’s the next HomeCamp tomorrow. And in a spectacular feat of bad calendaring, I’ve managed to organise the Letter Lounge to take place on the day I’ve been looking forward to for the last few months are coming away from the initial HomeCamp, utterly inspired by what I saw there.

So to make up for not being able to attend, the least I can do is finally get round to writing about the Tealight, a fun, Homecampy little project James Gardner and I built one evening in the Hub recently.

We did it partly to learn about the Arduino platform, and partly to explore how to make something as complex as demand response intelligible to people who don’t think about this for a living, and well here it is, in all it’s janky, low budget hackish glory:

@mrchrisadams
mrchrisadams / core.clj
Last active April 3, 2020 08:36
I'm trying to learn to use clojure to parse a wordpress XML and generate markdown files for each one.
; add a basic namespace, I guess
(ns thingo.core)
(require '[clojure.java.io :as io])
(require '[clojure.xml :as xml])
(require '[clojure.zip :as zip])
(require '[clojure.data.zip.xml :as zip-xml])
(require '[clojure.pprint :refer pprint :as pp])
(def blog-file "./path-to-wordpress-export-file.xml")