#!/usr/bin/python | |
import serial | |
import sys | |
import select | |
import os | |
ser=serial.Serial('/dev/ttyUSB0',115200) | |
BUF=4096 |
#!/usr/bin/env python | |
""" | |
Example usage: | |
find . -type f | head -3000 | ./suffixes.py | |
Use this to build a swish.conf file for swish-e, e.g: | |
IndexDir . | |
IndexOnly .h .qml .cpp .png .pro .qmlproject .svg .jpg .qdoc .qrc .json .js .sci .xml .pri .desktop .txt | |
IndexContents TXT* .h .qml .cpp .png .pro .qmlproject .svg .jpg .qdoc .qrc .json .js .sci .xml .pri .desktop .txt | |
""" |
class LinearRegression: | |
""" | |
>>> lr = LinearRegression() | |
>>> lst = [(0., 0.)] | |
>>> lr.add(lst[0][0], lst[0][1]) | |
>>> lr.get() | |
>>> lr.error() | |
>>> for nxt in [(1., 1.), (2., 2.), (4., 3.), (-1., -0.5)]: | |
... lst.append(nxt) | |
... lr.add(nxt[0], nxt[1]) |
OpenSCAD on the Linux box is faster than on the Macbook, I think, but it won't do recursion. Recursion must be done in Python. So the Sierpinski code must be rewritten as a Python script or an exercise in SolidPython that generates OpenSCAD.
The Linux version of OpenSCAD has a few other differences. Cylinders (and possibly spheres) don't support diameter arguments, only radius arguments. Anyway, I'm adding a Python script to perform the recursion and produce a flat *.scad file.
Or instead of all this nonsense resulting from the fact that the OpenSCAD in the Ubuntu repository is old and broken, you could just go to the download page and get a version that works correctly.
from functools import wraps | |
# A decorator without an argument. | |
def add_four(f): | |
@wraps(f) | |
def wrapped(x): | |
y = f(x) | |
return y + 4 | |
return wrapped |
# Can we do a JavaScript-like .then() hack in Python? | |
import threading | |
import time | |
class Sleeper(threading.Thread): | |
def __init__(self): | |
super(Sleeper, self).__init__() | |
self.f = None |
module home_depot_bucket() { | |
translate([0,0,14.25]) | |
difference() { | |
cylinder(h=1/4, d=14, $fn=30); | |
cylinder(h=1/4, d=12, $fn=30); | |
} | |
difference() { | |
cylinder(h=14.5, d1=10.5, d2=12.5, $fn=30); | |
translate([0,0,1/4]) | |
cylinder(h=14.5, d1=10, d2=12, $fn=30); |
Use OpenSCAD to take a slice from a 3D object and convert it to a 2D DXF file, suitable for laser cutting.
from math import cos, sin, atan2 | |
class Circle: | |
def __init__(self, x, y, radius): | |
self.x, self.y, self.radius = x, y, radius | |
def intersect_circles(first, second): | |
""" | |
>>> intersect_circles(Circle(0, 0, 1), Circle(1, 1, 1)) | |
((1.5700924586837752e-16, 1.0), (1.0, 0.0)) |