Skip to content

Instantly share code, notes, and snippets.

View sfaleron's full-sized avatar
:electron:
Figuring it out as I go

Chris Fuller sfaleron

:electron:
Figuring it out as I go
View GitHub Profile
@sfaleron
sfaleron / prettybin.py
Created September 24, 2015 23:40
Python function to create a hexdump inspired by old DOS DEBUG command
_fmtinner = ('',' ') * 3 + ('','-') + ('',' ') * 3 + ('','')
_fmtouter = (' ', ' |', '|')
def _mkhex(d, i):
try:
return '%02x' % (ord(d[i]),)
except IndexError:
return ' '
def _mkchar(d, i):
@sfaleron
sfaleron / ln2.py
Created September 24, 2015 23:44
Quick ln2 function for Python
from math import ceil
# for example, inc=4 gives ln16, or the number of hexadecimal digits
# required to represent n.
def ln2(n, inc=1):
if n<0:
raise ValueError('math domain error')
i = 0
n = int(ceil(n))