Skip to content

Instantly share code, notes, and snippets.

@mawillcockson
mawillcockson / twitter.sh
Created December 30, 2020 12:11
Compare Manhattan distance calculations implemented in python
# https://twitter.com/IsntTrivial/status/1344185584013742086
echo "sum(map(abs, map(operator.sub, p, q)))"
python -m timeit \
-s "import operator;p=q=range(-10_000, 10_000, 1);" \
-s "def manhattan_distance(p, q): return sum(map(abs, map(operator.sub, p, q)))" \
"manhattan_distance(p, q)"
echo ""
echo "sum(abs(x - y) for x, y in zip(p, q))"
python -m timeit \
@mawillcockson
mawillcockson / as_int.py
Created December 28, 2020 11:56
transforms a dotted quad IPv4 address into a single, unsigned 32-bit integer
#!/bin/env python
"""
https://twitter.com/dave_universetf/status/1342688553264762880
"""
import sys
from typing import List
def split_by_dots(dotted_quad: str) -> List[int]:
"turns '1.2.3.4' into [1,2,3,4]"
@mawillcockson
mawillcockson / keybase.md
Created January 26, 2018 00:53
Proof of identity for https://keybase.io/

Keybase proof

I hereby claim:

  • I am mawillcockson on github.
  • I am mawillcockson (https://keybase.io/mawillcockson) on keybase.
  • I have a public key ASDtn4sIGl7SslZu-ioUZwJ0JWd_6HC49F14VxV4YDP7kAo

To claim this, I am signing this object: