Skip to content

Instantly share code, notes, and snippets.

View asimpletune's full-sized avatar

Spencer Scorcelletti asimpletune

View GitHub Profile
@asimpletune
asimpletune / semantic.html
Created December 28, 2023 15:42
An example of 'semantic HTML' for optimizing a website article for 'Reader Mode', e.g. in Safari and Firefox
<!doctype html>
<html lang="en">
<head>
<title>Semantic HTML for "reader mode"</title>
<meta name="description" content="For an example visit https://spenc.es/writing">
</head>
<body>
<header>
@asimpletune
asimpletune / _middleware.ts
Created December 5, 2023 19:21
Cloudflare Pages' Basic Auth Middleware
async function errorHandling(context) {
try {
return await context.next();
} catch (err) {
return new Response(`${err.message}\n${err.stack}`, { status: 500 });
}
}
/**
* Parse HTTP Basic Authorization value.
@asimpletune
asimpletune / filter_md.html
Created November 29, 2023 23:57
A macro in Tera (for Zola) to only permit a subset of markdown to become HTML
{#
This macro is for removing desired html tags from markdown. You pass it literal text that is markdown, and it will remove the desired tags. There's an optional `allow_html` parameter that defaults to `false`. This controls whether to permit html that is mixed with markdown.
Note: you MUST store the result as a variable, before evaluating it as an expression, i.e. with the {{ }} syntax.
Otherwise, you will always get a string representation of the HTML. For some reason, saving the string, then evaluating
the expression doesn't have that issue.
TODO: file a bug. Case to reproduce is {{ filter_md(md, ["h1"]) }} does not work, but saving as a variable and then doing it does.
#}
{% macro filter_md(md, allow_html=false, disallow) %}
@asimpletune
asimpletune / util.html
Created November 27, 2023 18:10
Zola macro for detecting if website is running in Cloudflare Pages or not, and to substitute a cloudflare pages URL for a canonical one
{# This macro will provide the canonical URL if running in production, see 'private' below #}
{%- macro cf_url_to_canonical() -%}
{{ self::cf_url_to_canonical_private() | trim }}
{%- endmacro -%}
{# Note: 'private' because this macro leaves space, so it's trimmed in the 'public' version #}
{% macro cf_url_to_canonical_private() %}
{# https://developers.cloudflare.com/pages/platform/build-configuration/#environment-variables #}
{% set CF_PAGES = get_env(name="CF_PAGES", default="0") %}
@asimpletune
asimpletune / fig_cite.html
Last active November 25, 2023 22:02
Zola shortcode for inserting a figure + citation within your markdown
{# The following is a shortcode that extracts parameters from a markdown-style image #}
{# The usage is as follows (`cite` is optional) #}
{# {{ fig(img='![alt](src "title")', cite='<a href="">author</a>, by source') }} #}
{# `title` will be reused as caption if it exists, if no `title` but there is `cite` then just "Citation:" will appear #}
{# NOTE: it's advised to just use backticks for passing arguments, so that single and double quotes don't cause issues, e.g. using a possesive apostrophe or quotes in a caption #}
{% set img_tag = img | markdown %}
{% set src = img_tag | split(pat="src") | nth(n=1) | split(pat='"') | nth(n=1) %}
{% set alt = img_tag | split(pat="alt") | nth(n=1) | split(pat='"') | nth(n=1) %}
@asimpletune
asimpletune / CHANGELOG.md
Created June 29, 2023 11:02
Changelog Template

Changelog

v1.0.2 (2023-06-03)

  • add simple nav's for selecting/changing preferred language
  • add multilingual support

v1.0.1 (2023-05-18)

  • add a row to a an error table if there's a problem during waitlist signup
### Keybase proof
I hereby claim:
* I am asimpletune on github.
* I am asimpletune (https://keybase.io/asimpletune) on keybase.
* I have a public key ASDJM-8dqDzyPa_Xp-S7mCTbdmY-xomeTC87P4ux-n3KJgo
To claim this, I am signing this object:
@asimpletune
asimpletune / .bash_profile
Last active October 21, 2015 17:39
.bash_profile
export PS1="\[\033[36m\]\u\[\033[m\]@\[\033[32m\]\h:\[\033[33;1m\]\w\[\033[m\]\$ "
@asimpletune
asimpletune / bash-stuff.md
Created August 10, 2015 18:48
Bash stuff

Preferred shebang

#!/usr/bin/env bash
@asimpletune
asimpletune / abs-diagonal-difference.js
Created August 4, 2015 06:41
Absolute Diagonal Difference
function processData(input) {
var tokenized = input.split("\n").slice(1).map(function(current) { return current.split(/\s/); }), count = 0;
var l2R = tokenized.reduce(function(total, current) { return Number(total) + Number(current[count++]); }, 0);
var r2L = tokenized.reduce(function(total, current) { return Number(total) + Number(current[--count]); }, 0);
console.log(Math.abs(l2R -r2L));
}