Skip to content

Instantly share code, notes, and snippets.

@jpf
jpf / signed-jwt-in-python.md
Last active February 17, 2024 15:07
JWTs signed with RS256 in Python: A demonstration of org-babel

Introduction

This is a guide to using pyjwt to sign and validate a JWT using RS256.

The trickiest part of doing this is knowing what the proper OpenSSL commands are to generate the RSA keypair. I demonstrate that below.

Generating RSA keys

@jpf
jpf / requirements.org
Last active November 2, 2023 05:29
What a requirements.txt file might look like in a literate program

#

@jpf
jpf / validate_ssl_pin.py
Created March 3, 2015 02:15
How to implmement TLS Public Key Pinning in Python (Sort of modeled after HKPK)
import urllib3
from urllib3 import HTTPSConnectionPool
import certifi
import base64
import M2Crypto
import hashlib
class TestHTTPSConnectionPool(HTTPSConnectionPool):
def _validate_conn(self, conn):
@jpf
jpf / showoff.sh
Last active October 23, 2021 19:41
#! /usr/bin/env nix-shell
#! nix-shell -i bash -p curl -p xmlstarlet -p imagemagick -p jp2a -p lolcat
#
# showoff.sh:
# Demonstrate the capabilities of Nix by writing a gratuitously complex shell
# script that combines 5 different command line utilities together.
#
# Do the following to run this demo:
# If you don't have Nix yet, install it with this command:
# $ curl https://nixos.org/nix/install | sh
@jpf
jpf / thoughts-on-literate-programming.md
Last active June 7, 2021 03:50
Thoughts after 6 months of literate programming

Thoughts after 6 months of literate programming

I wrote my first literate program in November of 2015. Since then, I've been writing literate programs on an almost daily basis. It has been an experience with a sort of enlightenment that I haven't had in a long time. Not only is it a lot of fun to write literate programs, I feel like I have gained a new "super power" of sorts.

Below are my thoughts on my experiences with literate programming so far.

@jpf
jpf / turretpaste.lua
Created January 5, 2021 18:29
Hammerspoon code to do a "turret paste"
popHopper = function()
return nil
end
turretPaste = function()
next = popHopper()
if next == nil then
-- this will result in no action after a keypress
clip = hs.pasteboard.readString()
popHopper = string.gmatch(clip, "[^%s]+")
else

After many years of writing and thinking about developer documentation, I'm convinced that the discipline is still in its infancy. The goal of this document is to summarize my current opinions on the topic of documenting software.

When you ask a software developer what their favorite documentation is, you'll get a wide range of opinions with consensus centering roughly around the Stripe and Twilio documentation, as well as the documentation for open source software like Django, Perl, Flask, etc.

In academia, the uncontested master craftsman of developer documentation is Donald Knuth, who pioneered "Literate Programming"

At the frontier of developer documentation, we find projects like Eve and other projects inspired by Bret Victor's seminal "Inventing on Principle" video.

However, as folks at Dynamicland will often point out, the medium (in the McLuhan sense of the word) of software hasn't changed much since the days when code was written on teletypes: We still write software on fancy typewriters. The

@jpf
jpf / app.py
Created March 21, 2015 00:46
Example SAML SP using PySAML2. Can handle IdP initiated requests and make SP initated (authn) requests
# -*- coding: utf-8 -*-
import logging
import os
import uuid
from flask import Flask
from flask import redirect
from flask import request
from flask import url_for
from flask.ext.login import LoginManager
@jpf
jpf / simple-app.py
Created January 11, 2013 21:48
The bare minimum you need in Python/Flask to send a URL in an SMS.
import os
from twilio.rest import TwilioRestClient
from flask import Flask, request, render_template
twilio_account_sid = ''
twilio_auth_token = ''
twilio_from_number = ''
filepicker_api_key = ''
app = Flask(__name__)
@jpf
jpf / fetch-ssl-from-okta-com.sh
Created November 10, 2015 18:59
How to fetch the SSL certificate from www.okta.com
echo '' | openssl s_client -connect www.okta.com:443