Skip to content

Instantly share code, notes, and snippets.

Avatar

John Graham-Cumming jgrahamc

View GitHub Profile
@jgrahamc
jgrahamc / terminator.cob
Created Apr 13, 2020
COBOL code appearing in The Terminator (1984)
View terminator.cob
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 Mar 8, 2020
Update version to work in Portugal using the IPMA API
View totoro.lua
-- 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 Aug 13, 2019
Implementation of Knuth's bad random number generator from TAOCP Volume 2, Chapter 3
View knuth.py
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 Aug 8, 2019
Create a random photo collage from a directory of square photographs (all the same size)
View collage.py
# 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('.')
View symmetric_clock.java
// 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;
View lava.js
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
}
View babbage.js
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})
}
View gist:9811cdc25db6ea6226255e9f4913ff45
addEventListener('fetch', event => {
event.respondWith(getLogarithm(event.request))
})
async function getLogarithm(request) {
const url = new URL(request.url)
if (!url.searchParams.has("int")) {
return new Response("Missing query parameter 'int'", {status: 403})
}
@jgrahamc
jgrahamc / pwnd.js
Created Feb 24, 2018
Cloudflare Workers that adds an "Cf-Password-Pwnd" header to a POST request indicating whether the 'password' field appears in Troy Hunt's database of pwned passwords.
View pwnd.js
addEventListener('fetch', event => {
event.respondWith(fetchAndCheckPassword(event.request))
})
async function fetchAndCheckPassword(req) {
if (req.method == "POST") {
try {
const post = await req.formData();
const pwd = post.get('password')
const enc = new TextEncoder("utf-8").encode(pwd)
@jgrahamc
jgrahamc / ablearcher.bas
Created Jun 27, 2017
Code from Deutschland 83 episode 3
View ablearcher.bas
10 CLS
20 FOR I = 1 TO 64
30 FOR P = 1 TO 6
40 FOR Q = 1 TO 5
50 A=48+RND(1)*9
60 A$=A$+CHR$(A)
70 NEXT Q
80 A$=A$+" "
90 NEXT P
100 PRINT" ";A$:A$=""
You can’t perform that action at this time.