Skip to content

Instantly share code, notes, and snippets.

@austinjp
austinjp / README.md
Last active April 1, 2023 14:17
A silly deterministic shuffle.

Just a note-to-self to prevent me from reinventing the wheel again.

A shuffle that always produces a predictable output.

e.g.

>>> x = [0,1,2,3,4,5,6,7,8,9]
>>> dshuffle(x)
[7, 8, 1, 5, 3, 4, 2, 0, 9, 6]
@austinjp
austinjp / a-test.py
Last active December 22, 2021 10:28
Pony ORM with SQLite uses shorthand foreign key syntax instead of explicit
#!/usr/bin/env python
from pony.orm import Database, Optional, Required, Set
db = Database()
@db.on_connect(provider="sqlite")
def pragmas(db, connection):
cursor = connection.cursor()
cursor.execute('PRAGMA foreign_keys = true')
-- Extension of answer by Tarleb on Stackoverflow (https://stackoverflow.com/a/52131435/3888000) to include docx section ends with portrait/landscape orientation changes.
-- Also uses officer package syntax to create sections breaks
local function newpage(format)
if format == 'docx' then
local pagebreak = '<w:p xmlns:w=\"http://schemas.openxmlformats.org/wordprocessingml/2006/main\" xmlns:wp=\"http://schemas.openxmlformats.org/drawingml/2006/wordprocessingDrawing\" xmlns:r=\"http://schemas.openxmlformats.org/officeDocument/2006/relationships\" xmlns:w14=\"http://schemas.microsoft.com/office/word/2010/wordml\"><w:r><w:br w:type="page"/></w:r></w:p>'
return pandoc.RawBlock('openxml', pagebreak)
else
return pandoc.Para{pandoc.Str '\f'}
end
BEGIN MESSAGE.
gnXvwmSxwM9nDQY 6wQ0wgkEAMtRn1B 8gZHsOpAs8O09Af bbQW6dUqGEWpPT4
olQ3eL4ub5vEAsP eQVBjkLJSSNTCKq 6Xr2MZHgg4cAxZ3 xGkRmNk1xNLoRNk
ArYOC4c44CCQvgd ZdKEsIaBTwqJaV1 0XbOp0OoYtB8QuL kPyqSfNCfRHyLPC
8BrwHFbhag1VAwy 0OvLQs5T0rhkyWp uwoxJ0Qz5Z.
END MESSAGE.
! 2023-03-30 https://www.youtube.com
www.youtube.com###secondary
www.youtube.com##.ytd-popup-container.style-scope > .yt-mealbar-promo-renderer.style-scope
www.youtube.com###comments > .ytd-comments.style-scope
www.youtube.com###actions
www.youtube.com###subscribe-button > .ytd-watch-metadata.style-scope
! 2023-04-01 https://www.theguardian.com
www.theguardian.com##body > .dcr-1uyetce
www.theguardian.com##main > .dcr-v339xn
@austinjp
austinjp / openpgp.md
Last active July 5, 2023 13:13
openpgp.md

openpgp4fpr:C70D98C80C6F4A7FB4A8CC6D5DED1B0FE6F13374

@austinjp
austinjp / Automatic aliases in bash.md
Last active July 4, 2025 10:02
Automatic aliases in bash

I use direnv to automatically set environment variables per directory. It's great, but there's no elegant solution for aliases with direnv. So I rolled my own, inspired by this answer on Ask Ubuntu.

Add a few lines to your .bashrc and place custom aliases into a .aliases file in any directory. Those aliases will be set when you enter that dir, and unset when you leave.

It's certainly not perfect and there are doubtless some gotchas, but it's pretty handy.

Add the following to your .bashrc so whenever you start a shell, it will load the .aliases file in whichever dir your shell has started. You should add it somewhere after your other aliases are defined/loaded.