Wrote a class, which queries the package manager in order to fetch the package name, version code/name and permissions for a given app. There's also a method which returns a html formatted string which could be used to display your app's info (probably in a TextView or an AlertDialog). This will help avoid creating a separate 'about' HTML for your app. Go through this link for more information on this class. (The source file has been released under APACHE LICENSE2)
Tuesday, February 1, 2011
Monday, January 24, 2011
Setting up LG-Optimus One for development
I have been writing android-apps for over more than 8 months now. Finally, I got hold of my first android smart-phone, LG-Optimus One (Model name P500). The following were the steps I had to perform in order to get this phone ready for Android development.
Installing USB driver:
By default, this phone will not be detected over USB, as windows (Win7 32b) failed to find the USB driver for this device. Google search suggested that P500 USB driver needs to be manually installed. To do that, just go to the following link: http://www.lgforum.com/resources/ and select the 'LGAndroidDriver_Ver_1.0_All.exe' executable (about 9.4MB). Then run this exe in order to install the USB driver. Wallah! You're done!
Enabling USB debugging:
Again, by default, USB debugging will be disabled on this phone. (Makes perfect sense as this feature is for development only) In order to enable just select the Settings -> Applications -> Development -> USB debugging check-box. Now connect the USB cable. After this, open a command-prompt and then type adb devices. You'll see something like this:
> adb devices
List of devices attached
****************** device
****************** device
You're done! Now, you should be able to run an application (assuming android:debuggable is set true in the app's AndroidManifest.xml) and see the log messages through 'ddms'.
Happy coding!
Thursday, January 20, 2011
traceview fails to find the trace file (on windows)
You have the trace file 'my-trace.trace' present in the current working directory. However, when you type traceview my-trace, you would get the error message: "trace file 'my-trace' not found". Even if you append the trace file with the '.trace' extension, you would get the same error message.
Somehow, the traceview cannot recognize relative paths. So, the solution is to pass the absolute path of the trace file as input to the traceview.
EG: traceview C:\path\to\file\my-trace
(PS: It's been assumed here that the android-tools folder is in your PATH env-variable.)
Sunday, January 2, 2011
Kaprekar-Numbers
Kaprekar-numbers are interesting. For eg.: 703 is a kaprekar-number. Reason: 7032 = 494209 and 494 + 209 = 703. It's also been proven that one can get all the Kaprekar-numbers by prime factorization of 10n-1. However, I wanted to list all the Kaprekar-numbers by solving it in its pure form! A number 'k' (in base 10) is called as Kaprekar-number if it can be expressed in the form:
k = q + r and k2 = q * 10n + r
Where, q >= 1, 0 < r < 10n
I've hosted this program on github at the following location (read-only): git://github.com/teju85/Kaprekar-Numbers.git. If you are interested in this, please download the program and follow the instructions inside the 'README'.
I profiled this program and here are the results:
$ make profile printCpuInfo.sh Processor Information: processor : 0 vendor_id : GenuineIntel model name : Intel(R) Xeon(R) CPU X5355 @ 2.66GHz kaprekarnumber -nooutput -profile -limit 10000 Found 17 kaprekar-numbers among first '10000' integers. Took 0.001309 seconds to search for self-numbers among these integers. kaprekarnumber -nooutput -profile -limit 100000 Found 24 kaprekar-numbers among first '100000' integers. Took 0.014230 seconds to search for self-numbers among these integers. kaprekarnumber -nooutput -profile -limit 1000000 Found 54 kaprekar-numbers among first '1000000' integers. Took 0.188414 seconds to search for self-numbers among these integers. kaprekarnumber -nooutput -profile -limit 10000000 Found 62 kaprekar-numbers among first '10000000' integers. Took 1.616492 seconds to search for self-numbers among these integers.
Not sure whether the timings are 'optimal' or not. Still looking for possible optimizations...
Saturday, January 1, 2011
Removing password from pdf files
We frequently come across a lot of password-protected pdf's in our daily lives, be it our internet/credit-card bills. Problems come when we want to share these kind of files with others. We obviously don't want to share the password as well! There are a lot of (commercial!?) tools out there which claim to remove password from pdf files. However, we all know that ghostscript already provides an option of reading password-protected pdf files and then storing them back to hard-disk. So, wrote a wrapper-tool for myself in order to do this process for me. I've created a repo for this tool and is publicly available (for free, ofcourse!). If you want to use this tool, please download all the files from this repo: git://github.com/teju85/No-Pass.git.
Happy new year fellas!
Tuesday, December 21, 2010
Self-numbers
For any given base, a number is called as Self-number, if it cannot be represented as a sum of another integer and the sum of this integer's digits. Hmm... seems like a pretty simple coding-task. Indeed it is! Sat for about half-an-hour and here (released under GNU-GPL) is the program which can generate first 'n' self-numbers for base 10. I profiled this code and given below are the results:
$ make profile printCpuInfo.sh Processor Information: processor : 0 vendor_id : GenuineIntel model name : Intel(R) Xeon(R) CPU E5450 @ 3.00GHz selfnumber -nooutput -profile -limit 1000001 Found 0 self-numbers among first '1000000' integers. Took 0.004973 seconds to search for self-numbers among these integers. selfnumber -nooutput -profile -limit 10000001 Found 0 self-numbers among first '10000000' integers. Took 0.060016 seconds to search for self-numbers among these integers. selfnumber -nooutput -profile -limit 100000001 Found 0 self-numbers among first '100000000' integers. Took 0.597042 seconds to search for self-numbers among these integers. selfnumber -nooutput -profile -limit 1000000001 Found 0 self-numbers among first '1000000000' integers. Took 5.440813 seconds to search for self-numbers among these integers.
~5ms for 1 million numbers seems like pretty fast. Isn't it?
UPDATE1:
I moved this program to github. Read-only access for this is at git://github.com/teju85/Self-Numbers.git. I also optimized the inner loop to perform modulus operations only for one in 100 numbers. This way, I was able to reduce the run-time to 2ms for 1 million numbers!
UPDATE1:
I moved this program to github. Read-only access for this is at git://github.com/teju85/Self-Numbers.git. I also optimized the inner loop to perform modulus operations only for one in 100 numbers. This way, I was able to reduce the run-time to 2ms for 1 million numbers!
$ make profile printCpuInfo.sh Processor Information: processor : 0 vendor_id : GenuineIntel model name : Intel(R) Xeon(R) CPU X5355 @ 2.66GHz selfnumber -nooutput -profile -limit 1000001 Found 97786 self-numbers among first '1000000' integers. Took 0.002037 seconds to search for self-numbers among these integers. selfnumber -nooutput -profile -limit 10000001 Found 977787 self-numbers among first '10000000' integers. Took 0.018121 seconds to search for self-numbers among these integers. selfnumber -nooutput -profile -limit 100000001 Found 9777788 self-numbers among first '100000000' integers. Took 0.185008 seconds to search for self-numbers among these integers. selfnumber -nooutput -profile -limit 1000000001 Found 97777789 self-numbers among first '1000000000' integers. Took 1.789393 seconds to search for self-numbers among these integers.
FindBin equivalent in bash
Perl has a really useful module called 'FindBin'. Using this module, one can find the actual directory of the current script and also can find the real name of the script (when the current script is just a symlink). What's the equivalent of it in bash? Answer is 'FindBin.sh'.
I wrote this bash script to imitate the behavior of both $FindBin::RealBin and $FindBin::RealScript. You can find this script here. I uses the environment variable 'PATH' to figure out the dir name and actual name of the current script.
How use it?
It's really simple! 'FindBin.sh' currently accepts 2 command line options: '-bin' and '-script'. '-bin' is equivalent to FindBin::RealBin and '-script' is to 'FindBin::RealScript'. After these commandline options, just pass the name of the current script. (which is generally stored in $0).
Example: myRealBin=`FindBin.sh -bin "$0"`
Help?
Use the '-h' option with this script in order to know about its usage.
Help?
Use the '-h' option with this script in order to know about its usage.
Happy coding!
Subscribe to:
Posts (Atom)