Tuesday, December 31, 2013

Google App Engine Launcher - NameError: global name 'execfile' is not defined (Python)

When trying to run the helloworld example, it shows this error:

NameError: global name 'execfile' is not defined

This happens when you have multiple versions of python on your system. The App Engine sets its default to python 3 although it already searched and found python 2.7 on the system before installation!!

Anyway, to solve it, go to Edit -> Preferences and change Python Path to refer to Python 2.7

Sunday, December 22, 2013

Unable to execute dex: java.nio.BufferOverflowException.

When trying to run an android application from eclipse, I got this error

[2013-12-23 07:23:38 - Dex Loader] Unable to execute dex: java.nio.BufferOverflowException. Check the Eclipse log for stack trace.
[2013-12-23 07:23:38 - Spinner] Conversion to Dalvik format failed: Unable to execute dex: java.nio.BufferOverflowException. Check the Eclipse log for stack trace.

To solve it, right click on your project folder -> Android tools -> Add Support Library, and follow through the steps.

Edit: For some projects even this doesn't work and you have to set the target sdk to 19 (the latest as of the time of this post) in both the androidmanifest.xml and project.properties files.

Monday, December 9, 2013

Eclipse - Failed to create the java virtual machine

Running eclipse for the first time, I encountered the problem
"Failed to create the java virtual machine"
and the program didn't run.

There are two place in eclipse.ini that includes
--launcher.XXMaxPermSize
512m
make it
--launcher.XXMaxPermSize
256m

You may need to make the numbers smaller than 256 though, 128 or something and it should work


Saturday, November 9, 2013

Adding Git to Windows Path

This is under Windows 7, but it should work in a similar way for other versions.
  • Right-click on My Computer.
  • Click Advanced System Settings.
  • Click Environment Variables.
  • Under System Variables (or User Variables for ....), select PATH and click edit.
  • Add the following to the end of the line
      ;C:\Program Files\Git\bin;C:\Program Files\Git\cmd
 
This depends of course on where you have installed Git.
Then restart your command-line window. 

Sunday, November 3, 2013

BigInteger sqrt method

Since Java doesn't have a sqrt method for BigInteger, I found this one which works fine.
It's short and practical

source: http://faruk.akgul.org/blog/javas-missing-algorithm-biginteger-sqrt/

BigInteger sqrt(BigInteger n) {
  BigInteger a = BigInteger.ONE;
  BigInteger b = new BigInteger(n.shiftRight(5).add(new BigInteger("8")).toString());
  while(b.compareTo(a) >= 0) {
    BigInteger mid = new BigInteger(a.add(b).shiftRight(1).toString());
    if(mid.multiply(mid).compareTo(n) > 0) b = mid.subtract(BigInteger.ONE);
    else a = mid.add(BigInteger.ONE);
  }
  return a.subtract(BigInteger.ONE);
}
 

Saturday, October 12, 2013

How to take a screenshot in Sony Xperia Sola

Press and hold down the Power/Lock key and the sound DOWN key at the same time.

It's frustrating and in other models it's an option that appears when just holding down only the power key.

Tuesday, October 8, 2013

Python: error: Unable to find vcvarsall.bat

This error happens when you try to setup a new module but you don't have a C compiler installed on your system.
If you don't want to spend time and waste disk space installing a C compiler or if you don't how to install one, an easier solution would be to download a pre-compiled module from here

http://www.voidspace.org.uk/python/modules.shtml

Saturday, August 24, 2013

Solving SciTE indentation problem for Python

I had this annoying problem while coding python using SciTE.
SciTE uses TAB indentation instead of the regular 4 spaces. Moreover, it doesn't stick with the existing indentation of the current file.

To solve this problem:
  1. Go to Options -> Open Global Options File.
  2. Scroll down to #Indentation
  3. Modify the following variables
 indent.size=8
use.tabs=1
#indent.auto=1

to

indent.size=4
use.tabs=0
indent.auto=1

PS: Unfortunately, it does affect all other languages as well. Also, doing the same modifications only in python.properties file doesn't restrict the changes to python files.