Skip to content

Instantly share code, notes, and snippets.

@adewes
adewes / generate_random_color.py
Last active March 26, 2024 08:18
A small Python script to generate random color sequences, e.g. for use in plotting. Just call the "generate_new_color(existing_colors,pastel_factor)" function to generate a random color that is (statistically) maximally different from all colors in "existing_colors". The "pastel_factor" parameter can be used to specify the "pasteliness"(?) of th…
import random
def get_random_color(pastel_factor = 0.5):
return [(x+pastel_factor)/(1.0+pastel_factor) for x in [random.uniform(0,1.0) for i in [1,2,3]]]
def color_distance(c1,c2):
return sum([abs(x[0]-x[1]) for x in zip(c1,c2)])
def generate_new_color(existing_colors,pastel_factor = 0.5):
max_distance = None
@parijatmishra
parijatmishra / ddb_lsi_example.py
Created February 10, 2016 11:51
Using DynamoDB Local Secondary Indexes - example in Python and boto3
#!/usr/bin/env python
# ddb_lsi_example: A sample program to show how to use Local Secondary Indexes
# in DynamoDB, using Python and boto3.
#
# Copyright 2016 Parijat Mishra
# 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
#
# http://www.apache.org/licenses/LICENSE-2.0
@yoavram
yoavram / client.py
Created December 21, 2012 08:41
Example of uploading binary files programmatically in python, including both client and server code. Client implemented with the requests library and the server is implemented with the flask library.
import requests
#http://docs.python-requests.org/en/latest/user/quickstart/#post-a-multipart-encoded-file
url = "http://localhost:5000/"
fin = open('simple_table.pdf', 'rb')
files = {'file': fin}
try:
r = requests.post(url, files=files)
print r.text
@bonsak
bonsak / c4d-reset-object-axis.py
Created September 22, 2015 20:02
c4d-reset-object-axis
import c4d
# Slightly modified version of Lennart's (tca studios) script from this thread:
# http://www.plugincafe.com/forum/forum_posts.asp?TID=6600&KW=&PID=27379#27379
def main():
if op is None: return False
oldm = op.GetMg()
points = op.GetAllPoints()
ident = 5159
import c4d
print "************"*4
print "Results for", ident
for key, value in vars(c4d).iteritems():
if value == ident:
print(key)
@victormattosvm
victormattosvm / fix.php
Last active May 27, 2022 13:13
Fix for "anr_error" when using WPGraphQL or WP REST API with Captcha4WP (old Advanced Nocaptcha & Invisible Captcha)
<?php
/**
* This code disables the Captcha verification when using WPGraphQL or WP REST API
* It fixes the "anr_error" issue.
*
* Put this code in your functions.php
*/
add_action(
'rest_api_init',
@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.
@NiklasRosenstein
NiklasRosenstein / recover-scene.py
Last active March 20, 2022 06:12
This script imports a Cinema 4D scenefile and disables all deformers, generators and expressions. This is useful if the scene was saved at a state it is unrecoverable because of an issue while scripting (eg. saved the scene before a Python tag was executed, but now that Python tag always runs in an # infinite loop).
# Copyright (c) 2013, Niklas Rosenstein
#
# Permission is hereby granted, free of charge, to any person obtaining a copy
# of this software and associated documentation files (the "Software"), to deal
# in the Software without restriction, including without limitation the rights
# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
# copies of the Software, and to permit persons to whom the Software is
# furnished to do so, subject to the following conditions:
#
# The above copyright notice and this permission notice shall be included in
# localimport-v1.7.3-blob-mcw79
import base64 as b, types as t, zlib as z; m=t.ModuleType('localimport');
m.__file__ = __file__; blob=b'\
eJydWUuP20YSvutXEMiBpIfmeOLDAkJo7GaRAMEGORiLPUQrEBTVkumhSKK75Uhj5L+nHv2iSNpyf\
BiTXY+uqq76qpoqy+qsP/SyLIv4t+a5rVT0vleiU1o0XfSDdM8dEf95PFVNm9f96V28KstPQqqm71\
D4Kf9H/jZeNaehlzqq++Fqn49tv7PPvbJPw/PxrJvWvqqro2hZ1WJX1c924aUZDk0rVs0B2XK7adM\
d+s2bbVF8v15Fe3GIGi1OKrmk8BpJoc+yiy45L6aOQy5xScspWiWWNbaN0olTe4de0klMqmz7umoT\
dKarTiIbKv0B9aGMXSx6leN6Xu0U/u+4YatDLyNcK/E9gvOxCnBPR5hocBRQETVkiDrvRsozz4O6r\
AP/lWexsi8/VxAY64lVgH9AWIqOvNDyyv63SHCWmPcR9yoSl1oMOvpf1Z7FT1L2MggdbRa5va1C1F\
if5b6REcSi67Wl5EpXUqs/GtiFdkUejrv4VLXlEDqr4FiAnO2F0sVvfScyzjRFL+gHRAmJ4GmES2g\
@ruimac
ruimac / Mirror VertexMap.py
Last active November 11, 2021 10:00
Cinema 4D python script - Mirrors a VertexMap along a user defined axis.
# Script by RuiMac - 09-2015
import c4d
import sys
from c4d import gui
# IDs of the dialog elements
OPTION=1000
TH_TEXT=1009
THRESHOLD=1010