Skip to content

Instantly share code, notes, and snippets.

View jay3sh's full-sized avatar

Jayesh Salvi jay3sh

View GitHub Profile
@jay3sh
jay3sh / node-cli.js
Created September 23, 2011 02:42
How to write interactive CLI utility in node.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 / guard-my-mabook-when-i-am-away.sh
Created March 30, 2016 16:46
Guard My Macbook When I'm Away
#!/bin/bash
#
# When you are working on your macbook sitting in cafe and you have to go pee,
# you need some way to guard you machine.
#
# Start this script, remove any earphones, and go do the job.
# The assumption is the thief will close the lid of the laptop before taking it away.
# This script detects the closing of the lid and plays some loud audio that will
# likely distract the thief and/or grab attention of nearby people, making the
@jay3sh
jay3sh / cube-building.py
Created November 9, 2011 10:07
Build cube in PythonOCC (from vertex-face data)
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
### Keybase proof
I hereby claim:
* I am jay3sh on github.
* I am jay3sh (https://keybase.io/jay3sh) on keybase.
* I have a public key ASDisveofvyc0qtIYvkSUPKfTfFhBhMTHkUTUUP9SQKH1Ao
To claim this, I am signing this object:
@jay3sh
jay3sh / CMakeLists.txt
Created May 14, 2017 12:56
CMakeLists.txt for GSL project to make it browsable in Qt Creator
cmake_minimum_required(VERSION 3.0.0)
project(GSL)
set(CMAKE_C_COMPILER "/usr/bin/gcc")
set(CMAKE_VERBOSE_MAKEFILE ON)
file(GLOB_RECURSE SRC_LIST ${CMAKE_CURRENT_SOURCE_DIR}/*.c)
file(GLOB_RECURSE INC_LIST ${CMAKE_CURRENT_SOURCE_DIR}/*.h)
@jay3sh
jay3sh / stack-trace-without-exception.js
Created August 20, 2011 10:33
print stack trace anywhere
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 / minimum-opengles-code.html
Created August 26, 2011 13:46
Minimum length WebGL code to draw least meaningful output - A straight line
<html>
<head>
<title></title>
<script type="text/javascript">
var fragShaderSource = "\
precision highp float;\
uniform vec4 u_color;\
void main(void) {\
gl_FragColor = u_color;\
}\
@jay3sh
jay3sh / 7.coffee
Created November 24, 2012 07:52
Switch-To-Coffeescript-Code-Snippets-2
# While invoking a function you don't have to put the arguments in parenthesis.
# Instead of writing
console.log(message)
# You can write
console.log message
# Although this is convenient, it can be confusing for nested function calls
foo bar 2,3
# is equivalent to
foo(bar(2,3))
@jay3sh
jay3sh / 1.coffee
Created November 24, 2012 03:27
Switch-To-Coffeescript-Code-Snippets
methodfoo : (arg0) ->
func = => x = @someproperty
func()
@jay3sh
jay3sh / forum_main.cpp
Created September 3, 2012 03:27
OpenCASCADE 6.5.3 Boolean operations hang
/*
* This Program hangs for values of TOTAL >10
* consuming about 90% when run with OCC 6.5.3 on Ubuntu 11.04
*
* Build instructions
*
* g++ -o forum_main.o -c -I$OCC_INSTALL_DIR/inc forum_main.cpp
*
* g++ -o main -Xlinker -rpath -Xlinker $OCC_INSTALL_DIR/lib forum_main.o \
* -L$OCC_INSTALL_DIR/lib -lTKernel -lPTKernel -lTKMath -lTKService -lTKV3d -lTKV2d -lTKBRep -lTKIGES -lTKSTL -lTKSTEP -lTKSTEPAttr -lTKSTEP209 -lTKSTEPBase -lTKShapeSchema -lTKGeomBase -lTKGeomAlgo -lTKG3d -lTKG2d -lTKXSBase -lTKPShape -lTKShHealing -lTKHLR -lTKTopAlgo -lTKMesh -lTKPrim -lTKCDF -lTKBool -lTKBO -lTKFillet -lTKOffset