Measuring text width/height without rendering

Please check this. is a solution using canvas function get_tex_width(txt, font) { this.element = document.createElement(‘canvas’); this.context = this.element.getContext(“2d”); this.context.font = font; return this.context.measureText(txt).width; } alert(‘Calculated width ‘ + get_tex_width(“Hello World”, “30px Arial”)); alert(“Span text width “+$(“span”).width()); Demo using EDIT The solution using canvas is not the best, each browser deal different canvas size. Here is … Read more

Load dimension value from res/values/dimension.xml from source code

In my dimens.xml I have <dimen name=”test”>48dp</dimen> In code If I do int valueInPixels = (int) getResources().getDimension(R.dimen.test) this will return 72 which as docs state is multiplied by density of current phone (48dp x 1.5 in my case) exactly as docs state : Retrieve a dimensional for a particular resource ID. Unit conversions are based … Read more

1D Number Array Clustering

Don’t use multidimensional clustering algorithms for a one-dimensional problem. A single dimension is much more special than you naively think, because you can actually sort it, which makes things a lot easier. In fact, it is usually not even called clustering, but e.g. segmentation or natural breaks optimization. You might want to look at Jenks … Read more