Skip to content

Instantly share code, notes, and snippets.

View davewsmith's full-sized avatar

Dave Smith davewsmith

View GitHub Profile
@davewsmith
davewsmith / gist:a8a33e174ac495e99cdedc55f1ae015a
Created September 20, 2023 20:09
Silly spammer forgot to configure their spammy newsletter kit
Hi ,
Welcome!
Thanks for subscribing to [insert the name of your newsletter or “my email list”], !
Since you’re a subscriber, I’ll send you awesome content you can’t get from a Google search or anywhere else online. You’ll receive [insert email send cadence, such as daily, weekly, bi-weekly, monthly] emails with [insert the type of content you’ll send subscribers, such as blog posts, best practices, videos, podcasts, etc.].
[I/We] started [insert business name] because [insert the problem your business aims to solve for your audience]. [My/Our] mission is to help you [insert how you will help subscribers] by sharing best practices, tips, and tricks [I’ve/we’ve] learned through my/our own experiences.
"""
PM2.5 to AQI (Air Quality Index) conversion
This implements the formula in
https://www.airnow.gov/sites/default/files/2020-05/aqi-technical-assistance-document-sept2018.pdf
and uses category names and colors from there.
PurpleAir notes:
In the JSON blob returned from the PurpleAir API, the key 'pm2_5Value' appears
@davewsmith
davewsmith / sqlalchemy cascading delete oddity.md
Last active October 4, 2022 17:31
SQLAlchemy: `relationship` interferes with `cascade='DELETE'`

There's an oddity in SQLAlchemy foreign key support when you try to get deletes to cascade.

Here's a typical parent/child relationship. As coded, deleting a parent cascades to its children. (Since we're using SQLite3, we need to intervene to enable foreign key support, but that's an extraneous detail here. The Flask bits are due to this being extracted from a larger app.)

As coded you can't ask a parent for its children. For that, you need to enable one of (1) or (2). Form (1) appears in

@davewsmith
davewsmith / query_testbed.py
Last active August 1, 2019 20:13
Flask testbed for coaxing SQLAchemy into making the query that you know how to do in raw SQL
#!/usr/bin/env python3
"""
Test bed for flask-sqlalchemy queries
As in, "I know the SQL I want. Can I coax SQLAlchemy into giving it to me?"
"""
from contextlib import contextmanager
from app import create_app, db
@davewsmith
davewsmith / clean_twitter.js
Last active October 7, 2022 19:43
A bookmarklet for hiding both side columns of the new Twitter design. Uncluttered stream reading FTW
javascript:(function(){
var banner=document.querySelector('[role="banner"]');
if (banner && banner.firstElementChild !== null && banner.firstElementChild.firstElementChild !== null) {
banner.firstElementChild.firstElementChild.style='display:none';
}
var sc=document.querySelector('[data-testid="sidebarColumn"]');
if (sc && sc.firstElementChild !== null) {
sc.firstElementChild.style='display:none';
}
})()
@davewsmith
davewsmith / hide_trends.js
Created July 27, 2019 20:56
A bookmarklet to hide the Twitter Trends column
<!doctype html>
<html>
<head>
<title>Zip Test</title>
<style>
body {
color: #333;
font-size: 15px;
line-height: 15px;
font-family: sans-serif;