Skip to content

Instantly share code, notes, and snippets.

View yorikvanhavre's full-sized avatar

Yorik van Havre yorikvanhavre

View GitHub Profile
@yorikvanhavre
yorikvanhavre / getrecentfiles.py
Last active August 2, 2018 12:40
get list of recent documents in linux
#!/usr/bin/python
# -*- coding: UTF-8 -*-
import re,os,gtk,gio,magic
def geticon(filename):
m = magic.open(magic.MAGIC_MIME)
m.load()
mime = m.file(filename).split(";")[0]
mime = gio.content_type_get_icon(mime).get_names()
@yorikvanhavre
yorikvanhavre / convert.sh
Created July 28, 2015 18:04
replace colors in librecad icons
convert zoomwindow.png -fill darkgrey -transparent white -fuzz 50% -fill white -opaque black test.png
@yorikvanhavre
yorikvanhavre / soclipplane
Created February 27, 2015 20:50
Add a SoClipPlane to the FreeCAD view with Pivy
>>> 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)
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
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
@yorikvanhavre
yorikvanhavre / getTool
Created December 21, 2014 16:12
a getTool function for parametric paths
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
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 / export_vcf.php
Last active August 29, 2015 14:05
ProjectPier: export the contacts list as VCard - application/views/dashboard/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 / contacts_sidebar.php.diff
Created August 11, 2014 02:12
ProjectPier: add a link in the contacts view's sidebar - application/views/dashboard/conotacts_sidebar.php
16a17,19
> <div class="contactExport">
> <a href="application/views/dashboard/export_vcf.php"><?php echo lang('export vcard file');?></a>
> </div>
@yorikvanhavre
yorikvanhavre / FeedController.class.php.diff
Created August 10, 2014 22:31
ProjectPier : export tasks to google calendar - application/controllers/FeedController.class.php
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