Mount samba file server to Linux Mint 17

1. Install cifs-utils package

2. Create a file for authentication information with root account

3. In authentication file, please specify username, password and domain.

4. Modify /etc/fstab file and to mount the samba at start-up.

Add following line to the end.

then use “mount -a” to mount immediately.

 

New virtual environment after laptop re-image

公司电脑终于被Re-image了,再也没有了Admin的权限,除了portable的软件,其它都要在系统里Order,然后推送。系统里的软件很少,五笔输入也没有一个。VMWare也是再也不能装了,虽然有正版的License,好在开源VirtualBox是可以的。在安装了新的Linux Mint 17环境之后,然后我惊喜的发现,VirtualBox和VMWare在使用上的感觉差别不大了,速度也很快。

又要开始工作了,在新环境里很爽!

一个小Tip,VirtualBox 4.2.16的Additions有点问题,要下载安装4.3.x的Additions。Maybe that’s for newer Linux!

Class.cast() vs. cast operator

A co-worker told me Class.cast() is better than cast opertor as it’s safer to handle null reference. Really?

Let’s take a look at the following code snippet. As you can see, basically, there is no difference. Both test cases can pass.

In the function of cast(), it does null and type check but still uses cast operator to cast object.

What’s the difference in byte code? See the source code and byte code (compiled by Java 7) of a simple test case.

Note: Internally, line index starts from 0.

For L1: Instruction of “CHECKCAST” will be invoked to do type casting. In JVM specification, you can find all details about it. Basically, it behaves the same as we expects. See more details here.

For L2: Function cast() will be invoke first and later “CHECKCAST” still needed. Why? I think Java compiler plays a trick. cast() is a generic function, which should return an object in T type. But in runtime, information of type will be erased. So compiler need to put an extra instruction here to do type casting, which should be the same for other generic functions. Actually, in cast(), “CHECKCAST” is not really invoked.

In that case, way to use case() has worse performance.

See a simple performance test.

And the difference is BIG.

Conclusion

I think in most cases, cast operator is safe and simple. But in some cases, when you only have Class object, such as some generic function/class, cast() is also a good choice.

When sharing SharedPreference among activities, pay more attention!

Generally, we update SharedPreference by its editor;

Then we use putXXX to update the value in it.

Finally, commit the change to save it to file. We often do it in onStop() or onDestroy()

It’s OK in one activity. But if multiple activities get the same preference, you need pay more attention. Since after committing, the previous settings, especially updated by other activities, may be lost. You may need a class to do updating/committing if you only want one preference. Or you can have multiple SharedPreference.

Manually uninstall OSGi bundle in the runtime

Sometimes in a RCP application, you may need to uninstall OSGi bundle in the runtime. With BundleContext, it’s doable. Here is a sample.

As you can see, you need to specify the bundle/plugin name.

Add watchpoint for variables in Eclipse

Sometimes, in debugging, we want program stopped when some variables are accessed or modified. To set traditional breakpoints for this case, you have to spend a lot of time to find all places to access or modify variables. It’s even harder when variables are passed to other object or the derivation hierarchy is complicated. In this case, watchpoint is a good helper.

In Eclipse, it’s quite easy to set watchpoint. In “Outline” view, you can right click on the variable you want to want and select “Toggle Watchpoint“. 2014-11-06_13-21-43

Then you can find a new watchpoint in “Breakpoints” view. You can see the icons of breakpoint and watchpoint are different.

2014-11-06_13-24-02

By default, watchpoint will be hit when accessing or modifying the watched variable. To change it, we can simply right-click the watchpoing and select “Breakpoint Properties…“.2014-11-06_13-27-11

 

 

Eclipse插件之EHEP

开发过程中偶然需要到查看Tar文件的格式,发现在Emacs里对Tar文件做了特别的处理,不能显然文件的原貌。网上搜索之后,发现Eclipse里有个很给力的插件。它就是EHEP。

安然很简单,用下面的Update Link,

http://ehep.sourceforge.net/update

当打开二进制文件时,在Editor中选择“Hex Editor“,

2014-11-04_12-01-52

然后就可以看到可爱的二进制文件了。

2014-11-04_12-03-40

 

在Android App里分享二进制文件

在Android App里想向别的程序分享二进制文件很简单,下面是段分享声音文件的例子。

 

Resolve an issue when launching Docker daemon

When I first tried to launch “docker -d” on Linut Mint 17, I got some errors.

To resolve it is easy, just use “root” to change the content of file of  “/sys/module/apparmor/parameters/enabled” from “Y” to “N”.

If path doesn’t have parent directory, File.getParent() will return null.

Found this behavior in a unit test case and in Java Doc, it’s described very clear.

String java.io.File.getParent()

Returns the pathname string of this abstract pathname’s parent, or null if this pathname does
not name a parent directory.
The parent of an abstract pathname consists of the pathname’s prefix, if any, and each
name in the pathname’s name sequence except for the last. If the name sequence is empty
then the pathname does not name a parent directory.

See following test cases,

Just pay attention on it!

 

 

没事写写博客,没事拍拍照片。。。