Skip to content

Instantly share code, notes, and snippets.

Avatar

Jayesh Salvi jay3sh

View GitHub Profile
@jay3sh
jay3sh / cube-building.py
Created Nov 9, 2011
Build cube in PythonOCC (from vertex-face data)
View cube-building.py
import sys
from OCC.gp import gp_Pnt
from OCC.GC import GC_MakeSegment
from OCC.BRepBuilderAPI import \
BRepBuilderAPI_MakeEdge, BRepBuilderAPI_MakeFace, BRepBuilderAPI_MakeWire,\
BRepBuilderAPI_MakeShell, BRepBuilderAPI_MakeSolid
from OCC.BRep import BRep_Builder
from OCC.TopoDS import TopoDS_Shell, TopoDS_Solid
from OCC import StlAPI
@jay3sh
jay3sh / node-cli.js
Created Sep 23, 2011
How to write interactive CLI utility in node.js
View node-cli.js
var questions = [
{ id:'fname', text:'First Name', answerType:'str' },
{ id:'lname', text:'Last Name', answerType:'str' },
{ id:'age', text:'Age', answerType:'int' },
{ id:'weight', text:'Weight', answerType:'float' }
]
function ask(question, callback) {
var stdin = process.stdin, stdout = process.stdout;
@jay3sh
jay3sh / minimum-opengles-code.html
Created Aug 26, 2011
Minimum length WebGL code to draw least meaningful output - A straight line
View minimum-opengles-code.html
<html>
<head>
<title></title>
<script type="text/javascript">
var fragShaderSource = "\
precision highp float;\
uniform vec4 u_color;\
void main(void) {\
gl_FragColor = u_color;\
}\
View stack-trace-without-exception.js
function foo(args) {
var i, j, k;
// ...
// j acquires some interesting value
// Who called foo when j took this interesting value?
//
var e = new Error('dummy');
var stack = e.stack.replace(/^[^\(]+?[\n$]/gm, '')
.replace(/^\s+at\s+/gm, '')
@jay3sh
jay3sh / webworker-stacktrace.js
Created Aug 16, 2011
WebWorker stacktrace for debug
View webworker-stacktrace.js
//
// In the WebWorker
//
function debug(msg) {
postMessage(JSON.stringify({type:'debug',msg:msg}));
}
onmessage = function (e) {
try {
@jay3sh
jay3sh / webworker-debug.js
Created Aug 16, 2011
WebWorker postMessage for debug
View webworker-debug.js
//
// In the Main thread
//
var worker = new Worker('/path/of/webworker/code.js')
worker.onmessage = function (e) {
var result = JSON.parse(e.data);
if(result.type == 'debug') {
console.log(result.msg);
} else if(result.type == 'response') {
@jay3sh
jay3sh / shear-test.py
Created Jun 27, 2011
PythonOCC Shear transform testing
View shear-test.py
from OCC.BRepPrimAPI import *
from OCC.BRepBuilderAPI import *
from OCC.gp import *
from OCC import StlAPI
from OCC.Precision import *
from OCC.Utils.Topology import *
from OCC.TopoDS import *
from OCC.TopAbs import *
from OCC.BRepMesh import *
from OCC.BRep import *
View tornado-async-process-mixin.py
# Copyright (c) 2010, Philip Plante of EndlessPaths.com
#
# Permission is hereby granted, free of charge, to any person obtaining a copy
# of this software and associated documentation files (the "Software"), to deal
# in the Software without restriction, including without limitation the rights
# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
# copies of the Software, and to permit persons to whom the Software is
# furnished to do so, subject to the following conditions:
#
# The above copyright notice and this permission notice shall be included in
@jay3sh
jay3sh / menger-sponge.py
Created Jun 12, 2011
Menger Sponge generator
View menger-sponge.py
#!/usr/bin/python
from cadmium import *
LIMIT = 9
def count_zeroes(lst):
return sum(1 for x in lst if x == 0)
def menger_void(k):
View abstract.py
#!/usr/bin/python
from cadmium import *
b0 = Box(x=4,y=4,z=4, center=True)
s0 = Sphere(radius=2.5)
(s0 - b0).toSTL('abstract.stl')