Tuesday, April 23, 2013

Java: What is the difference between runnable jar library handling options in Eclipse?

When exporting a Java app into a Runnable Jar, there are three options in Eclipse. What is the difference?

Answer by Michael:
  1. Extract required libraries into JAR
    Extracts the actual .class files from the libraries your app uses and puts those .class files inside the runnable JAR. So, the runnable JAR will not only contain the .class files of your application, but also the .class files of all the libraries your application uses.

  2. Package required libraries into JAR
    Puts the actual JAR files of the libraries into your runnable JAR. Normally, a JAR file within a JAR file cannot be loaded by the JVM. But Eclipse adds special classes to the runnable JAR to make this possible.

  3. Copy required libraries into sub folder next to JAR
    Keeps the library JARs completely separate from the runnable JAR, so the runnable JAR will only contain the .class files of your application.

Ref:
eclipse - What is the difference between runnable jar library handling options? - Stack Overflow

Sunday, April 21, 2013

Android: EditText in ListView lose focus when the soft keyboard appears

Problem:
Using (numeric) EditText in ListView

1. tab on a EditText field
2. numeric keyboard show up
3. EditText lose focus
4. numeric keyboard switch to back to a regular keyboard


Workaround:
Use ScrollView + LinearLayout instead of ListView...

Ref:
android - When the soft keyboard appears, it makes my EditText field lose focus - Stack Overflow
android - Buggy ListView makes me sad - Stack Overflow

Thursday, April 18, 2013

Firefox: Restore a Lost or Discarded Session

Problem:
If Firefox was not closed properly, it would show a restore previous session option. If you missed that option, or you changed your mind after starting a new session, there is still hope to restore your previous session.


To restore a previous session:
1. browse to %AppData%\Mozilla\Firefox\Profiles
2. select your profile, e.g. xxxxxxxx.default
3. make a backup copy of sessionstore.bak and sessionstore.js
4. close Firefox (if you haven't already)
5. delete sessionstore.js
6. rename sessionstore.bak to sessionstore.js
7. launch Firefox


Ref:
Restore a Lost or Discarded Firefox Session in Three Quick Steps

Monday, April 8, 2013

Firefox: Change User Agent String For a Specific Domain

1. Enter about:config in the URL
2. Search for general.useragent.site_specific_overrides
3. Ensure its value is set to true
4. Right-click -> New -> String
5. Type general.useragent.override.[domain].com
     e.g. general.useragent.override.blogger.com
6. Enter the new user agent string

For example:
Mozilla/5.0 (Linux; U; Android 2.1-update1; en-us; Nexus One Build/ERE27) AppleWebkit/530.17 (KHTML, like Gecko) Version/4.0 Mobile Safari/530.17


Extra:
* To check your current user agent, enter about: in the URL
* To revert your changes, right-click on general.useragent.override.[domain].com -> Reset. The key will go away when you refresh the page.

Tuesday, January 8, 2013

TortoiseHg: ImportError: No module named repo

Problem:
I updated my TortoiseHg from version 2.4 to 2.6.2. When I try to launch Hg Workbench for the 1st time, it shows the following error:

    #!python
    ** Mercurial version (2.4.2).  TortoiseHg version (2.6.2)
    ** Command: --nofork workbench
    ** CWD: C:\Code
    ** Encoding: cp1252
    ** Extensions loaded: hgsubversion
    ** Python version: 2.7.3 (default, Apr 10 2012, 23:31:26) [MSC v.1500 32 bit (Intel)]
    ** Windows version: sys.getwindowsversion(major=6, minor=1, build=7601, platform=2, service_pack='Service Pack 1')
    ** Processor architecture: x86
    ** Qt-4.8.0 PyQt-4.9.1
    Traceback (most recent call last):
      File "tortoisehg\hgqt\workbench.pyo", line 564, in openRepo
      File "tortoisehg\hgqt\workbench.pyo", line 934, in _openRepo
      File "tortoisehg\hgqt\thgrepo.pyo", line 53, in repository
      File "mercurial\hg.pyo", line 111, in repository
      File "mercurial\hg.pyo", line 106, in _peerorrepo
      File "C:\Code\hgsubversion\hgsubversion\__init__.py", line 179, in reposetup
      File "mercurial\demandimport.pyo", line 86, in __getattribute__
      File "mercurial\demandimport.pyo", line 58, in _load
      File "C:\Code\hgsubversion\hgsubversion\svnrepo.py", line 99, in <module>
      File "mercurial\demandimport.pyo", line 86, in __getattribute__
      File "mercurial\demandimport.pyo", line 58, in _load
    ImportError: No module named repo

Solution:
It was actually caused by the out-dated hgsubversion extension.

1. goto TortoiseHg -> Global Settings
2. Extensions -> Edit File
3. comment out the hgsubversion variable with #
4. Hg Workbench should launch correctly now
5. update to the latest version of hgsubversion
6. re-enable the extension


Ref:
tortoisehg / thg / issues / #2090 - No module named repo — Bitbucket

Friday, November 2, 2012

Android: Taking Screenshot

Question:
How do I take screenshot on a Android device?

Answer:
Android 4.0 (Ice Cream Sandwich) or above:
 - Hold down the volume down and power button at the same time

Kindle Fire:
 - Hold down the volume down and power button at the same time

HTC devices:
 - Hold down the power button, then press Home

If you are a developer and have the Android SDK installed, you can use DDMS