Very glad to announce another daily-coding work: an extension for gnome deskbar applet to search and launch virtual machine. There is a plugin for gnome-do that does the same job. That’s what I create the the plugin for. I switched to deskbar because gnome-do’s Do.exe reminds me nightmares when I was a M$ Windows user. The deskbar applet has been a great replacement, however, the virtualbox plugin in Do is really impressive while deskbar doesn’t provide me the same functionality.
You can ignore words above and just take a look at the screenshot:

Download
Download the extension from (the highlighted one):
http://bitbucket.org/sunng/daily-coding/downloads/?highlight=5137
You can also trace the development at bitbucket project. However, the repository is mixed with other small code snippets. Currently, mercurial doesn’t support subdirectory pull. So there is no way to grab the deskbar-applet individually.
Installation
copy this file to /usr/lib/deskbar-applet/deskbar-applet/modules-2.20-compatible/ (Ubuntu installation for example) with super user privilege. Right click desktbar applet, select Preference, Searchers tab, hit “Reload” button, then check the Virtualbox Deskbar Module.

Issue
Feel free the report issues on bitbucket:
http://bitbucket.org/sunng/daily-coding/issues/
This content is published under the Attribution-Noncommercial-Share Alike 3.0 Unported license.
I’m sorry for the long title. Due to lack of documentation, it’s not easy to use python xpcom api from virtualbox sdk. The code below is just a sample that lists your installed virtual machines. It works on linux with VirtualBox OSE 2.0.8. Hope useful to you.
1 2 3 4 5 6 7 | import vboxapi vmsg = vboxapi.VirtualBoxManager(None, None) vbox = vmsg.vbox vmsg.mgr.getSessionObject(vbox) machs = vbox.getMachines() names = map(lambda x: (x.name,x.id), machs) print names |
Output:
This content is published under the Attribution-Noncommercial-Share Alike 3.0 Unported license.
Glad to announce my works this morning: A simple heatmap API based on HTML5 canvas.

The programming interface is rather simple now. To create such a heatmap, you just new a heatmap object by:
<canvas width="300" height="215" id="canv"></canvas>
heatmap = new HeatMap("canv");
Then read your dataset and push data into the heatmap:
heatmap.push(x, y, value);
At last, spread the data and get the canvas rendered:
heatmap.spread(); heatmap.render();
Now you got it.
For advanced usage, you can specify the resolution of heatmap by px:
heatmap = new HeatMap("canv", 2);
Large value will gain performance with low image quality.
Also, you can specify a value to define the attenuation value of each px.
heatmap.spread(5);
Finally, there is an option to use your own color schema for heatmap generation.
heatmap.render(function(value, maxValue){
var light = value / maxValue * 100;
return "hsl(20, 75%, "+light+"%)";
});
The parameters passed in are current pixel value and max value in whole context.
That’s all the toolkit. More functionality and options might be added in future. Grab it from my bitbucket page:
http://bitbucket.org/sunng/daily-coding/src/tip/canvas-heatmap/
There is a demo page which you can test the api by clicking canvas:

then click heatmap button!

This is the new year gift for my readers and my dear friends !
This content is published under the Attribution-Noncommercial-Share Alike 3.0 Unported license.
今天在工作用的ArchLinux上安装了用Openbox取代了GNOME桌面,感觉良好,回来尝试一下在Ubuntu上也做同样的事情。不料遇到问题,在完成基本的配置之后,Openbox Session无法启动,总是自动跳回gdm。查看.xsession-errors,是gnome-setting-daemon报错:
(gnome-settings-daemon:2519): GLib-CRITICAL **: g_propagate_error: assertion `src != NULL’ failed
既然是gnome-settings-daemon报错,就在.config/openbox/autostart.sh中注视掉和gnome-settings-daemon相关的部分:
# Make GTK apps look and behave how they were set up in the gnome config tools #if test -x /usr/libexec/gnome-settings-daemon >/dev/null; then # /usr/libexec/gnome-settings-daemon & #elif which gnome-settings-daemon >/dev/null; then # gnome-settings-daemon & # Make GTK apps look and behave how they were set up in the XFCE config tools #elif which xfce-mcs-manager >/dev/null; then # xfce-mcs-manager n & #fi
进而可以启动Openbox Session了,但是发现Conky仍然无法启动,经过搜索是sleep的时间不够长导致的。而根据launchpad上上的讨论,gnome-settings-daemon也可以在Openbox Session启动后正常运行,于是可以这样设置autostart.sh
(sleep 20 && conky 1>/dev/null 2>/dev/null) & (sleep 2 && tint) & (sleep 5 && tilda) & (sleep 20 && gnome-settings-daemon 1>/dev/null 2>/dev/null) &
tint和tilda对启动顺序没有明确的要求,conky和gnome-settings-daemon需要设置一个较长的等待时间。
这是Ubuntu中Openbox的一个bug,可以在此跟踪:
https://bugs.launchpad.net/ubuntu/+source/openbox/+bug/459005
openbox / tint2 / conky / tilda 还没来得及认真配置,呵呵。
再有,Ubuntu源里的的tint2版本很低,问题不少,不支持宽度的百分数配置,不支持systray等配置。建议安装开发版本:
http://code.google.com/p/tint2/wiki/Install#For_Ubuntu_9.10_%28Karmic%29
This content is published under the Attribution-Noncommercial-Share Alike 3.0 Unported license.
我草,这是真的吗,同志们是3:0吗??!!
是不是电视显示错了??!
我有生之年居然看到这一幕了!!!
人生啊,这是人生吗
见证历史了!!!
牛逼!!这是真的吗,这是他妈真的吗
邓卓翔!!
牛逼!!!
娘的,要下载录像
这他妈是真的吗??!!
去你妈的CCTV
去你妈的江和平
This content is published under the Attribution-Noncommercial-Share Alike 3.0 Unported license.
Simple-xml is an object-xml serialization and de-serialization framework. It’s featured by annotation-driven, light-weight and self-contained.
In simple-xml, pojos that will be serialized are annotated with @Root, @Element, @Attribute or @Text. The problem is, when handling with inheritance, if the actual type is different from declared type, simple-xml will add a “class” attribute for de-serialization consideration. That is, the parser will use this attribute to determine the schema of the xml element. However, this is of no useful when we do not parse xml by simple-xml. And there is also risk that the class attribute exposes our program’s internal structure.
Take following code as example:
@Root
public class Response{
@Element
private Object entry;
// getter and setter ...
}
public class OrderItem{
@Element
private String name;
// getter and setter ...
}
When you generate xml from classes above, you will have the entry element of response with an attribute “class”, which value is the qualified class name, like “package.OrderItem”.
This is done by simple-xml’s Strategy interface. By default, the Persister uses TreeStrategy which has an implementation of setElement like:
/**
* This is used to attach a attribute to the provided element
* that is used to identify the class. The attribute name is
* "class" and has the value of the fully qualified class
* name for the object provided. This will only be invoked
* if the object class is different from the field class.
*
* @param type this is the declared class for the field used
* @param value this is the instance variable being serialized
* @param node this is the element used to represent the value
* @param map this is used to maintain contextual information
*
* @return this returns true if serialization is complete
*/
public boolean setElement(Type type, Object value, NodeMap node, Map map){
Class actual = value.getClass();
Class expect = type.getType();
Class real = actual;
if(actual.isArray()) {
real = setArray(expect, value, node);
}
if(actual != expect) {
node.put(label, real.getName());
}
return false;
}
This is where class attributed. So to suppress the attribute, we simply override this method by inherit TreeStrategy. I take a inline class for convenience here.
Serializer s = new Persister(new TreeStrategy(){
@Override
public boolean setElement(Type type, Object value, NodeMap node, Map map){
return false;
}
});
Now it works, however, simple-xml won’t be able to deserialize xml generated by this modified strategy.
This content is published under the Attribution-Noncommercial-Share Alike 3.0 Unported license.








on
on