Skip to content

Instantly share code, notes, and snippets.

View flashspi.ino
// 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
View arduinoisp.diff
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);
@jgrahamc
jgrahamc / knightrider.bas
Created May 12, 2017 20:31
Code used in episodes 2 and 10 of season 3 of Knight Rider
View knightrider.bas
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 / loc_parser.go
Created March 27, 2014 13:43
DNS LOC textual record parser
View loc_parser.go
// loc_parser: functions to parse the textual part of a LOC record
// stored in our DNS. The key function here is parseLOCString which
// should be passed a dns.LOC and a string containing the latitude,
// longitude etc.
//
// This is an implementation of RFC 1876. Read it for background as
// the format in a dns.LOC is slightly unusual.
//
// Copyright (c) 2014 CloudFlare, Inc.
View morseify.py
code = {
'01': 'A',
'1000': 'B',
'1010': 'C',
'100': 'D',
'0': 'E',
'0010': 'F',
'110': 'G',
'0000': 'H',
'00': 'I',
@jgrahamc
jgrahamc / airwolf.bas
Created May 9, 2017 18:00
AppleSoft BASIC program used in Airwolf S02E03 "Moffett's Ghost"
View airwolf.bas
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 / dreamon.c
Created June 26, 2017 19:51
Code from Silicon Valley S03E01
View dreamon.c
#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 / seti.pl
Created May 6, 2016 11:08
Small perl program to read the SETI Decrypting Challenge binary data and output PNG files
View seti.pl
# 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";
@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.
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 / index.php
Last active June 18, 2020 09:38
Demonstrating how to use Link headers to make CloudFlare push assets
View index.php
<?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;