Skip to content

Instantly share code, notes, and snippets.

@danallison
danallison / with_sql_session.py
Last active April 23, 2024 07:32
Connect to Postgresql locally or through SSH tunnel
from sshtunnel import SSHTunnelForwarder
from sqlalchemy import create_engine
from sqlalchemy.orm import sessionmaker
from functools import wraps
# secrets.py contains credentials, etc.
import secrets
def get_engine_for_port(port):
return create_engine('postgresql://{user}:{password}@{host}:{port}/{db}'.format(
@danallison
danallison / cc2ld.py
Created May 16, 2018 21:28
A Python dictionary of second-level domains, keyed by country code. Useful when parsing URLs.
# https://en.wikipedia.org/wiki/Second-level_domain
# https://www.quackit.com/domain-names/country_domain_extensions.cfm
from collections import defaultdict
second_level_domains_by_country_code = defaultdict(set)
d = second_level_domains_by_country_code
# Afghanistan
d['af'] = set((
'com',
'edu',
@danallison
danallison / datetime_cycles.py
Created June 4, 2018 00:11
Get the cyclic properties of a datetime, represented as points on the unit circle.
from datetime import datetime
from math import sin, cos, pi
days_in_month = [31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31]
def sin_cos(n):
theta = 2 * pi * n
return (sin(theta), cos(theta))
def get_cycles(d):
Brain fog coping strategies
Intro: Playfulness and experimentation will help you find strategies that work for you.
Memory
Navigating your memory landscape (vs constructing memory palaces)
The problem with mnemonics
Mnemonic techniques (such as memory palaces) are powerful, but ...
Mnemonics only help when you know ahead of time exactly what you want to remember _and_ when writing it down is not sufficient _and_ when you have the time and energy to do the encoding
Very few cases meet this criteria
Memorizing foreign language vocabulary
Memorizing material for an exam