Javascript: Parsing query parameters

There are at least 2×3 thigs you could mean by "parsing" a query string (do you want a Map, or an Object? how do you want duplicate keys handled?) Here's all those: function parse_qs_map(search=window.location.search) { let qs = search.match(/^\??(.*)$/)[1]; let params = qs.split('&'); let params_array = params.map(s => { let [key, value] = s.match(/^(.*?)(?:=(.*))?$/).slice(1); key…

WordPress: Restrict MathJax to a class

I write on a variety of topics, only some of which it's appropriate to have mathematical typesetting for. To avoid triggering a math rendering engine on unrelated use of $spurious dollar signs$, while activating it when $\text{necessary}\wedge\text{appropriate}$, I decided to restrict them to only elements with .language-mathjax. Here's how that's done: MathJax = { tex:…

Converting SVG to .ico with Python

Just a super rudimentary script that I made which hooks CairoSVG up to Pillow because apparently Firefox doesn't support SVG-formatted browserAction images: import cairosvg.surface from PIL import Image from io import BytesIO def svg2ico(*args, resolutions={96, 48, 32, 24, 16}, write_to=None, **kwargs): t = cairosvg.surface.Tree(*args, **kwargs) ims = [] for res in resolutions: cairosvg.surface.PNGSurface(t, f:=BytesIO(), res…

Applying highlight.js to inline code on WordPress

If you're using the plugin Prismatic to apply highlight.js to your code excerpts, but you want it to also affect inline <code> tags (i.e. those not wrapped in <pre> blocks), simply go Settings > Prismatic > Highlight.js and paste this monster into the “Init Script” field: // This init script was written by James E.…

Parsing the HTTP "Date" header in Python

As per RFC 7231 §7.1.1.1: A recipient that parses a timestamp value in an HTTP header field MUST accept all three HTTP-date formats. These formats are then described as (with the first being the only preferred format; the latter 2 are designated as "obsolete"), converted for this post into strftime(3) syntax: %a, %d %b %Y…