Langweiliges Zeug. Was sonst.
OpenCL: Optimal work group size

If you ever try to determine the optimal work group size, you have to keep an odd thing in mind: most implementations have significant performance boosts for powers of two. So just benchmark performance for 512, 1024, 2048… workers.
In tests, 1024 workers performed 60 times better than 1023 or 1025 workers.

Lenovo ThinkPad T530 - Monitor dock support with linux

The T530 has two graphic chips: a low power intel and a dedicated nvidia one. Using bumblebee I was not able to get Twin View working. I just ended up with activating only the discrete nvidia chip using a BIOS setting. After that I was able activate twin view in nvidia-settings.

However, it is pretty inconvenient to navigate in that GUI every time you dock your thinkpad. That’s why I created a disper cycle script in a custom gnome-keybinding-properties shortcut:

disper --cycle-stages='-d DFP-2,DFP-0 -e -t left: -d auto -e : -d auto -s : -S' -C
The use cases for these modes are:
  1. Docked mode. Main screen on external monitor (has to be listed first), secondary screen on laptop.
  2. Presentation mode. Main screen on laptop, secondary on beamer.
  3. Single mode. Used before undocking
  4. Secondary only mode.
Repeatedly pressing of the assigned shortcut will cycle through all modes.
JavaScript: Remove element from Array
Forget about awkward splice and indexOf loops! Use the power of closures TODAY!
var removeMe = 4;
var array = [5, 1, 3, 4, 2, 1, 4];
array.filter(function(x) { return x != removeMe;});
// output: [5, 1, 3, 2, 1]
gnuplot: yerror AND outliers
File foo.dat:
# x med q25 q75 min max 
1   138,5   135 146 132 228 
file.plot:
# yerror bars
set style line 1 lt rgb "blue" lw 1
# outliers, pt 6 = points instead of crosses
set style line 2 lt rgb "red" lw 1 pt 6
plot "foo.dat" ls 1 title "" with yerror, "foo.dat" using 1:5 ls 2 title "" with points, "foo.dat" using 1:6 ls 2 title "" with points
utf8 encode/decode in java
You might want to encode/decode strings in java but are unable to use conventional classes. This could be for example due to a restrictive environment like google web toolkit (gwt). In this case, you can use use these two methods:
private static String byte2str(byte[] utfarray) {
	StringBuilder sb = new StringBuilder();
	int i = 0;
	int c=0, c2=0, c3 = 0;

	while (i < utfarray.length) {

		c = (0xFF & utfarray[i]);

		if (c < 128) {
			sb.append((char)c);
			i++;
		} else if ((c > 191) && (c < 224)) {
			c2 =  (0xFF & utfarray[i + 1]);
			sb.append((char)(((c & 31) << 6) | (c2 & 63)));
			i += 2;
		} else {
			c2 =  (0xFF & utfarray[i + 1]);
			c3 =  (0xFF & utfarray[i + 2]);
			sb.append((char)(((c & 15) << 12)
					| ((c2 & 63) << 6) | (c3 & 63)));

			i += 3;
		}

	}

	return sb.toString();
}
private static byte[] str2byte(String string) {
	IndependentByteStream bos = new IndependentByteStream(string.length());
	for ( int n = 0; n < string.length(); n++) {

		char c = string.charAt(n);

		if (c < 128) {
			bos.write((byte) c);
		} else if ((c > 127) && (c < 2048)) {
			bos.write((byte) ((c >> 6) | 192));
			bos.write((byte) ((c & 63) | 128));
		} else {
			bos.write((byte) ((c >> 12) | 224));
			bos.write((byte) (((c >> 6) & 63) | 128));
			bos.write((byte) ((c & 63) | 128));
		}

	}

	return bos.toByteArray();
}
Ubuntu: import CA certificate as trusted
Using mumble and want to import your own CA certificate as trusted?
sudo cp /tmp/myCoolOwnCaCert.pem /etc/ssl/certs/
Google-web-tookit (gwt): Deserialize JSON array
To deserialize a JSON array you can use an Overlay Type. However, those examples return objects instead of arrays. Here an example of how this is case is handled: JSON:
[{"age": 42, "name": "arthur"}, {"age": 23, "name": "adam"}]
public class PersonRecord extends JavaScriptObject{
	protected PersonRecord() {

	}
	public final native String getName() /*-{ return this.name; }-*/;
	public final native int getAge() /*-{ return this.age; }-*/;
}

public class Deserialize {
	public static final native JsArray<PersonRecord> deserialize(
			String json) /*-{
		return eval('(' + json + ')');
	}-*/;
}
ROBOTS OR DINOSAURS?

dinosaurs, sorry :(

JavaScript HashSet: objects in associative arrays
As it turns out, associative arrays can’t be used as a cheap hashSET surrogate. Consider the following source:
var hashset = {};
var obj1 = new Object();
obj1['foo'] = 42;
hashset[obj] = true;

for(key in hashset)
  alert(key.foo);
This won’t work for a simple reason: Associative arrays only support simple types as key. Obj1 will be casted to string as soon as you use it as an index. Thus key.foo is inaccessible because strings don’t have a property “foo”. I ended up with a quick and dirty solution which should require O(1)/O(log n). Depends on the javascript implementation of associative arrays.
var _hashSetSufix = 0;

function HashSet() {
	this.data = {};
	this.counter = 0;
	this.objAttr = '_hashsetCounter_' + (_hashSetSufix++);
}

HashSet.prototype.add = function(obj) {
	obj[this.objAttr] = this.counter++;
	this.data[obj[this.objAttr]] = obj;
};

HashSet.prototype.contains = function(obj) {
	return this.objAttr in obj && obj[this.objAttr] in this.data;
};

HashSet.prototype.remove = function(obj) {
	delete this.data[obj[this.objAttr]];
	delete obj[this.objAttr];
};

// test

(function() {
	var hs = new HashSet();
	var obj1 = new Object();
	var obj2 = new Object();

	hs.add(obj1);

	if (!hs.contains(obj1) || hs.contains(obj2))
		alert("Hashset: selftest fail");

	hs.remove(obj1);
	if (hs.contains(obj1) || hs.contains(obj2))
		alert("Hashset: selftest fail2");
})();
Flash HTC Desire S HBOOT 2.00.0002
  1. Download ROM, place as .zip on sd card
  2. Unlock bootloader: www.htcdev.com/bootloader/unlock-instructions/
  3. Get in fastboot mode, boot cwm:
    ./fastboot boot /tmp/recovery-clockwork-5.0.2.0-saga.img
  4. Wipe
  5. Install zips
  6. Reboot
  7. If stuck at loading screen: flash boot.img by hand
    ./fastboot flash boot /tmp/boot.img