Skip to content

Instantly share code, notes, and snippets.


Joseph Hewitt JosephHewitt

View GitHub Profile

Keybase proof

I hereby claim:

  • I am josephhewitt on github.
  • I am jhewitt_net ( on keybase.
  • I have a public key ASDDJXFEDHbW4ea0zVinM_BP0hU27bV6CtJSkRhCeRUBWQo

To claim this, I am signing this object:

JosephHewitt /
Created Jul 3, 2020
An example of a badly implemented random numerical ID generator based on ord() and os.urandom()
#!/usr/bin/env python3
This code snippet is a deliberate bad implementation of a random numerical ID generator based on ord()
This will generate 150000 random 18-digit IDs and then show the frequency of each digit in the IDs.
You should see more 1s and 2s than other digits.
ord(os.urandom(1)) will return a random number up to 255. If you generate multiple values and concatenate them,
you will get a random code/ID up to the length you want, however, because ord is returning an int which is <255,
you will statistically get more 1s and 2s in your ID.
JosephHewitt / cloudflare_worker.js
Last active Nov 20, 2021
Cloudflare Worker JS code to cache Wordpress HTML for logged-out users.
View cloudflare_worker.js
/*I make no guarantees this code will work reliably. Use at your own risk. Please thoroughly test before deploying.
Enabling this on a Cloudflare Worker for a Wordpress site should cache all HTML pages (if your origin headers allow that) but bypass the cache when a user is logged in.
This is tested and working on a Wordpress 5.0.2 installation and the free Cloudflare tier (but I make no guarentees it will work for anyone else).
Sets the `x-cfw-cache` header to indicate the Worker cache status (either HIT, MISS, NO, or BYPASS): `NO` = server has set cookies (won't cache) and `BYPASS` = client has cookies (bypassing cache).
addEventListener('fetch', event => {