Skip to content

Instantly share code, notes, and snippets.

View hrgdavor's full-sized avatar

Davor Hrg hrgdavor

  • RGO communications
  • Croatia
View GitHub Profile
@hrgdavor
hrgdavor / matcher
Created October 17, 2015 20:57
small, simple, matcher function factory for searching DOM nodes
/** any tag
- () - any alement that is a tag and not TextElement
- (func) - matching decided by the provided function
- (tag) - element with that tag
- (attr,value) - element with attribute and value for it
- (tag,attr,value) */
function matcher(p1,p2,p3){
if(typeof(p1) == 'function') return p1;
if(!p3){
if(!p2){
@hrgdavor
hrgdavor / Highlander.java
Created March 10, 2017 12:15
Use a TCP port to check if another instance is running ad stop it (for dev when restarting app multiple times to test)
import java.io.BufferedReader;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.OutputStream;
import java.net.InetSocketAddress;
import java.net.ServerSocket;
import java.net.Socket;
public class Highlander {
@hrgdavor
hrgdavor / Bits.java
Last active April 25, 2017 16:48
java convert long to 64 bits(0|1) string
public class Bits{
public static void main(String[] args){
long val = -12435L;
System.out.println(longBits(val));
// 1111111111111111111111111111111111111111111111111100111101101101
System.out.println(longBitsSpaced(val));
// 11111111 11111111 11111111 11111111 11111111 11111111 11001111 01101101
}
@hrgdavor
hrgdavor / TestBitMask.java
Last active May 4, 2017 08:38
java Example of generating bit masks with "ones" one the left or on the right // ((1<<x)-1) // (-1<<x)
public class TestBitMask {
public static void main(String[] args) throws Exception{
System.out.println("Java integer bit mask example");
System.out.println();
System.out.println("Zeroes on the left and x ones on the right. Formula: ((1<<x)-1)");
for(int x=1; x<32;x++) {
System.out.println(x+"\t "+padRight( ((1<<x)-1) ,12) +""+intBitsSpaced(((1<<x)-1)));
}
var len = 200;
var off = 2.5;
function main() {
return shape().subtract(holes()).translate([-100,-25,0]);
// return
}
function shape(){
return prism(len,25,10).union([
@hrgdavor
hrgdavor / organizers.js
Last active September 24, 2020 13:08
OpenJSCAD example, spoon organizers
var funcs = {};
function getParameterDefinitions() {
var defs = [];
defs.push({
name:'piece',
caption:'Piece', type:'choice',
values: [
'funcs.Spoon_Small',
@hrgdavor
hrgdavor / rounded_top.js
Last active October 6, 2020 18:44
openjscad V2 rounded top
/**
* Extrude rounded top From Slices
* @description Demonstrating the advanced extrusion using slices to create rounded top
* @tags extrude, slice, slices, extrudefromslices, callback
* @authors Davor Hrg
* @licence MIT License
*/
const { circle, square, roundedRectangle } = require('@jscad/modeling').primitives
@hrgdavor
hrgdavor / testCylinderFromTo.js
Last active November 1, 2020 15:07
openjscad utility cylinderFromTo
const jscad = require('@jscad/modeling')
const { connectors, geometry, math, primitives, text, utils, booleans, expansions, extrusions, hulls, measurements, transforms } = jscad
const { translate, scale, center, rotate } = transforms
const { cuboid, sphere, cylinder, circle, star,cylinderElliptic } = jscad.primitives
function main(){
var ret = [];
function testCylinderFromTo(p1,p2){
ret = [ ...ret,
@hrgdavor
hrgdavor / towel_hanger.js
Last active December 8, 2020 09:26
towel hanger
/*
.\_dev_build\watch_dev.bat -l .\_useful\towel_hnager.jscad
*/
var _parameters = [
{name:'pipeDiameter',caption:'Pipe diameter', type:'int', initial:23},
{name:'pipeDistance',caption:'Pipe distance', type:'int', initial:36},
{name:'width',caption:'width', type:'int', initial:10},
{name:'thick',caption:'Thickness', type:'float', initial:3.5},
{name:'preview',caption:'Preview', type:'checkbox', checked:false},
];
@hrgdavor
hrgdavor / tesseract.jscad
Created January 23, 2021 12:55
Configurable hypercube(tesseract) for 3D print
/*
Configurable hypercube(tesseract) https://en.wikipedia.org/wiki/Tesseract
Used it for 3D printing for a friend and to play with jscad.
@author Davor Hrg (https://github.com/hrgdavor)
*/
const {primitives, transforms, maths, extrusions, geometries} = require('@jscad/modeling')