Skip to content

Instantly share code, notes, and snippets.

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 February 24, 2018 16:36
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.
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 June 27, 2017 21:19
Code from Deutschland 83 episode 3
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$=""
@jgrahamc
jgrahamc / dreamon.c
Created June 26, 2017 19:51
Code from Silicon Valley S03E01
#include <stdio.h>
#include <stdlib.h>
typedef unsigned long u64;
typedef void enc_cfg_t;
typedef int enc_cfg2_t;
typedef __int128_t dcf_t;
enc_cfg_t _ctx_iface(dcf_t s, enc_cfg2_t i) {
@jgrahamc
jgrahamc / thereturn.bas
Created June 19, 2017 14:43
Snippet of code from the 1980 film "The Return"
10 DIM P(10): T$="TTT": I$="I": SC=0:SP$=" "
20 P(0)=10:P(1)=150:P(2)=100:P(3)=200:P(4)=50:P(5)=180:P(6)=120:P(7)=220:P(8)=60:P(9)=90
30 HGR2
40 FOR Y = 0 TO 9: GOSUB 900: NEXT: END
900 GOSUB 920 : FOR X = 140 TO P(Y) STEP 6 * SGN(P(Y)-140): HCOLOR = 0: HPLOT X1, 170 TO X1, 155: HCOLOR = 7: HPLOT X, 170 TO X, 155: HPLOT 140, 170 TO 140, 155: HPLOT 140, 163 TO X, 163: X1 = X: NEXT : GOSUB 920
910 FOR X = P(Y) TO 140 STEP 6 * SGN(140-P(Y)): HCOLOR = 0: HPLOT X1, 170 TO X1, 155: HPLOT X, 163 TO X1, 163: HCOLOR = 7 : HPLOT X, 170 TO X, 155 : X1 = X: NEXT: GOSUB 920: RETURN
920 SC = SC + 1: IF SC > 4 THEN SC = 0
930 PRINT T$; SC; I$; : PRINT LEFT$(SP$, RND(1) * 10 + 1);: PRINT I$;: RETURN
@jgrahamc
jgrahamc / knightrider.bas
Created May 12, 2017 20:31
Code used in episodes 2 and 10 of season 3 of Knight Rider
1 SPEED= 240
50 HOME
55 INPUT "";W$
70 HTAB 9
82 HTAB 9
85 PRINT
90 FOR A = 1 TO 30
100 R = RND (9)
140 HTAB 1
150 PRINT SIN (R),
@jgrahamc
jgrahamc / airwolf.bas
Created May 9, 2017 18:00
AppleSoft BASIC program used in Airwolf S02E03 "Moffett's Ghost"
1 PP=2
10 HOME
12 PRINT
20 A$ = "0123456789ABCDEF"
30 FOR I = 1 TO 19
31 IF I = 9 THEN GOSUB 1000
40 L$ = ""
45 FOR J = 1 TO 9
50 L1 = INT ( RND (1) * 15 ) + 1: L2 = INT ( RND (1) * 15 ) + 1
60 L$ = L$ + MID$ (A$,L1,1) + MID$(A$,L2,1) + ": "
@jgrahamc
jgrahamc / index.php
Last active June 18, 2020 09:38
Demonstrating how to use Link headers to make CloudFlare push assets
<?php
function ccbysa($imagehtml, $sourceuri, $owneruri, $ownername) {
return <<<HTML
{$imagehtml}
<br/>
<small><a href="https://creativecommons.org/licenses/by-sa/2.0/">CC BY-SA</a>
<a href="{$sourceuri}">image</a> by <a href="{$owneruri}">{$ownername}</a>
<br/>
HTML;
@jgrahamc
jgrahamc / seti.pl
Created May 6, 2016 11:08
Small perl program to read the SETI Decrypting Challenge binary data and output PNG files
# http://phl.upr.edu/library/notes/SETIChallenge
use strict;
use warnings;
use GD;
my @seti;
my $in = 'SETI_message.txt';
open S, "<$in" or die "Failed to open $in";

Keybase proof

I hereby claim:

  • I am jgrahamc on github.
  • I am jgrahamc (https://keybase.io/jgrahamc) on keybase.
  • I have a public key ASCYBDOIZyzosDOYJlurgIvmBkUPYwCCcRaUOElhCFSkZAo

To claim this, I am signing this object: