Skip to content

Instantly share code, notes, and snippets.

@5263
5263 / dtg.py
Last active December 12, 2015 10:08
Date/Time Group
def gettimeszonestg(tz,dt1=None):
if tz is None:
return 'J'
else:
utco=tz.utcoffset(dt1)
if utco.days>=0:
tzg = 'ZABCDEFGHIKLM'[utco.seconds//3600]
else:
tzg = 'ZNOPQRSTUVWXY'[(-utco).seconds//3600]
if utco.seconds % 3600 == 1800:
@5263
5263 / decalc.py
Last active December 11, 2015 22:58
query the calc database
#/usr/bin/env python
import sqlite3
conn=sqlite3.connect('memento.sqlite')
cr=conn.cursor()
calcslist=cr.execute("SELECT * FROM `entry`").fetchall()
calcsdict=dict((entry[0].lower(),entry) for entry in calcslist)
conn.close()
if __name__ = '__main__':
import sys
@5263
5263 / thingiverse1.py
Created January 9, 2013 23:05
thingiverse api experiments
token_type='Bearer'
access_token=''
baseurl='https://api.thingiverse.com/'
meurl='https://api.thingiverse.com/users/me'
import urllib2, base64
import json
def isfiletype(name,suffixes=('fcstd','scad','brep','brp')):
return any([name.lower().endswith(suffix) for suffix in suffixes])
@5263
5263 / decmagellan.py
Created July 29, 2012 09:01
Decode information from Magellan Serial 6-DOF input devices
#!/usr/bin/env python
#with information from http://paulbourke.net/dataformats/spacemouse/
smkeys=('1','2','3','4','5','6','7','8', '*','L','R','?')
nibble2sm=('0','A','B','3','D','5','6','G','H','9',':','K','<','M','N','?')
sm2nibble=dict(zip(nibble2sm,range(16)))
sm2nibble2=lambda x:ord(x) & 0xf
binary=False
def sm2coord(cstr):
@5263
5263 / hamster.py
Created July 13, 2012 16:46
start and end hamster activities by manipulationg the DB
#!/usr/bin/env python
import sqlite3,datetime,sys
def buildactdict(c):
c.execute('SELECT id,name from categories')
catdict=dict(((cat[0], cat[1]) for cat in c.fetchall()))
c.execute('SELECT id,name,category_id from activities')
actdict=dict(((act[0], '%s@%s' % (act[1],catdict.get(act[2]))) \
for act in c.fetchall()))
return actdict
def findunfinished(c):
@5263
5263 / mailbox.py
Created June 28, 2012 19:10
List new e-mails from IMAP mailbox ordered by spamscore
#!/usr/bin/env python
import imaplib,getpass
import email
import email.header
import email.utils
import re
def decodestr(str1):
str2,enc=email.header.decode_header(str1)[0]
if enc:
return str2.decode(enc)
@5263
5263 / gist:2842792
Created May 31, 2012 11:31
WIP: ISO261 Thread script for FreeCAD
import Part, FreeCAD, math
iso261pitchregular={1.0:0.25, 1.1:0.25, 1.2:0.25,
1.4:0.30,
1.6:0.35, 1.8:0.35,
2.0:0.4,
2.2:0.45, 2.5:0.45,
3.0:0.5,
3.5:0.6,
4.0:0.7,
4.5:0.75,
@5263
5263 / Export.html
Created March 23, 2012 15:51
Mirror of Exporter of OpenSCAD CSG files for FreeCAD by Keith Sloan
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Frameset//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-frameset.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<title>Untitled Document</title>
</head>
<frameset rows="*" cols="147,*" framespacing="0" frameborder="no" border="0">
<frame src="../menu.html" name="leftFrame" scrolling="No" noresize="noresize" id="leftFrame" />
<frame src="Export_main.html" name="mainFrame" id="mainFrame" />
@5263
5263 / ImportCSG.html
Created March 12, 2012 13:57
Mirror of Importer of OpenSCAD CSG files for FreeCAD by Keith Sloan
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Frameset//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-frameset.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<title>Untitled Document</title>
</head>
<frameset rows="*" cols="150,*" framespacing="0" frameborder="no" border="0">
<frame src="../menu.html" name="leftFrame" scrolling="No" noresize="noresize" id="leftFrame" />
<frame src="ImportCSG_main.html" name="mainFrame" id="mainFrame" />
@5263
5263 / Extrusions.py
Created February 7, 2012 13:51 — forked from thehans/Extrusions.py
Parametric Aluminum Extrusion Module
import math
from FreeCAD import Base
#Main class for general extrusion related methods
class ExtrusionProfile():
def __init__(self, profile):
self.profile = profile
def makeExtrusion(self, p1, p2, rotateAngle=0):
"""Generates an extrusion which connects between two points,