Skip to content

Instantly share code, notes, and snippets.

@5263
5263 / ultimo.py
Created Jun 14, 2018
Last day of previous months
View ultimo.py
import datetime,calendar
def ultimo(num=3,today=None):
"""return a list of datetime.date with the last day of num previous months"""
if today is None:
today = datetime.date.today()
return [datetime.date(y,m,calendar.monthrange(y,m)[1]) for \
m,y in (((today.month - i -1) % 12+1, today.year + \
((today.month - i -1) // 12)) for i in range(num+1,0,-1))]
@5263
5263 / checkoutandload.FCMacro
Last active Oct 26, 2020
FreeCAD files git repo
View checkoutandload.FCMacro
#!/usr/bin/env python
import zip2git
from PySide import QtGui
# 1. Choose repository (directiory)
repodir = QtGui.QFileDialog.getExistingDirectory(QtGui.qApp.activeWindow())
if repodir:
# ToDO: 2. List branches in a list and let the user choose one
# ToDo: 3. List commits in a list and let the user choose one
# ToDo: 4. Check if it would overwrite a file. And if the file is
# part of the repo. Ask the user for cofirmation
@5263
5263 / parsegitweb3.py
Last active Apr 24, 2021
gitwebparser
View parsegitweb3.py
#!/usr/bin/env python3
import bs4
import requests
sa = requests.Session()
sa.verify = False # workaround
# sa.auth = BearerAuth()
sa.timeout = 10
@5263
5263 / checkwire.py
Last active Aug 29, 2015
check if a FreeCAD wire can be traversed
View checkwire.py
import FreeCAD
def checkwire(w):
"""steps through every edge of a wire and checks the orientation"""
pos=w.Vertexes[0].Point
for i,e in enumerate(w.Edges):
if e.Orientation == "Forward":
vs=e.Vertexes
else:
vs=e.Vertexes[::-1]
@5263
5263 / hash.py
Last active Aug 29, 2015
blobhash recursive
View hash.py
#!/usr/bin/env python
def blobhash(str1):
import hashlib
hash1=hashlib.sha1("blob %d\0" % len(str1))
hash1.update(str1)
return hash1.hexdigest()
def walk(dir1,extension=".py"):
import os
for root, dirs, files in os.walk(dir1):
@5263
5263 / phpbbpost.py
Last active Aug 29, 2015
post on PHPBB forum
View phpbbpost.py
def phppost(subject,message,url,forum,username,password):
import mechanize
import time
br = mechanize.Browser()
br.open(url+'/ucp.php?mode=login')
loginform = tuple(br.forms())[1]
br.form=loginform
loginform.find_control("username").value=username
loginform.find_control("password").value=password
loginform.find_control("viewonline").set_single(True)
@5263
5263 / FreeFormTurning.py
Last active Aug 29, 2015
Free form turning
View FreeFormTurning.py
import FreeCAD
import Part
def rayshape(phi=0,z=0,r=1e3):
import math
x=r*math.cos(phi)
y=r*math.sin(phi)
l=Part.Line(FreeCAD.Vector(0,0,z),FreeCAD.Vector(x,y,z))
return l.toShape()
@5263
5263 / uniname.py
Created Sep 25, 2014
encode unicode with name literals
View uniname.py
import unicodedata
def encodechar(c):
i=ord(c)
if i >= 32 and i <=122 and \
c not in '\'\"/\\^_~`|':
return c
else:
if not isinstance(c,unicode):
c=unicode(c)
name = unicodedata.name(c,None)
@5263
5263 / exrsdoc.py
Last active Aug 5, 2016
parser for the rdsoc file format
View exrsdoc.py
#!/usr/bin/env python
import zipfile
tempdirlin='/home/user/sattemp'
tempdirwine='D:\\'
converterbin="/windows/Programme/Program Files (x86)/DesignSpark/DesignSpark Mechanical 1.0/sabSatConverter.exe"
# add freecad libdir to path
import sys
sys.path.insert(0,'/usr/local/freecad/lib')
@5263
5263 / hexplacment.py
Created Feb 20, 2014
exact representation of a FreeCAD placement
View hexplacment.py
def hexplacement(plm):
fhex="*[float.fromhex(s) for s in %s]"
fstr="FreeCAD.Placement(FreeCAD.Vector(%s),FreeCAD.Rotation(%s))"
t=[f.hex() for f in plm.Base]
r=[f.hex() for f in plm.Rotation.Q]
return fstr % (fhex % t, fhex % r )
if __name__=='__main__':
import FreeCAD
print hexplacement(FreeCAD.Placement())