Skip to content

Instantly share code, notes, and snippets.

Avatar

Yorik van Havre yorikvanhavre

View GitHub Profile
@yorikvanhavre
yorikvanhavre / contacts_sidebar.php.diff
Created Aug 11, 2014
ProjectPier: add a link in the contacts view's sidebar - application/views/dashboard/conotacts_sidebar.php
View contacts_sidebar.php.diff
16a17,19
> <div class="contactExport">
> <a href="application/views/dashboard/export_vcf.php"><?php echo lang('export vcard file');?></a>
> </div>
@yorikvanhavre
yorikvanhavre / export_vcf.php
Last active Aug 29, 2015
ProjectPier: export the contacts list as VCard - application/views/dashboard/export_vcf.php
View export_vcf.php
<?php
require('../../../config/config.php');
date_default_timezone_set("America/Sao_Paulo");
header('Content-Type: text/vcard; charset=utf-8'); //To tell that the data is a visiting card format
header('Content-Disposition: attachment; filename=projectpier_contacts.vcf'); //To make the data downloadable
$conn = mysql_connect(DB_HOST, DB_USER, DB_PASS) or die('Could not connect to MySQL database. ' . mysql_error());
mysql_select_db(DB_NAME,$conn)or die(mysql_error());
$companies = array();
$comp = mysql_query('SELECT name,id FROM `'.DB_PREFIX.'companies`');
@yorikvanhavre
yorikvanhavre / FeedController.class.php.diff
Created Aug 10, 2014
ProjectPier : export tasks to google calendar - application/controllers/FeedController.class.php
View FeedController.class.php.diff
187,189d186
< $todo = new iCalendar_Todo();
< $todo->setPropertyValue('SUMMARY', $project->getName().": ".$task->getText());
< $todo->setPropertyValue('UID', 'a9idfv00fd99q344o' . rand() . 'cgef733m6bs@google.com');
190a188,191
> $lines = explode("\n",$task->getText());
> $title = $lines[0];
> $title = preg_replace( "/\r|\n/", "", $title );
> $text = preg_replace( "/\r|\n/", " ", $task->getText() );
191a193,195
View pre_example test
f = open("/path/to/myfile.ncc")
s1 = f.read()
from PathScripts import pre_example
s2 = pre_example.parse(s1)
import Path
p = Path.Path(s2)
@yorikvanhavre
yorikvanhavre / getTool
Created Dec 21, 2014
a getTool function for parametric paths
View getTool
def getTool(self,obj,number=0):
"retrieves a tool from a hosting object with a tooltable, if any"
for o in obj.InList:
if hasattr(o,"Tooltable"):
return o.Tooltable.getTool(number)
# not found? search one level up
for o in obj.InList:
return self.getTool(o,number)
return None
View pathviewprovider.py
class ViewProviderPath:
def __init__(self,vobj): #mandatory
obj.addProperty("App::PropertyFloat","SomePropertyName","PropertyGroup","Description of this property")
obj.Proxy = self
def __getstate__(self): #mandatory
return None
def __setstate__(self,state): #mandatory
View very_basic_post.py
def export(objectslist,filename):
gfile = open(filename,"wb") # open the file with write permission
for obj in objectslist:
if hasattr(obj,"Path"): # not all objects might be paths
gfile.write(obj.Path.toGCode()) # this simply dumps the path data as internal gcode
commands = obj.Path.Commands # but we could also do stuff with the commands list
gfile.close()
print "successfully exported " + filename
@yorikvanhavre
yorikvanhavre / soclipplane
Created Feb 27, 2015
Add a SoClipPlane to the FreeCAD view with Pivy
View soclipplane
>>> from pivy import coin
>>> sg=Gui.ActiveDocument.ActiveView.getSceneGraph()
>>> clip = coin.SoClipPlane()
>>> clip.on.setValue(False)
>>> plane = coin.SbPlane(coin.SbVec3f(0,0,1),1000)
>>> plane
<pivy.coin.SbPlane; proxy of <Swig Object of type 'SbPlane *' at 0x7fd8424b62a0> >
>>> clip.plane.setValue(plane)
>>> sg.addChild(clip)
>>> clip.on.setValue(True)
@yorikvanhavre
yorikvanhavre / convert.sh
Created Jul 28, 2015
replace colors in librecad icons
View convert.sh
convert zoomwindow.png -fill darkgrey -transparent white -fuzz 50% -fill white -opaque black test.png
@yorikvanhavre
yorikvanhavre / tangent.py
Created Apr 4, 2012
get a tangent vector from an edge in FreeCAD
View tangent.py
def getTangent(edge):
"Returns a tangent vector from an edge in FreeCAD"
if isinstance(edge.Curve,Part.Line):
vec = edge.Vertexes[-1].Point.sub(edge.Vertexes[0].Point)
elif isinstance(edge.Curve,Part.Circle):
v1 = edge.Vertexes[-1].sub(edge.Curve.Center)
v2 = edge.Curve.Axis
vec = v1.cross(v2)
else:
print "not supported"
You can’t perform that action at this time.