Skip to content

Instantly share code, notes, and snippets.

View techtonik's full-sized avatar

anatoly techtonik techtonik

View GitHub Profile
@techtonik
techtonik / mingwsdk.py
Last active October 12, 2015 10:38
Python - MinGW locally - Helper to downloaded toolchain into local subdirectory
#!/usr/bin/env python3
#
# Use `locally` bootstrap code to get MinGW SDK for Windows
# operational from the local directory.
# This stuff is placed into public domain by
# anatoly techtonik <techtonik@gmail.com>
# --- bootstrap .locally ---
#
@techtonik
techtonik / README.rst
Last active October 12, 2015 12:58
Python - stdlib - Standard library tools
@techtonik
techtonik / get_version.py
Last active June 18, 2019 15:41
Python - setup.py - read version without importing (2/3 compatible)
"""
# This snippet is in public domain
# https://gist.github.com/techtonik/4066623/
# Minified (Python 2.6+, 3+ compatible):
import io
from os.path import dirname, join
def get_version(relpath):
@techtonik
techtonik / find_executable.py
Last active April 4, 2022 06:23
Python Which/Where - Find executable
#!/usr/bin/env python
# https://gist.github.com/4368898
# Public domain code by anatoly techtonik <techtonik@gmail.com>
# AKA Linux `which` and Windows `where`
# For Python 3 you probably want
# https://docs.python.org/dev/library/shutil.html#shutil.which
import os
@techtonik
techtonik / setup.py
Created March 5, 2013 18:38
Python - setup.py - auto link issues in reST files (such as CHANGES.rst)
import re
# tested with BitBucket
TRACKER = 'http://bitbucket.org/tarek/distribute'
# return contents of reStructureText file with linked issue references
def _linkified(rstfile):
revision = re.compile(r'\b(issue\s*#?\d+)\b', re.M | re.I)
rstext = open(rstfile).read()
@techtonik
techtonik / hashdeep.py
Created March 16, 2013 10:45
Python - hashdeep.py - recursive hash of directory tree files in hashdeep format
"""
Build recursive hash of files in directory tree in hashdeep format.
Hashdeep format description:
http://md5deep.sourceforge.net/start-hashdeep.html
hashdeep.py differences from original hashdeep:
- if called without arguments, automatically starts to build
@techtonik
techtonik / findfiles.py
Created June 2, 2013 20:23
Python - case-insensitive glob
# snippet is placed into public domain by
# anatoly techtonik <techtonik@gmail.com>
# http://stackoverflow.com/questions/8151300/ignore-case-in-glob-on-linux
import fnmatch
import os
import re
def findfiles(which, where='.'):
@techtonik
techtonik / Makefile
Last active December 18, 2015 13:18
Using Python inside Makefile
# Black magic to use Python logic for setting Makefile variables
# Real world example that is detecting AppEngine SDK with Python
# Helper code to detect SDK location
define DETECT_SDK
import os
locations = [
"../google_appengine",
"/usr/local/google_appengine",
"../.locally/google_appengine",
@techtonik
techtonik / bootstrap.py
Last active December 18, 2015 14:38
locally - repository checkout w/out moving
# locally recipe that checks out Rietveld sources
# sources go into subdir, because hg is unable to
# checkout into dirty dir. no custom move logic
# is done also
# [ ] check rietveld checkout into given dir
# [ ] check dir/
# [ ] check dir/.hg/
# [ ] check dir/codereview/
# [ ] clone
@techtonik
techtonik / bootstrap.py
Last active December 18, 2015 14:39
locally - download and apply patch
# locally recipe that downloads patch and applies it
# --- bootstrap .locally ---
#
# this creates .locally/ subdirectory in the script's dir
# and sets a few global variables for convenience:
#
# ROOT - absolute path to bootstrap.py dir, ends with /
# LOOT - absolute path to the .locally/ subdir
# LIB - path to downloaded helper libs added to sys.path