Skip to content

Instantly share code, notes, and snippets.

@austinjp
austinjp / Automatic aliases in bash.md
Last active June 23, 2025 14:47
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 anser on Ask Ubuntu.

Add a few lines to your .bashrc and your .bash_aliases 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.

@austinjp
austinjp / openpgp.md
Last active July 5, 2023 13:13
openpgp.md

openpgp4fpr:C70D98C80C6F4A7FB4A8CC6D5DED1B0FE6F13374

! 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
BEGIN MESSAGE.
gnXvwmSxwM9nDQY 6wQ0wgkEAMtRn1B 8gZHsOpAs8O09Af bbQW6dUqGEWpPT4
olQ3eL4ub5vEAsP eQVBjkLJSSNTCKq 6Xr2MZHgg4cAxZ3 xGkRmNk1xNLoRNk
ArYOC4c44CCQvgd ZdKEsIaBTwqJaV1 0XbOp0OoYtB8QuL kPyqSfNCfRHyLPC
8BrwHFbhag1VAwy 0OvLQs5T0rhkyWp uwoxJ0Qz5Z.
END MESSAGE.
-- 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
@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')
@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 / papers_by_fos.py
Created November 19, 2020 18:13 — forked from jaklinger/papers_by_fos.py
Get papers from Open Academic Graph by FOS
import pandas as pd
from sqlalchemy import create_engine
from sqlalchemy.sql import text as sql_text
from collections import defaultdict
with open('/Users/jklinger/Nesta-AWS/AWS-RDS-config/open-academic-graph.config') as f:
host, port, database, user, password = f.read().split(':')
database_uri = 'postgresql://{}:{}@{}/{}'.format(user, password, host, "microsoft_academic_graph")
con = create_engine(database_uri)
@austinjp
austinjp / signtext.js
Created September 24, 2020 14:34 — forked from Glamdring/signtext.js
WebCrypto API electronic signature
<html>
<head>
<script type="text/javascript">
function sign(input, password) {
// salt should be Uint8Array or ArrayBuffer
var saltBuffer = str2ab('e85c53e7f119d41fd7895cdc9d7bb9dd');
// don't use naive approaches for converting text, otherwise international
// characters won't have the correct byte sequences. Use TextEncoder when
// available or otherwise use relevant polyfills
BEGIN MESSAGE.
pNDvwhystUSfREk 6CZlgP5pDbEthDx kgJ3uLpwjCHE6L5 ZkhZXiR3iEMwvdk
Knc3lRi7AIRtdkn f7U6NZcbzpbTCKq 6Xr2MZHgg6ZqWjy Abevu3bUnOUBioP
IiYKZkK9uN6KORI H0iHRG4SavIZXan 1C7Sab8tHSIjkDI X8YTHeED989atrc
SxK4zyOwyNZfQdJ 8PF4ggKvsPkonSH XC4Ht0Qz5Z.
END MESSAGE.