Skip to content

Instantly share code, notes, and snippets.

Avatar

Hermann Stamm-Wilbrandt Hermann-SW

View GitHub Profile
@Hermann-SW
Hermann-SW / wlog.js
Created Jun 25, 2022
OpenSCAD external NodeJS animation demo
View wlog.js
var fs = require("fs");
var writer;
function wait(ms) {
return new Promise(function (resolve) {
setTimeout(resolve, ms);
});
}
function rad2deg(r) {
return r / Math.PI * 180;
@Hermann-SW
Hermann-SW / calc60.ps
Created May 15, 2022
Determination of pentagon fold angle for C60 fullerene (truncated icosahedron)
View calc60.ps
%!
0 setlinewidth
/vertex { 2 copy 5 4 roll dup 4 1 roll
newpath 0 360 arc closepath
gsave 1.0 setgray fill grestore
stroke
12 ge {
@Hermann-SW
Hermann-SW / lmbda.cpp
Last active May 3, 2022
Self contained test code for partial initializing struct function pointers with lambdas (c++14)
View lmbda.cpp
// Copyright: https://mit-license.org/
//
// cpplint lmbda.cpp 2>&1 | grep -v "Is this a non-const reference?"
// g++ -Wall -Wextra -pedantic -std=c++14 -g lmbda.cpp -o lmbda
//
#include <assert.h>
#include <iostream>
#include <vector>
@Hermann-SW
Hermann-SW / C30.py
Created Apr 22, 2022
Planar drawing of C30 fullerene
View C30.py
#!/usr/bin/env python
import matplotlib.pyplot as plt
import networkx as nx
C30=[[9,10,1],[0,2,25],[1,18,3],[2,4,26],[3,16,5],[4,6,27],[5,14,7],[6,8,28],[7,12,9],[8,0,29],[0,11,19],[10,12,21],[11,8,13],[12,14,22],[13,6,15],[14,16,23],[15,4,17],[16,18,24],[17,2,19],[18,10,20],[19,21,24],[20,11,22],[21,13,23],[22,15,24],[23,17,20],[1,26,29],[25,3,27],[26,5,28],[27,7,29],[28,9,25]]
G = nx.Graph()
for i in range(len(C30)):
for j in C30[i]:
G.add_edge(i, j)
@Hermann-SW
Hermann-SW / ps_done.ps
Last active Apr 27, 2022
PostScript file with /vertex and /poly definitions useful for drawing graphs, with demo
View ps_done.ps
%!
0 setlinewidth
/Times-Roman findfont 12 scalefont setfont
newpath 8 99 moveto 601 99 lineto 601 692 lineto 8 692 lineto closepath stroke
/vertex { 2 copy 5 4 roll dup 4 1 roll
newpath 0 360 arc closepath
@Hermann-SW
Hermann-SW / tetrahedron_with_cylinder_edges.scad
Last active Apr 18, 2022
OpenSCAD unfilled tetrahedron with cylinder edges
View tetrahedron_with_cylinder_edges.scad
v=[[sqrt(8/9),0,-1/3],[-sqrt(2/9),sqrt(2/3),-1/3],[-sqrt(2/9),-sqrt(2/3),-1/3],[0,0,1]];
R=40;
r=1;
$fn=25;
for (a = [0:2], b = [a + 1:3]) hull() {
translate(R*v[a]) sphere(r);
translate(R*v[b]) sphere(r);
}
@Hermann-SW
Hermann-SW / tetrahedron.py
Created Apr 18, 2022
First (nearly) minimal script for execution in FreeCAD Python console
View tetrahedron.py
# store as eg. '/home/pi/tetrahedron.py', then execute in FreeCad Python console by:
# exec(open('/home/pi/tetrahedron.py').read())
import FreeCAD,FreeCADGui
import Part
import math
if FreeCAD.ActiveDocument == None:
FreeCAD.newDocument()
@Hermann-SW
Hermann-SW / planar_face_traversal.cpp
Last active Apr 5, 2022
Replaced hardcoded example graph by code to read fulgen.c output; here C60
View planar_face_traversal.cpp
//=======================================================================
// Copyright 2007 Aaron Windsor
//
// Distributed under the Boost Software License, Version 1.0. (See
// accompanying file LICENSE_1_0.txt or copy at
// http://www.boost.org/LICENSE_1_0.txt)
//=======================================================================
// Replaced hardcoded example graph by code to read fulgen.c output; here C60 fulleren:
// $ ~/plantri52/fullgen 60 ipr code 6 stdout 2>/dev/null | ./planar_face_traversal
//=======================================================================
@Hermann-SW
Hermann-SW / mjpeg_fps
Last active Mar 11, 2022
determine min/avg/max framerate of a mjpeg stream
View mjpeg_fps
#!/bin/bash
host=$1
port=$2
get="GET /?action=stream HTTP/1.1\r\nConnection: Keep-Alive\r\n\r"
(
read -r prev
read -r line
mi=$(echo "1/(${line}-${prev})" | bc -ql)
ma=${mi}
su=${mi}
@Hermann-SW
Hermann-SW / isPrime.js
Created Mar 5, 2022
Test whether "num" is prime slowly (vie regexp match) and report runtime
View isPrime.js
// GatewayScript script (IBM DataPower Gateways) that tests passed
// number "num" for being a prime slowly, via regexp match + reports runtime
//
var sm = require('service-metadata');
session.input.readAsJSON(function (error, num) { throwIf(error);
var t0 = sm.timeElapsed;
var iP = isPrime(num);
var t1 = sm.timeElapsed;
session.output.write(iP+" ("+(t1-t0)/1000.0+"s)");