Skip to content

Instantly share code, notes, and snippets.

// flashspi
//
// Small program to use with Arduino to connect to an SPI
// flash chip using the SPIMemory library. This program
// provides an interface over the serial connection at 115200
// baud that supports the following commands:
//
// id - prints the JEDEC, manufacturer and unique ID
// cap - prints the flash chip's capacity in bytes
// dump - dumps the entire chip in hex (xxd format)
@jgrahamc
jgrahamc / arduinoisp.diff
Created September 18, 2022 15:06
Added 8Mhz clock on pin 9 to ArduinoISP
74c74
< #define LED_HB 9
---
> // #define LED_HB 9
96c96
< #define LED_HB 7
---
> // #define LED_HB 7
231,232c231,241
< pinMode(LED_HB, OUTPUT);
code = {
'01': 'A',
'1000': 'B',
'1010': 'C',
'100': 'D',
'0': 'E',
'0010': 'F',
'110': 'G',
'0000': 'H',
'00': 'I',
@jgrahamc
jgrahamc / terminator.cob
Created April 13, 2020 17:10
COBOL code appearing in The Terminator (1984)
IDENTIFICATION DIVISION.
PROGRAM-ID. ADD.
ENVIRONMENT DIVISION.
DATA DIVISION.
WORKING-STORAGE SECTION.
77 IDX PICTURE 9999.
77 SUMX PICTURE 999999.
77 X PICTURE X.
PROCEDURE DIVISION.
BEGIN.
@jgrahamc
jgrahamc / totoro.lua
Created March 8, 2020 20:52
Update version to work in Portugal using the IPMA API
-- totoro.lua
--
-- Small program to get the weather forecast for a location and turn
-- on two LEDs that will illuminate Totoro's eyes if it is going to
-- rain, hail or snow today
--
-- Copyright (c) 2017-2020 John Graham-Cumming
local config = require("totoro-config")
@jgrahamc
jgrahamc / knuth.py
Created August 13, 2019 17:52
Implementation of Knuth's bad random number generator from TAOCP Volume 2, Chapter 3
ten5 = 100000
ten8 = 100000000
ten9 = 1000000000
ten10 = 10000000000
def krng(x):
iterations = x/ten9 + 1
while iterations > 0:
step = (x/ten8) % 10 + 3
@jgrahamc
jgrahamc / collage.py
Created August 8, 2019 11:53
Create a random photo collage from a directory of square photographs (all the same size)
# Makes a collage image from a directory full of images
#
# Assumes all the images are the same size and square
from os import listdir
from PIL import Image
import random
import math
images = listdir('.')
// Draw all clock faces where the hands are symmetrically placed either side of the
// vertical 12<->6 line
void setup() {
size(720, 480);
// r is each clock's radius
// f is a fudge factor used to make space between the clocks
int r = 50;
int f = 10;
addEventListener('fetch', event => {
event.respondWith(handleRequest(event.request))
})
async function handleRequest(request) {
const response = await fetch("https://csprng.xyz/v1/api?length=10")
if (response.status != 200) {
return response
}
addEventListener('fetch', event => {
event.respondWith(getLogarithm(event))
})
async function getLogarithm(event) {
const url = new URL(event.request.url)
if (!url.searchParams.has("int")) {
return new Response("Missing query parameter 'int'", {status: 403})
}