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 / convert_print.py
Last active February 24, 2020 18:03
[Aptana Studio 3: Convert print to print()] Aptana Studio 3 ruble commands which convert between Python 2 and Python 3 print statement syntax using lib2to3 and lib3to2. #aptanastudio #ruble #command #conversion #syntax #userscript #python #python3
#!/usr/local/bin/python
# -*- coding: utf-8 -*-
#
# convert_print.py
# Aptana Ruble Commands
#
# Created by André Berg on 28.05.2013.
# Copyright 2013 Berg Media. All rights reserved.
#
# Used from a Python.ruble command in Eclipse
@andreberg
andreberg / python_py3k_print_convert.rb
Last active February 24, 2020 18:05
[RegEx: Convert print to print()] Functions to convert between Python 2 and Py3k print statements.Supports string interpolation and multiline strings. Does *NOT* cover Python 2 backslash line continuations completely (yet). I originally wrote it for use in a ruble command in Eclipse Aptana Studio 3. #regex #conversion #python #python3 #ruby #rub…
# -*- coding: utf-8 -*-
#
# == Aptana Ruble Commands
# Convert Between Python 2 and Py3k Print Statements
#
# Created by André Berg on 2013-05-23.
# Copyright 2013 Berg Media. All rights reserved.
#
# Used from a Python.ruble command in Eclipse
# Aptana Studio 3:
@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 / 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 / CINEMA 4D Python Plane Class.py
Last active October 26, 2020 17:30
[CINEMA 4D: Python Plane Class] Class representing a plane defined by position and normal vector. Can calculate point distance and line intersections. #cinema4d #c4d #python #class #plane #computergraphics #cg
class Plane(object):
"""Represents a plane defined by position and normal vector"""
def __init__(self, pos, n):
super(Plane, self).__init__()
self.pos = pos
self.n = n.GetNormalized()
if DEBUG: print "self.pos = %r, self.n = %r" % (pos, n)
def setN(self, newn):
self.n = newn.GetNormalized()
@andreberg
andreberg / CINEMA 4D Python Helpers.py
Last active March 25, 2022 05:43
[CINEMA 4D: Python Helpers Class] The Helpers class is collection of reusable methods from cgsociety, the Plugin Café and from my own scripts. #cinema4d #c4d #python #class #helpers #computergraphics #cg
class Helpers(object):
"""Contains various helper methods."""
def __init__(self, arg):
super(Helpers, self).__init__()
@staticmethod
def readConfig(filepath=None):
"""
Read settings from a configuration file.
@andreberg
andreberg / C4D-SetGlobalAxisRotation.py
Last active May 9, 2020 19:45
[CINEMA 4D: Python Set Global Axis Rotation Func] A function for setting the orientation of the object axis withouth modifying the points. #cinema4d #c4d #python #function #computergraphics #cg
def SetGlobalAxisRotation(obj, rot, depth=0):
"""
Set the global rotation of the object axis (i.e. keeping points in place).
obj object
rot vector
"""
# unfortunately tail recursion and depth guard
# seem needed because of the MatrixToHPB(HPBToMatrix(Rad(angle))
# roundtrip round-off error, so we need to improve
@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 / TestDependent.java
Last active February 24, 2020 18:06
[Pydev TestDependent Mac OS X Template] #pydev #unittest #java #template
/*
* Create a file TestDependent.java with the contents in this file and substitute the
* values as needed...
*/
package org.python.pydev.core;
public class TestDependent {
//NOTE: this should be gotten from some variable to point to the python lib (less system dependence, but still, some).