Skip to content

Instantly share code, notes, and snippets.

View techtonik's full-sized avatar

anatoly techtonik techtonik

View GitHub Profile
@techtonik
techtonik / sha1.py
Last active March 3, 2024 16:06
Calculate SHA-1 of a file in Python
#!/usr/bin/env python
"""
usage: python -m sha1 <filename>
"""
import sys
import hashlib
# --- these fields are required for packaging
__version__ = '1.0'
__author__ = 'anatoly techtonik <techtonik@gmail.com>'
@techtonik
techtonik / caller_name.py
Created March 21, 2012 19:29
Python - inspect - Get full caller name (package.module.function)
# Public Domain, i.e. feel free to copy/paste
# Considered a hack in Python 2
import inspect
def caller_name(skip=2):
"""Get a name of a caller in the format module.class.method
`skip` specifies how many levels of stack to skip while getting caller
name. skip=1 means "who calls me", skip=2 "who calls my caller" etc.
@techtonik
techtonik / webview.py
Last active October 27, 2023 10:33
View HTML content in Python with PySide
"""
Placed into public domain by
anatoly techtonik <techtonik@gmail.com>
Show HTML in GUI window through PyQt4/PySide.
[ ] position window at the center of the screen
(right now it is middle bottom)
[ ] implement lazy loading for PyQt4/PySide
"""
@techtonik
techtonik / NonBlockingPipe.md
Last active September 21, 2023 18:01
Non-blocking pipe reads in Windows Python
@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 / 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 / minijinja.py
Last active January 15, 2022 21:57
Template engine that knows how to render {{ tag }}
# minijinja is in public domain
class MiniJinja(object):
""" Template engine that knows how to render {{ tag }} """
def __init__(self, templates='.'):
"""templates - template path"""
import re
import sys
self.PY3K = sys.version_info[0] == 3
@techtonik
techtonik / PythonFar.md
Last active October 29, 2019 21:40
Using Python with Far Manager
@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):