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 / CDNumberDialingTextField.m
Last active May 9, 2020 19:45
[Number Dialing Text Field Widget] Cocoa widget which combines a number-formatted text field with a up/down arrow control for "dialing" the displayed number. #cocoa #widget #gui #objective_c
//
// CDNumberDialingTextField.m
// Countdown
//
// Created by Andre Berg on 20.03.10.
// Copyright 2010 Berg Media. All rights reserved.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
@andreberg
andreberg / sRGB Response Curve
Last active May 9, 2020 19:46
[sRGB Response Curve] Math formula for generating a sRGB standard response curve. #color #colorcorrection #colorprofile #standard
if (in <= 0.00304)
{
out = in*12.92;
}
else
{
out = (1.055 * pow(in, (1.0/2.4)) - 0.055);
}
@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).
@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 / 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 / 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 / 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 / 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 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 / 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