Skip to content

Instantly share code, notes, and snippets.

View avakar's full-sized avatar
💭
Awaiting pull requests...

Martin Vejnár avakar

💭
Awaiting pull requests...
View GitHub Profile
@avakar
avakar / bin2c.py
Created January 2, 2012 16:23
Converts a binary file to a C array
import sys
s = open(sys.argv[1], 'rb').read()
lines = []
while s:
bytes = ['0x%02x' % ord(ch) for ch in s[:16]]
lines.append(' ' + ', '.join(bytes) + ',' + '\n')
s = s[16:]
print ''.join(lines)
@avakar
avakar / extract_torrent.py
Created April 9, 2012 15:34
Extracts embedded torrent files
import sys, os, os.path
def find_bencode_end(s):
if not s:
raise RuntimeError('Not a valid bencode blob.')
if s[0] == 'i':
if len(s) < 2:
raise RuntimeError('Not a valid bencode blob.')
if s[1:3] == '0e':
return 3
@avakar
avakar / fixup_qt_msvc.py
Last active April 28, 2018 13:14
The script will recursively walk a directory and modify all .vcxproj.filter files so that the filters reflect the filesystem structure. It will also update .sln files so that they would open in msvc11, and update .vcxproj files so that Debug configurations would have optimizations disabled. I use the script after generating msvc projects from Qt…
import sys, os.path
from xml.etree import ElementTree
import xml.dom.minidom
def process_vcxproj_file(fname):
with open(fname, 'rb') as fin:
proj = fin.read()
add_optimize_after = ' <ItemDefinitionGroup Condition="&apos;$(Configuration)|$(Platform)&apos;==&apos;Debug|Win32&apos;">\r\n <ClCompile>'
proj = proj.replace(add_optimize_after, add_optimize_after + '\r\n <Optimization>Disabled</Optimization>')
@avakar
avakar / gencrctable.py
Created October 23, 2013 15:57
Generates CRC tables from the generating polynom.
"""
Generates CRC tables. Run as follows.
gencrctable.py <polynom> -w <width>
# for CRC-32
gencrctable.py 0x04C11DB7 -w 32
# for CRC-32C
gencrctable.py 0x1EDC6F41 -w 32
#!/usr/bin/env python3
import argparse
import sys
def _main():
ap = argparse.ArgumentParser()
ap.add_argument('--min-range-length', '-n', type=int, default=3)
ap.add_argument('input')
args = ap.parse_args()