Skip to content

Instantly share code, notes, and snippets.

View doctaphred's full-sized avatar
🚮
computers are bad don't use them

Frederick Wagner doctaphred

🚮
computers are bad don't use them
View GitHub Profile
#!/bin/sh
# Pretty-print the JSON on the (macOS) clipboard.
# Works with Python 2 or 3.
pbpaste | python -m json.tool | pbcopy
@doctaphred
doctaphred / django-secret-key
Last active March 7, 2018 18:25
Generate a secret key suitable for use with Django
#!/usr/bin/env python
"""Generate a new secret key suitable for use with Django.
Uses the same process as django.core.management.utils:get_random_secret_key.
"""
from random import SystemRandom
random = SystemRandom()
chars = 'abcdefghijklmnopqrstuvwxyz0123456789!@#$%^&*(-_=+)'
print(''.join(random.choice(chars) for _ in range(50)))
@doctaphred
doctaphred / ntfs-filenames.txt
Last active March 24, 2025 08:51
Invalid characters for Windows filenames
Information from https://docs.microsoft.com/en-us/windows/win32/fileio/naming-a-file :
Use any character in the current code page for a name, including Unicode
characters and characters in the extended character set (128–255), except
for the following:
- The following reserved characters:
< (less than)
> (greater than)
//
// Regular Expression for URL validation
//
// Author: Diego Perini
// Updated: 2010/12/05
// License: MIT
//
// Copyright (c) 2010-2013 Diego Perini (http://www.iport.it)
//
// Permission is hereby granted, free of charge, to any person
@doctaphred
doctaphred / shell-script
Last active February 11, 2020 18:59
How to start every shell script, since I can never remember
#!/bin/sh -euvx
# -e If non interactive then exit immediately if a command fails.
# -u Treat unset variables as an error when substituting.
# -v Print shell input lines as they are read.
# -x Print commands and their arguments as they are executed.
@doctaphred
doctaphred / client.py
Created September 21, 2016 21:48
Basic pyzmq client/server
from datetime import datetime
import os
import sys
import time
import zmq
port = int(sys.argv[1])
n = int(sys.argv[2])
magic = lambda x: x()
class word:
def __init__(self, current, prev=None):
self.current = current
self.prev = prev
def __getattr__(self, name):
return self.__class__(name, self)
@doctaphred
doctaphred / wsh
Last active March 8, 2019 13:49
If you're going to curl to shell, at *least* verify the checksum!
(
script=$(curl -fsSL <INSERT URL HERE>);
checksum=$(echo "$script" | shasum -pa256 | cut -c-64);
test $checksum = <INSERT CHECKSUM HERE> || exit 1;
sh -c "$script";
)
@doctaphred
doctaphred / bug-hunt.md
Last active April 16, 2016 14:57
How far would you go to save the build you love?

So yesterday we had a fun time as soon as we pushed some code that uses pyopenssl: our deploy build started crashing from an IOError in a call to open(filename, 'w')—in ply.lex, of all places.

  • Why on earth are we using ply?

  • Turns out pyopenssl depends on cryptography, which depends on cffi, which depends on pycparser, which depends on ply.

  • Why on earth is ply writing out to disk?

  • Turns out ply attempts to write out intermediate results as an optimization to avoid redundant work.

  • Why don't we see these files on our dev machines?

  • ply also cleans up its intermediate result files immediately after it runs; fswatch . | grep lextab.py confirms that the writes are happening locally.

Keybase proof

I hereby claim:

  • I am doctaphred on github.
  • I am doctaphred (https://keybase.io/doctaphred) on keybase.
  • I have a public key whose fingerprint is A2A1 4E61 BBA9 06CB EE09 A712 84BE D09B 5EF5 A533

To claim this, I am signing this object: