Skip to content

Instantly share code, notes, and snippets.

View mrchrisadams's full-sized avatar

Chris Adams mrchrisadams

View GitHub Profile
@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")
@mrchrisadams
mrchrisadams / traceback-hint-overloaded-method-toArray.txt
Created March 21, 2020 08:40
tracesbacks when using perun for the first time
boot --help ⏎
SLF4J: Failed to load class "org.slf4j.impl.StaticLoggerBinder".
SLF4J: Defaulting to no-operation (NOP) logger implementation
SLF4J: See http://www.slf4j.org/codes.html#StaticLoggerBinder for further details.
boot.App.main App.java: 500
boot.App.runBoot App.java: 407
org.projectodd.shimdandy.impl.ClojureRuntimeShimImpl.invoke ClojureRuntimeShimImpl.java: 145
org.projectodd.shimdandy.impl.ClojureRuntimeShimImpl.invoke ClojureRuntimeShimImpl.java: 154
...
boot.main/-main main.clj: 216
@mrchrisadams
mrchrisadams / Senior-Manager-Sustainability-Product-Innovation.md
Created December 16, 2019 10:37
Interesting MS sustainability tech roles, without the sign in guff

Senior Manager, Sustainability Product Innovation

Redmond, Washington, United States

  • Job number 742615
  • Date posted Nov 15, 2019
  • Travel 0-25 %
  • Profession Business Programs & Operations
  • Role type Individual Contributor
  • Employment type Full-Time