{{error}}
{{(quickSearchResults.length>10)?'10+':(quickSearchResults.length)}} {{(quickSearchResults.length==1)?'result':'results'}}
{{result.title}} {{result.timeStamp | mysql2ymd }}
I am sorry, no such article was written yet.
How to throw an exception in Java even if the compiler does not allow you to...
How to throw an exception that you are not allowed to...
Did you ever get frustrated when a previous developer declared an interface that simply won't allow you to throw a new type of exception?
Rethrow it wrapped in a runtime exception: throw new RuntimeException(myOldJunkyException)
Did you ever need to rethrow the very same exception as reported by a remote system?
Serialize it, receive it, and rewrap it in a synthetic new exception with new RuntimeException().setStackTrace(myNewSyntheticStackTraceIncludingRemoteJunkyLines)
Or, just throw it as it is, by breaking the "convention" of throwing only declared exceptions from the method signature (which anyway the JVM does not care much at run time)... Usage:
public static int main(String[] args) throws IOException {
	THROW(new RuntimeException());
	return "dummy statement that won't ever be executed, but it's requied to compile the function. The compiler cannot figure out that the THROW will throw an exception... :D".length();
}
PS: Don't try it on JVM clones, it might not work at all. Neither on Google's Dalvik...
2 files attached: HelperClass.java Usage.java
HelperClass.java Usage.java
Windows NTNET test on "Java code to check if LDAP (including AD over LDAP) with basic authentication works (check if user/password) is valid"
Thanks to Dmitriy, I put below additional notes and an example on real-life NTNET domain test (sterilized code). The code below was tested on my current (production) NTNET DC and it worked fine.
Notes: {domain_controller_machine} can be found by running Windows echo %logonserver%, then run tracert {logon_server} to identify it's full name.
{my_ntnet_user in short form} is my NTNET user without any realm or domain information.
1 files attached: Test.java
Test.java
Shortest (generally working) full-screen toggle coode
1 files attached: sample.html
sample.html
<div class='pull-right' onclick='$(this).find("a").toggle()'>
	<a onclick='for(var k in{request:1,webkit:1,moz:1,ms:1})try{document.documentElement[k+"RequestFullScreen"]();}catch(e){console.log(e)}'><%icon:maximize%></a>
	<a style='display:none' onclick='for(var k in{exitFulls:1,mozCancelFullS:1,webkitCancelFullS:1})try{document[k+"creen"]();}catch(e){console.log(e)}'><%icon:window%></a>
</div>
Java code to check if LDAP (including AD over LDAP) with basic authentication works (check if user/password) is valid
Straight-forward pinging an LDAP server (to check if also authentication works).
1 files attached: Test.java
Test.java
package dms;
import java.util.Hashtable;
import javax.naming.Context;
import javax.naming.Name;
import javax.naming.NamingException;
import javax.naming.directory.DirContext;
import javax.naming.directory.InitialDirContext;
import javax.naming.ldap.LdapName;
public class Test {
	public static void main(String[] args) {
		try {
			test();
		} catch (NamingException e) {
			System.out.println(e.getMessage());
		}
	}

	public static void test() throws NamingException {
		Hashtable<String, String> env = new Hashtable<String, String>();
		env.put(Context.INITIAL_CONTEXT_FACTORY,
				"com.sun.jndi.ldap.LdapCtxFactory");
		env.put(Context.PROVIDER_URL, "ldap://ldap_server.www.company.com:389/o=Users");
		env.put(Context.SECURITY_AUTHENTICATION, "simple");
		env.put(Context.SECURITY_PRINCIPAL,
				"CN=myUserName,CN=Users,DC=ldap_server,DC=www,DC=company,DC=com");
		env.put(Context.SECURITY_CREDENTIALS, "********");
		DirContext ctx = new InitialDirContext(env);
		Name name=new LdapName("invalid_name");
		Object o=null;
		ctx.bind(name, o);
		//Should throw "invalid name exception"
	}
}
jQuery.val("input[type=checkbox]"[,value]) custom setter and getter - to work similar to regular input fields
Sample script on how to overwrite the jQuery val() for checkbox fields so that jQuery.val("input[type=checkbox]"[,value]) is in line with the one for input text.
1 files attached: jQueryValOverwrite.js
jQueryValOverwrite.js
$.valHooks.checkbox.get=function(a){return $(a).attr('checked')?'checked':''}
	$.valHooks.checkbox.set=function(a,b){$(a)[$(a).attr('checked')?'removeAttr':'attr']('checked','checked');}
HTML5 Canvas - sample gauge for smart home monitoring systems
Wrapper over HTML5 canvas for polar drawing (coordinates origin are in the centre of the canvas, the angle coordinate goes anti-clockwise, and the unitary magniture is the minimum of width and height of canvas) is attached. Instantiation is:
		var canvas=document.getElementById(dialName+"_z");
		var drawing=new Drawing(canvas);
. Sample usage (partial code) is in Sample.js. Result is:

2 files attached: Canvas.js Sample.js
Canvas.js Sample.js
:for(var sensorIdx=0;sensorIdx<sensors.length;sensorIdx++){
	var dialName=sensors[sensorIdx];
	var canvas=document.getElementById(dialName+"_z");
	var drawing=new Drawing(canvas);
	drawing.clear();
	drawing.circle({w:0.5,r:1,fg:'#000',bg:'#448'});
	drawing.circle({r:0.85,fg:'#111',bg:'#eee'});
	drawing.line({w:4,fg:'#f00',from:{a:Math.PI/2,m:0},to:{a:Math.PI/2,m:0.98}});
	drawing.line({w:2,fg:'#ff0',from:{a:Math.PI/2,m:0},to:{a:Math.PI/2,m:0.97}});
	for(var hour=1;hour<=12;hour++){
		drawing.line({w:0.25,fg:'#777',from:{x:0,y:0},to:{a:offsetA-Math.PI*2*(hour)/(12),m:0.85}});
		drawing.text({a:offsetA-Math.PI*2*(hour)/(12),m:0.925,text:hour,size:0.125,fg:'#bbb'});
	}
	:
	if(MOUSE_OVER){
		if(dialName==MOUSE_OVER.sensor){
			MOUSE_OVER.at=Math.atan2(-MOUSE_OVER.y+canvas.height/2,MOUSE_OVER.x-canvas.width/2);
			while(MOUSE_OVER.at<0)
				MOUSE_OVER.at+=2*Math.PI;
			while(MOUSE_OVER.at>=2*Math.PI)
				MOUSE_OVER.at-=2*Math.PI;
			drawing.line({from:{a:0,m:0},to:{a:MOUSE_OVER.at,m:0.85},w:2,fg:'#f70'});
		}
	}
	:
	drawing.circle({w:0.5,r:0.4,fg:'#000',bg:'#dde'});
	var params={};
	drawing.text({x:0,y:1.2,text:allSensors[sensorProperties.name].label,size:0.2,align:'center',bg:'#000',fg:'#ff0'});
	var lastPoint=null;
	var tooltips=[];
	for(var dataIdx=0;dataIdx<data.length;dataIdx++){
		var x=data[dataIdx][0];
		if(lastTS-x>1000000)continue;
		if(!minTSIdx)minTSIdx=dataIdx;
		if(data[minTSIdx][0]>x)
			minTSIdx=dataIdx;
		var y=data[dataIdx][1+json.sensor2column[sensorProperties.name]];
		if(!data[dataIdx][1+json.sensor2column[sensorProperties.name]])continue;
		if((x==null)||(y==null))continue;
		x/=100;
		var min=x%100;
		var hour=((x-min)/100)%100;
		var params={};
		params.w=0.5+3*dataIdx/data.length*dataIdx/data.length;
		params.from=lastPoint;
		var chan=2.5+2.5*Math.sin(Math.PI*2*((12+6+hour-1)/24));
		chan=Math.round(chan);
		params.fg='rgba('+chan*255/5+',0,'+(5-chan)*255/5+','+(1)+')';
		params.to={};
		params.to.a=offsetA-2*Math.PI*(hour/12+min/12/60);
		while(params.to.a<0)
			params.to.a+=2*Math.PI;
		while(params.to.a>=2*Math.PI)
			params.to.a-=2*Math.PI;
		params.to.m=(y-minVal)/(maxVal-minVal)*0.4+0.4;
		params.y=y;
		if(lastPoint){
			drawing.line(params);
			if(MOUSE_OVER)
			if(dialName==MOUSE_OVER.sensor){
					//alert(params.from.a);
						//alert([params.from.a,MOUSE_OVER.at,params.to.a]);
						if(between(params.from.a,MOUSE_OVER.at,params.to.a)){
							if(tooltips.length==2)
								alert([params.from.a,MOUSE_OVER.at,params.to.a]);
							tooltips.push(dataIdx);
						}
				}
		}
		lastPoint=params.to;
	}
	var rezolutie=allSensors[sensorProperties.name].resolution;
	//alert(rezolutie);
	var actualValue=Math.round(params.y/rezolutie)*rezolutie;
	var yesterdaysValue=Math.round(data[minTSIdx][colIdx]/rezolutie)*rezolutie;
	actualValue=1*actualValue.toFixed(6);
	yesterdaysValue=1*yesterdaysValue.toFixed(6);
	var delta=actualValue-yesterdaysValue;
	delta=1*delta.toFixed(6);
	if(delta>0)
		delta='+'+delta;
	delta=delta+' ';
	//alert(data[minTSIdx][0]);
	drawing.text({x:0,y:-0.34,text:minVal,size:0.1,bg:"#bbb"});
	drawing.text({x:0,y:+0.34,text:maxVal,size:0.1,bg:"#bbb"});
	if(actualValue>yesterdaysValue){
		drawing.text({x:0,y:0.2,text:actualValue,size:0.25,align:'center',fg:params.fg,bg:params.fg});
		drawing.text({x:0,y:0,text:delta+"&#8599;",size:0.1,bg:"#f00",align:"center"});
		drawing.text({x:0,y:-0.15,text:allSensors[sensorProperties.name].um,size:0.2,align:'center',fg:params.fg,bg:params.fg});
		//drawing.text({x:0,y:-0.05,text:delta,size:0.1,align:"center"});
	}else if(actualValue<yesterdaysValue){
		drawing.text({x:0,y:0.2,text:actualValue,size:0.25,align:'center',fg:params.fg,bg:params.fg});
		drawing.text({x:0,y:0,text:delta+"&#8600;",size:0.1,bg:"#00f",align:"center"});
		drawing.text({x:0,y:-0.15,text:allSensors[sensorProperties.name].um,size:0.2,align:'center',fg:params.fg,bg:params.fg});
		//drawing.text({x:0,y:-0.05,text:,size:0.1,align:"center"});
	}else{
		drawing.text({x:0,y:0,text:actualValue+allSensors[sensorProperties.name].um,size:0.2,align:'center',fg:params.fg,bg:params.fg});
	}
JackRabbit JCR - initial setup and "Hello World" to check that R/W access was granted
How I made the first Jackrabbit JCR have R/W access on the local environment. The smoke test (ran from a different application) is mentioned in SmokeTest.java. The reason I published this trivial code snippet (most of it copied from somewhere from the internet) is that I got frustrated for hours searching for a working snippet to grant me writing access.
2 files attached: Test.java SmokeTest.java
Test.java SmokeTest.java
Node root=session.getRootNode();
System.out.println(root.addNode("message!").getPath());
root.setProperty("number",123); System.out.println(root.getPath());
System.out.println(root.getNode("message!"));
How to batch-kill processes in Windows from command prompt - taskkill /im image.exe /t /f
Automating web pages in Chrome using Selenium leads to lots of Chrome windows open that even if closed, the driver remains open. I am using the command taskkill /im chromedriver.exe /t /f to:
  • close all the Chrome Driver server processes;
  • close the Chrome Driver server process tree of children (/t);
  • close the Chrome Driver server processes forcefully (/f);
How to parse in PHP the cPanel mime type configuration, and how to filter the files using the .htaccess
Hosting more sites on a single IP and with an economic entry-level support from ISP (but still, allowed to process requests from more domains through the same PHP engine) leads to a long series of challanges.
One of them is that even though each site has its own files structured in its own folder, in case that a file was not found or there were conflicting files, the server seemed to pick randomly a file from another domain's folder.
Problem looked solved with the following configuration:
#Resources to their folders
RewriteCond %{REQUEST_URI} \.(pdf|doc|xml|pem|crx|apk|svg)$
RewriteCond %{DOCUMENT_ROOT}/%{HTTP_HOST}%{REQUEST_URI} -f
#RewriteCond %{DOCUMENT_ROOT}/%{HTTP_HOST}%{REQUEST_URI} !-d
RewriteRule ^(.+)$ %{HTTP_HOST}%{REQUEST_URI}
But it does not do what it should obviously do (due to whatever small detail, mistake, or misunderstanding from my side), so I found myself in need to filter the files through PHP code (yes, I know, let the web server deliver the static file contents). But until this will happen, I had to urgently improvise the code below.
The problem got solved by .htaccess-routing all the txt|png|jpeg|... to .mimeDelivery.php code (mentioned below).
The principle is that the script picks all the htaccessed mime types (as saved by cPanel in Perl store (serialized form). Perl deserialization algorithm is mentioned below.
1 files attached: Algorithm.php
Algorithm.php
Android - how to find the physical size of a display - using the DPI/PPI scale
Most of solutions found on internet compute the diagonal of the display by dividing the number of pixels to the DPI resolution. The capital mistake is that the DPI returns the dots per inch, and not the pixels. For this, you may use the scaledDensity to convert from DPI to PPI.
		float x=outMetrics.widthPixels/outMetrics.xdpi;
		float y=outMetrics.heightPixels/outMetrics.ydpi;
		double diag=Math.hypot(x, y);
		double physicalDiagonal=diag/outMetrics.scaledDensity;
		s+="Diag. logică: "+diag+";\n";
		s+="Diag. fizică: "+diag/physicalDiagonal+"\"";