Skip to content

Instantly share code, notes, and snippets.

View christianp's full-sized avatar

Christian Lawson-Perfect christianp

View GitHub Profile
@christianp
christianp / seq.py
Created July 30, 2024 08:35
It just makes the natural numbers
class NegativeStep(Exception):
pass
def countdown(n,step=0):
if n==0:
return [0]
if n<0:
raise NegativeStep()
for d in range(-1,2):
@christianp
christianp / README.md
Last active July 27, 2023 09:09
Numbas LTI show request headers on "not SEB launch" page

Instructions

  • Put seb_show_headers.patch in your numbas-lti-provider directory.
  • Run git apply seb_show_headers.patch.
  • Run supervisorctl restart numbas_lti:

When you launch a Numbas exam through SEB, the "Not launched by Safe Exam Browser" page will show you the page's URI, all request headers, and all GET and POST data.

There should be a header called X-Safeexambrowser-Configkeyhash which is the sha-256 created by concatenating the request URI and the SEB config key.

@christianp
christianp / def.tex
Created July 17, 2023 13:50
Chirun macro loading issue when \input doesn't have curly braces
\newcommand{\clp}{Christian Lawson-Perfect}
\newcommand{\twopi}{2\pi}
@christianp
christianp / circular-lights-out-codepen.py
Last active June 2, 2023 09:35
Explore the full space of states accessible in the Circular Lights Out puzzle. It can be solved if every light can be turned on at the same time.
# The other set of rules, implemented at https://codepen.io/xenohunter/full/GRpaKjR
# You can flip any three adjacent lights.
def find_all_states_12_lamps(num_lights):
reachable = set()
# Sets of lights that can be changed simultaneously
change_sets = [((i+num_lights-1)%num_lights, i, (i+1)%num_lights) for i in range(num_lights)]
queue = [tuple([True]+[False]*(num_lights-1))]
@christianp
christianp / birthday-thirds.ipynb
Created May 2, 2023 08:48
Jupyter notebook answering the question: which way of splitting people up in three groups by something to do with their birth date produces the most evenly-sized groups?
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
@christianp
christianp / christmas_stocking.lean
Last active December 22, 2022 18:07
A proof of the Christmas stocking theorem in Lean
import data.nat.choose
import data.finset
import algebra.big_operators.basic
open finset
open_locale big_operators
/- The Christmas stocking theorem:
- If you start at any point on the edge of the binomial coefficients triangle and
@christianp
christianp / numbas_attempt_question_order.py
Created October 31, 2022 13:00
Get the order of questions shown in each attempt of a Numbas LTI attempt data dump
"""
Get the order of questions shown in each attempt of a Numbas LTI attempt data dump.
Prints a CSV file, with a header row and a row for each attempt.
The first column is the ID of the attempt, and subsequent columns represent each of the questions, in the order they appear in the editor. The value in the column for a particular question gives the index at which that question appeared in that attempt.
"""
import sys
import csv
import json
@christianp
christianp / five-times-square.eukleides
Created January 5, 2022 16:04
Constructing a square with area 5
let(
middle, point(3/2,3/2),
t, point(0,1)..point(2,1)..point(2,0),
t2, point(0,1)..point(2,0)..point(0,0),
colors, qualitative_color_schemes(5)[0],
eukleides("A 3×3 grid of squares. The middle square is filled in, and the 2×1 rectangles around it each have half filled in. The filled-in shapes together make a square whose corners touch the edges of the grid.",
[
map(x filled color, [x,color], zip(iterate(rotate(tri,middle,deg(90)),tri,t,3), colors))
, map(x filled color opacity(0.3), [x,color], zip(iterate(rotate(tri,middle,deg(90)),tri,t2,3), colors))
@christianp
christianp / README.md
Created August 25, 2020 11:52
Mastodon LaTeX preview

This patch applies on top of the mathstodon branch maintained by christianp. It's only useful if you have something rendering LaTeX inside status content. The mathstodon branch uses MathJax for this.

You need a copy of MathJax 3 in the folder public/MathJax.

Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.