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
@doctaphred
doctaphred / quine.py
Created July 22, 2014 21:43
A quick quine. Runs in Python 2 or 3.
q="\nprint('q='+repr(q)+q)"
print('q='+repr(q)+q)
@doctaphred
doctaphred / simple_profiler.py
Created September 24, 2015 00:55
simple Python profiler
"""
$ python -i simple_profiler.py
>>> mark()
2015-09-23 20:49:30.993140: Starting profiler [default]
>>> mark('before crazy stuff')
2015-09-23 20:49:34.855766: Profiler [default], mark #1 (before crazy stuff): took 3.862e+00s
>>> mark('after crazy stuff')
2015-09-23 20:49:40.047713: Profiler [default], mark #2 (after crazy stuff): took 5.192e+00s
>>> mark()
2015-09-23 20:49:46.805728: Profiler [default], mark #3: took 6.758e+00s

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:

@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.

@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";
)
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 / 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])
@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.
//
// 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 / ntfs-filenames.txt
Last active May 9, 2024 13:27
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)