Skip to content

Instantly share code, notes, and snippets.

View ThatGuySam's full-sized avatar
🍉
Discovering the wonders of JAMStack

Sam Carlton ThatGuySam

🍉
Discovering the wonders of JAMStack
View GitHub Profile
/* These types were generated messily by hand, and thus will probably not be the most intuitive, but they should be correct according to current Cloudflare DNS resolution Output. Pulled from the current CF DNS Spec at https://developers.cloudflare.com/1.1.1.1/encrypted-dns/dns-over-https/make-api-requests/dns-json */
declare type DNSJSON = {
/* The Response Code of the DNS Query. These are defined here: https://www.iana.org/assignments/dns-parameters/dns-parameters.xhtml#dns-parameters-6 */
Status: DNSRequestStatus,
/* If true, it means the truncated bit was set. This happens when the DNS answer is larger than a single UDP or TCP packet. TC will almost always be false with Cloudflare DNS over HTTPS because Cloudflare supports the maximum response size. */
TC: Boolean,
/* If true, it means the Recursive Desired bit was set. This is always set to true for Cloudflare DNS over HTTPS. */
RD: Boolean,
/* If true, it means the Recursion Available bit was set. This is always set to true for Cloudflare
<html>
<head>
<base href="https://gist.githubusercontent.com/nicolaslegland/f0577cb49b1e56b729a2c0fc0aa151ba/raw/" />
<title>QOI decoder</title>
<style>
a, img, li, ul
{
margin: 0;
padding: 0;
As noted by @murdats below, there are more URLs than just these 1440 ones, depending on the argument values
that are hashed (as the filenames below are MD5 hashes of a few arguments: red/blue pill color, HHMM time, etc.)
You can read details about the algorithm used to generate these URLs here:
https://news.ycombinator.com/item?id=28448335
---
00:00 https://thechoiceisyours.whatisthematrix.com/generated/v7/high/d43725991d28ffcab04aa716762cf6af.mp4
@wilsonpage
wilsonpage / swr.ts
Last active April 22, 2024 08:58
An implementation of stale-while-revalidate for Cloudflare Workers
export const CACHE_STALE_AT_HEADER = 'x-edge-cache-stale-at';
export const CACHE_STATUS_HEADER = 'x-edge-cache-status';
export const CACHE_CONTROL_HEADER = 'Cache-Control';
export const CLIENT_CACHE_CONTROL_HEADER = 'x-client-cache-control';
export const ORIGIN_CACHE_CONTROL_HEADER = 'x-edge-origin-cache-control';
enum CacheStatus {
HIT = 'HIT',
MISS = 'MISS',
REVALIDATING = 'REVALIDATING',
@tallguyjenks
tallguyjenks / code.sh
Last active August 22, 2023 19:55
ZettelKasten Sync Code
# To permanently cache the credentials
git config --global credential.helper store
# To ignore files that could cause issues across different workspaces
touch .gitignore
echo ".obsidian/cache
.trash/
.DS_Store" > .gitignore
@MoonTahoe
MoonTahoe / upload.yaml
Last active April 16, 2024 21:40
Github Action to build iOS app with expo and upload to testflight
# Just place this file in your repo under the .github/workflows folder.
# You set all of the secrets in the setting of the repo
name: Deploy to Testflight
# When a pull request is closed...
# This is because this action commits back to the repository
# so setting this on a push would cause an infinite loop of commits
# unless you pragmatically check the contents of the repo or something
@ThatGuySam
ThatGuySam / wp-env-color-scheme.php
Last active July 28, 2022 21:26
Set custom admin color scheme for your local Wordpress environment
<?php
// Force Color Scheme for environments
// so that you're less likely to accidentally
// make a DEV update to a Production WordPress
// instance.
add_filter( 'get_user_option_admin_color', 'update_user_option_admin_color', 5 );
function update_user_option_admin_color( $color_scheme ) {
if (defined('WP_LOCAL_DEV') && WP_LOCAL_DEV) return 'ocean';
@v1vendi
v1vendi / api_generator.js
Created August 20, 2019 19:19
REST API functional generator
const fetch = (...args) => console.log(...args) // mock
function httpRequest(url, method, data) {
const init = { method }
switch (method) {
case 'GET':
if (data) url = `${url}?${new URLSearchParams(data)}`
break
case 'POST':
case 'PUT':
case 'PATCH':

How to setup a practically free CDN using Backblaze B2 and Cloudflare

⚠️ Note 2023-01-21
Some things have changed since I originally wrote this in 2016. I have updated a few minor details, and the advice is still broadly the same, but there are some new Cloudflare features you can (and should) take advantage of. In particular, pay attention to Trevor Stevens' comment here from 22 January 2022, and Matt Stenson's useful caching advice. In addition, Backblaze, with whom Cloudflare are a Bandwidth Alliance partner, have published their own guide detailing how to use Cloudflare's Web Workers to cache content from B2 private buckets. That is worth reading,

@ThatGuySam
ThatGuySam / shortcode-class.php
Created May 16, 2019 14:52
Wordpress Shortcode Class
<?php
class Cool_Shortcode_Name {
static $add_script;
static function init() {
add_shortcode('cool_shortcode_name', array(__CLASS__, 'handle_shortcode'));
add_action('init', array(__CLASS__, 'register_script'));