Skip to content

Instantly share code, notes, and snippets.

View christianp's full-sized avatar

Christian Lawson-Perfect christianp

View GitHub Profile
@christianp
christianp / everyones-a-mathematician.js
Created October 17, 2017 11:20
Everyone's a Mathematician bookmarklet
javascript:(function() {function textNodesUnder(el){ var n, a=[], walk=document.createTreeWalker(el,NodeFilter.SHOW_TEXT,null,false); while(n=walk.nextNode()) a.push(n); return a; }; var nodes=textNodesUnder(document.body); var lowercase = 'a-zàèìòùáéíóúýâêîôûãñõäëïöüÿçßøåæœ'; var uppercase = 'A-ZÀÈÌÒÙÁÉÍÓÚÝÂÊÎÔÛÃÑÕÄËÏÖÜŸÇØÅÆ'; var one_name = '['+uppercase+']['+lowercase+']+\\.?'; var re_name = new RegExp('((?:(?:'+one_name+'(?:-'+one_name+')*|(?:['+uppercase+']\\.)+)(?: (?:(?:['+uppercase+']\\.)+|'+one_name+'(?:-'+one_name+')*))* (?:(?:de|von|van|ibn) |(?:ibn )?al-|el-|d\')?'+one_name+'(?:-'+one_name+')*)|Euclid|Archimedes|Pythagoras|Brahmagupta|Eudoxus|Fibonacci|Aryabhata|Apollonius|Diophantus|Bháscara|Hipparchus|Archytus|Panini|Aristotle|Pappus|Hippocrates|Thales)','g'); Array.prototype.map.call(nodes,function(n){ n.textContent = n.textContent.replace(re_name,'Mathematician $1')}) })()
// Numbas version: exam_question_groups
{"name": "Single quote in .exam file", "extensions": [], "resources": [], "navigation": {"showfrontpage": false, "preventleave": false, "allowregen": true}, "question_groups": [{"pickingStrategy": "all-ordered", "questions": [{"statement": "<p>it's OK</p>", "variablesTest": {"maxRuns": 100, "condition": ""}, "extensions": [], "rulesets": {}, "variables": {}, "functions": {}, "metadata": {"licence": "None specified", "description": ""}, "preamble": {"css": "", "js": ""}, "name": "Single quote in .exam file", "tags": [], "parts": [], "variable_groups": [], "ungrouped_variables": [], "advice": ""}]}]}
@christianp
christianp / rounding-two-thirds-x.ipynb
Last active August 3, 2017 10:42
Find the points where "0.67*x" and "2/3*x" round to the same number to two decimal places, but "0.66*x" rounds to something else.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
<?php
function find_logs_without_strings($str) {
// this function finds log_<whatever>(, then searches forward until it finds the matching closing bracket.
// it calls itself on the contents of the brackets, so any nested logs are caught
// it doesn't deal with strings, or `log10`. It wouldn't be too hard to add, but the resulting code would be UGLY
$offset = 0;
$len = strlen($str);
while($offset<$len) {
if(preg_match("/log_([\S]+?)\(/",$str,$m,PREG_OFFSET_CAPTURE,$offset)) {
The following wordsearch grid contains some Christmas words. Clues run either left-to-right or top-to-bottom.
BUT: they've been encrypted! For each clue N+1, the grid is Vigenere-encrypted using clue N as the key.
For example, the first two rows of the grid when decrypted with the key EXAMPLE would be:
X R B X P Y A M M N I G V
S S A E N I D B M D H U C
The first clue is "CHRISTMAS". Find the next clue, and the next, and so on until you find CHRISTMAS in the grid.
As a bonus, each clue has a RED HERRING somewhere else in the grid.
T U B L A N W I P N W R K

These instructions will create a virtual machine in Vagrant, which runs the Numbas LTI provider proxied through nginx. If you want to run on a real machine, skip the first couple of steps to do with Vagrant. I used Ubuntu 16.04 - the process of installing packages will be different on different versions or different distributions.

I set up Vagrant to forward port 443 on the host machine to port 443 on the VM. I think this might only work on Windows. I'm not sure how to get it running on a different port - I had problems with the nginx proxy.

Create a directory for the vagrant VM:

mkdir numbas_lti
@christianp
christianp / morse-code-homonyms.ipynb
Created July 22, 2016 13:32
Homonyms in Morse code, if you forget the spaces
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
@christianp
christianp / geogebra.js
Created June 14, 2016 14:01
Numbas geogebra extension
Numbas.addExtension('geogebra',[],function(extension) {
window.geogebraIdAcc = window.geogebraIdAcc || 0;
var delay = 10;
var container;
$(document).ready(function() {
container = document.createElement('div');
container.setAttribute('id','numbasgeogebracontainer');
container.setAttribute('class','invisible');
document.body.appendChild(container);