Skip to content

Instantly share code, notes, and snippets.

View andreberg's full-sized avatar
💭
I may be slow to respond.

André Berg andreberg

💭
I may be slow to respond.
View GitHub Profile
@andreberg
andreberg / gist:775214
Created January 11, 2011 21:46
Module: CLI (optparse)
#!/usr/bin/env python
# encoding: utf-8
'''
${module} -- ${shortdesc}
${module} is a ${description}
It defines ${classes_and_methods}
@author: ${user_name}
@andreberg
andreberg / gist:775212
Created January 11, 2011 21:45
Module: CLI (argparse)
#!/usr/local/bin/python2.7
# encoding: utf-8
'''
${module} -- ${shortdesc}
${module} is a ${description}
It defines ${classes_and_methods}
@author: ${user_name}
@andreberg
andreberg / GW2 Spidy Functions.js
Last active February 24, 2020 17:19
[Guild Wars 2 Spidy functions] Used in my Google Docs spreadsheets for price fetches and conversions. #guildwars2 #spidy #googledocs #spreadsheets
/**
* Guild Wars 2 Spidy Functions
*
* for use in Google Docs spreadsheets
* via the Script Editor.
*
* After an idea and first concept of
* Valaadus.5012 on Northern Shiverpeaks
*
* Additional functions by Cauldron.1653
@andreberg
andreberg / TooltipsForGuiControls.ahk
Last active February 24, 2020 17:25
[GUI Tooltips] Shows how to attach tooltips to Gui controls on-the-fly and update them. Works with all AHK versions: ANSI+Unicode, 32/64bit. #autohotkey #ahk #gui
; ### Example Code #####
Gui,Add,Button,hwndbutton1 Gbut1,Test Button 1
Gui,Add,Button,hwndbutton2,Test Button 2
Gui,Add,Button,hwndbutton3,Test Button 3
AddTooltip(button1,"Press me to change my tooltip")
AddTooltip(button2,"Another Test Tooltip")
AddTooltip(button3,"A Multiline`nTest Tooltip")
Gui,show,,Test Gui
Return
@andreberg
andreberg / CINEMA 4D MinMax Class.py
Last active February 24, 2020 17:37
[CINEMA 4D: Python MinMax Class] Class for calculating various metrics from a list of vectors, such as min, max, radius, size and midpoint. #cinema4d #c4d #python #class #minmax #computergraphics #cg
class MinMax(object):
"""
Calculate various area metrics from a list of points,
such as min, max, midpoint, radius and size.
"""
def __init__(self):
super(MinMax, self).__init__()
FLOATMIN = sys.float_info[3]-1000 # workaround for underflow error
FLOATMAX = sys.float_info[0]
self.min = c4d.Vector(FLOATMAX, FLOATMAX, FLOATMAX)
@andreberg
andreberg / pyobjc_coregraphics_example1.py
Last active February 24, 2020 17:45
[PyObjC CoreGraphics API Example] Shows how to use the functional API of the CoreGraphics framework through PyObjC and Python 2.7. #pyobjc #python #coregraphics #quartz #macos #examples
#!/usr/local/bin/python
# -*- coding: utf-8 -*-
#
# pyobjc_coregraphics_example1.py
# PyObjC Scripts
#
# Created by André Berg on 2013-07-09.
# Copyright 2013 Berg Media. All rights reserved.
#
# Example script that shows how to use
@andreberg
andreberg / Timestamp.py
Last active February 24, 2020 17:48
[Synalyze It Pro: Timestamp Data Type Script] For displaying and manipulating the timestamp header bytes in a Python bytecode (pyc) file. #synalyzeitpro #userscript #python #bytecode
# Data type script for displaying and manipulating the
# timestamp header bytes in a Python bytcode (pyc) file.
#
# pyc header
# 8 16
# +-+-+-+-+-+-+-+-+ +-+-+-+-+-+-+-+-+
# |X|X|X|X|0|D|0|A| |T|I|M|E|S|T|M|P|
# +-+-+-+-+-+-+-+-+ +-+-+-+-+-+-+-+-+
# \______/\______/ \_______________/
# inc. cr/lf timestamp
@andreberg
andreberg / pyc.grammar
Last active February 24, 2020 17:59
[Synalyze It Pro: Python 2 and 3 Bytecode Grammar] Targets .pyc and .pyo bytecode files. #synalyzeitpro #grammar #python #python3 #bytecode
<?xml version="1.0" encoding="UTF-8"?>
<ufwb version="1.5.1">
<grammar name="Python Bytecode" start="id:104" author="André Berg" email="andre.bergmedia@googlemail.com" fileextension="pyc, pyo" uti="public.data" complete="yes">
<description>Grammar for PYC and PYO files
Version: 8
Now works with pyc/pyo files generated by Python 2, Python 3.0-3.2 and Python 3.3.
References
@andreberg
andreberg / pylong_from_bytearray.py
Last active February 24, 2020 18:00
[PyLong from ByteArray] Methods for reading and converting PyLong objects as defined in longobject.c. Made this to help me understand how Python's marshal interface deals with these objects when it commits the bytes making up the PyLong object to a binary pyc file. #cython #python #python3 #marshall #cpython #synalyzeitpro
#!/usr/local/bin/python3.3
'''
pylong_from_bytearray -- methods for reading and converting PyLong objects.
Ported from Python's C source code, specifically from marshal.c and longobj.c
Serialization of PyLong objects to marshal's bytecode format has the following
layout:
+--+--+--+--+--+--+--+--+--+
@andreberg
andreberg / benchmark decorator.py
Last active February 24, 2020 18:01
[Benchmark Decorator] Prints the time a function take to execute per call and cumulative total. Works with Python 2.7 and Python 3. #python #python3 #benchmark #decorator
# -*- coding: utf-8 -*-
#
# Created by André Berg on Jun 2, 2013.
# Copyright 2013 Berg Media. All rights reserved.
#
from functools import wraps, partial
def benchmark(func=None, prec=3, unit='auto', name_width=0, time_width=8):