Skip to content

Instantly share code, notes, and snippets.

Alice Zoë Bevan–McGregor amcgregor

Block or report user

Report or block amcgregor

Hide content and notifications from this user.

Learn more about blocking users

Contact Support about this user’s behavior.

Learn more about reporting abuse

Report abuse
View GitHub Profile
@amcgregor
amcgregor / amcgregor-day-1.plan
Created Nov 12, 2019
Before Things, before Apple's Reminders, before all of this GTD enthusiasm, I had .plan files.
View amcgregor-day-1.plan
# Day one, everything is new.
+ Epic Projectico
+ First sub-task. (Some additional description for that task.)
+ Second sub-task.
@amcgregor
amcgregor / what-do-you-expect-to-happen.py
Last active Oct 29, 2019
Gut-feelings and code go together…
View what-do-you-expect-to-happen.py
# Here's a simple (and silly, but it's an example) function definition in Python:
def append(value, l=[]):
"""Append a value to a list, return that list."""
l.append(value)
return l
print(append(27)) # [27]
print(append(42)) # ?
@amcgregor
amcgregor / sample-a.py
Last active Oct 21, 2019
A comparison of various ways of (declaratively) defining classes whose attributes comprise instance fields.
View sample-a.py
from typeguard import typechecked
class Foo:
@typechecked
def __init__(self, name: str, age: int, gender: str = 'na'):
self.name = name
self.age = age
self.gender = gender
@amcgregor
amcgregor / self-rendering-models.py
Last active Oct 9, 2019
An example self-rendering model component.
View self-rendering-models.py
from marrow.mongo import utcnow
from marrow.mongo.trait import Identified
from marrow.mongo.field import Date, Markdown, Reference
from ..asset import Depend
__all__ = ('Note', )
@amcgregor
amcgregor / init-d--application.sh
Created Sep 16, 2019
An example extremely minimal and silly "init.d script".
View init-d--application.sh
#!/bin/bash
ENV=production
BASE=/home/application
cd ${BASE} # Could also slap /${ENV} on there, if that's how you're structuring.
# Activate the virtual environment. Alter to taste.
source ${BASE}/bin/activate
@amcgregor
amcgregor / xray.css
Last active Sep 30, 2019
"Xray CSS" to highlight element nesting and stacking.
View xray.css
body { background: black !important; }
body > * { background: #111 !important; }
body > * > * { background: #222 !important; }
body > * > * > * { background: #333 !important; }
body > * > * > * > * { background: #444 !important; }
body > * > * > * > * > * { background: #555 !important; }
body > * > * > * > * > * > * { background: #666 !important; }
body > * > * > * > * > * > * > * { background: #777 !important; }
body > * > * > * > * > * > * > * > * { background: #888 !important; }
body > * > * > * > * > * > * > * > * > * { background: #999 !important; }
@amcgregor
amcgregor / normalize.py
Last active Aug 29, 2019
Example Unicode normalization and sanitization for the purpose of "slugification" -- making URL-safe.
View normalize.py
import re
from unicodedata import category, combining, normalize as uninorm
from ftfy import fix_text # Needs library; pip install ftfy
def normalize(value, slug=False, fold=True, *, sep='-', elide='CMPSZ'):
"""Normalize and optionally "slugify" a given string.
This is very much a multi-step process, initially ensuring we have Unicode text in the first place,
@amcgregor
amcgregor / wsgi-sample.md
Last active Aug 12, 2019
A very, very brief explanation of the WSGI request/response flow.
View wsgi-sample.md

User's browser formualtes the following request:

GET / HTTP/1.1
Host: www.example.com

The request is parsed by something (FELB like Nginx, etc.) and passed through to the application process in some manner, e.g. HTTP reverse proxy, FastCGI binary socket, uWSGI, etc. Upon hitting the WSGI application, the Python side host reformulates the request:

@amcgregor
amcgregor / punt-ugly.js
Last active Aug 15, 2019
JavaScript / ES6 sufficient to polyfill missing window.console (wholesale, or specific missing methods), identify local development vs. production, squelch certain logging operations in production, and rote console interactions (in non-file: protocol environments) to the back-end server for archival, analytics, etc.
View punt-ugly.js
"use strict";!function(){const e=new RegExp("^"+["([^.].)+local","([^.].)+example","([^.].)+test","([^.].)+internal","([^.].)*localhost","127.0.0.1","::1"].join("|")+"$","i"),o="file:"==window.location.protocol||e.test(window.location.hostname),i=()=>{},n=(e,...o)=>{fetch(`/meta/collect/${e}`,{method:"POST",mode:"same-origin",cache:"no-cache",credentials:"same-origin",redirect:"error",referrer:"client",headers:{"Content-Type":"application/json"},body:JSON.stringify({args:o})})},t=["assert","clear","count","countReset","debug","dir","dirxml","error","exception","group","groupCollapsed","groupEnd","info","log","markTimeline","profile","profileEnd","table","time","timeEnd","timeLog","timeStamp","timeline","timelineEnd","trace","warn"],r=["debug","error","exception","info","log","table","trace","warn"],l=["debug","info","log"];var c=window.console=window.console||{},a={};for(let e of t)c[e]||(c[e]=i.bind(c));if(!o)for(let e of l)c[e]=i.bind(c);if("file:"!=window.location.protocol)for(let e of r)a[e]=c[e],l.includ
@amcgregor
amcgregor / 404.html
Last active Sep 26, 2019
My own HTML5 boilerplate sans most of the code. Because there's too much Romulus-be-damned boilerplate, and people fail to realize almost none of it is in any way needed. For more details than you probably wanted, ref: https://tomhodgins.hashnode.dev/code-that-you-just-never-ever-need-to-write-cjpblnfff00km0ys149kbttbg
View 404.html
<!DOCTYPE html>
<html lang="en">
<title>Page Not Found</title>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<h1>Page Not Found</h1>
<p>Sorry, but the page you were trying to view does not exist.</p>
You can’t perform that action at this time.