Tuesday, December 29, 2009
Clear command in Cygwin
Basically, install ncurses package from Util and Libs.
Setup OpenSSH on Windows
Basically, install cygwin with OpenSSH selected. Then run "ssh-host-config" to configure it. "net start sshd" to start it.
Very easy to use and install. Then you can use "ssh" and "scp"!
Monday, December 28, 2009
Android Dev Notes
Attach android source to Eclipse:
http://stuffthathappens.com/blog/2008/11/01/browsing-android-source-in-eclipse/
Basically, download source from google and copy frameworks/base/core/java/ to android-sdk/platforms/android-version/sources.
But it didn't work at first attempt. It turns out eclipse's cache is preventing source from showing up. Deleted some directories (don't remember exactly what I deleted :) under eclipse-workspace/.metadata/.plugins/org.eclipse.core.resources/.history and .projects directory. Then the source file begins to show up.
The link for downloading source code is like this: http://git.source.android.com/?p=platform/frameworks/base.git;a=snapshot;h=HEAD;sf=tgz (Thanks for http://geekycoder.wordpress.com/2009/07/03/how-to-download-latest-zip-android-source-code-and-using-it-in-intellij/) This link is for HEAD, if you want to download tagged version, such as 1.5, you have to find the correct value for "h" as in "h=HEAD". It can be found here: http://android.git.kernel.org/?p=platform/frameworks/base.git;a=summary. Click any version you want, then in the URL, you can see the parameter value for "h".
Code Optimization for Dalvik VM
Accessing a local variable is much more efficient than accessing a field in the Dalvik VM. So creating a new local variable to refer to field variable will make the routine much more efficient. It is recommended that you use this optimization when possible.
Monday, December 21, 2009
Can not fix width for SPAN
Friday, September 25, 2009
Firefox cache executable jars
https://bugzilla.mozilla.org/show_bug.cgi?id=518850
Sunday, August 30, 2009
GWT Debug mode not working in Eclipse
Google came to rescue. After some search, this blog (http://gbacon.blogspot.com/2009/06/gwt-not-hitting-breakpoints-in-hosted.html) is complaining the same issue and it turns out to be the "newer" JDK version (1.6.0_14) is the culprit. So either upgrade to latest 1.6.0_16 or downgrade to 1.6.0_13 fixed the problem!
Thursday, August 20, 2009
HTML position: absolute inside relative
Tuesday, July 14, 2009
http://www.dailyreckoning.com.au/austrian-keynesian-bastiat/2008/02/15/
Frédéric Bastiat pointed to one: the belief that the destruction of wealth fuels its creation. He explains this by means of an allegory that has come to be known as the story of the broken window. Most famously it was retold as the opening of Henry Hazlitt's Economics in One Lesson, which is probably the bestselling economics book of all time.
A kid throws a rock at a window and breaks it, and everyone standing around regrets the unfortunate state of affairs. But then up walks a man who purports to be wise and all-knowing. He points out that this is not a bad thing after all. The man fixing the window will get money for doing so. This will then be spent on a new suit, and the tailor too will get money. The tailor will spend money on other items and the circle of rising prosperity will expand without end.
What's wrong with this scenario? As Bastiat put it, "It is not seen that as our shopkeeper has spent six francs upon one thing, he cannot spend them upon another. It is not seen that if he had not had a window to replace, he would, perhaps, have replaced his old shoes, or added another book to his library. In short, he would have employed his six francs in some way which this accident has prevented."
You can see the absurdity of the position of the wise commentator when you take it to absurd extremes. If the broken window really produces wealth, why not break all windows up and down the whole city block? Indeed, why not break doors and walls? Why not tear down all houses so that they can be rebuilt? Why not bomb whole cities so construction firms can get busy rebuilding?
Thursday, May 28, 2009
Tuesday, April 14, 2009
Groovy: No signature of method: java.lang.String.call()
The first time I ran into this, took some time to figure out. Maybe because I haven't got used to this dynamic language.
def sendMail(mailhost, port, from, to) {
ant.mail(mailhost:"${mailhostname}", mailport:"${port}", subject:'Test Email') {
from( address:"${from}" )
to( address:"${to}" )
message(msg)
}
}
Code above will throw this exception, because groovy will use input parameter "from" and "to" to evaluate from, to function ant.mail closure.
Change to a different name.
Tuesday, April 7, 2009
HTTP keep-alive
1. Keep-alive (default 300 seconds) will make the URL still work for 5 mins. But after that, it will need cookie to make download work.
2. If resuming download from middle of the file, i.e. bytes=(value > 0), then the download works fine. The server only validates the download request for the initial request starting from byte 0. This makes sense. It will make resuming download still works since it's already authenticated.
Saturday, March 14, 2009
Hibernate key generator per model
while ( classes.hasNext() ) {
PersistentClass model = (PersistentClass) classes.next();
if ( !model.isInherited() ) {
IdentifierGenerator generator = model.getIdentifier().createIdentifierGenerator(settings.getDialect(),
settings.getDefaultCatalogName(), settings.getDefaultSchemaName(),
(RootClass) model);
identifierGenerators.put( model.getEntityName(), generator );
}
}
This is quite flexible and customizable. Each table can configure a different sequence High Low key generator.
Same EntityKey for parent and child objects
After tracing into Hibernate, the reason looks to me is that Hibernate is using rootEntityName to generate hashcode for all subclasses. It will break if subclasses are using same id.
For example, Department (Dept) and Employee (Emp) class all extend from class Entity which has id attribute. When loading department and join fetching employees, if id in Dept table happens to have the same id in Emp table, that won't work. As of Hibernate 3.3.1 GA, in org.hibernate.engine.EntityKey:
private int generateHashCode() {
int result = 17;
result = 37 * result + rootEntityName.hashCode();
result = 37 * result + identifierType.getHashCode( identifier, entityMode, factory );
return result;
}
So the Dept and Emp are getting the same hashcode, and when loading Emp, Hibernate think it's already in cache, but that's Dept instance.
There is actually a ticket (not assigned yet) in Hibernate Jira: http://opensource.atlassian.com/projects/hibernate/browse/HHH-3445
It's easy to patch, but not sure whether it will break other parts in Hibernate.
Friday, March 13, 2009
Duplicated resultsets by join fetch
For example, Department (Dept) has many employees (Emp) and sales deparment has 5 employees:
- in HQL:
from Dept d join fetch d.emps where d.name = 'sales'will return 5 exact same department records, each with totally initialized employees - in mapping:
<set name="emps" table="EMP" inverse="true" fetch="join">will only return 1 department with 5 initialized employees. This works as expected.
One possible workaround is using setResultTransformer(Criteria.DISTINCT_ROOT_ENTITY). This works, although I feel they should fix it in the core.
Also see: http://glueclue.blogspot.com/2006/02/hibernate-duplicates-with-join-fetch.html
Sunday, March 8, 2009
Quotes - Confucius
http://en.wikiquote.org/wiki/Confucius
http://www.brainyquote.com/quotes/authors/c/confucius.html
Quotes - Lzo Tzu
http://www.brainyquote.com/quotes/authors/l/lao_tzu.html