Ok, now that i have my first app built in android, i want to give it to my client for a demo who does not have a android PAD, (or yet to have one)...so they have to use the emulator which comes with android SDK to install the APP and show it running like its an android device....
the steps are pretty much simple
(please note you dont need Eclipse or any plugin to just run a APK (android package), - they are needed only for developers to debug and stuff)...
1) install android SDK(google has enuf details for it)
2) RUN the emulator so taht it starts up and ready to install your app
3) copy the APK file to a particular folder (say Desktop)
4) open up the terminal and navigate to the andoird SDK folder
$ cd ./android
$ cd platform-tools
your current working directory would be the platform-tools which contains a file called ADB.exe which will install the APK to the android emulator device...
execute the command
$ ./adb install "APK file name"
it will show some messages like installing etc., and has to finally say SUCCESS...
go to the emulator and open up the menu by clicking the android menu button (its the little dots stacked at the bottom of the page and not the button labelled "MENU" on the emulator)
you must then see your app being displayed as an icon....
I have now finished with my POC and want to install it in my android emulator outside of Eclipse.
Here are the steps
Execute the emulator so that it starts and is ready to install new programs.
(you need to run the emulator.exe under the android SDK\Tools folder)
1) copy the APK file (which will under /bin directory) to "C:\myProject.apk" (this step is really not needed, but its just a failsafe method)
2) open the command prompt (in your PC and not in the emulator) and type
abd install c:\myProject.apx
this will install the APK file in the emulator
3) If you are getting "command not found" - navigate to the Android SDK/Tools folder
cd x:/androidsdkfolder/tools
and run command again.....
So now that i started doing my first android PAD project for one of my clients. We need to submit a POC which will showcase a work flow. A login screen, a screen with tab controls, a grid view with menu and a table layout with details.
Before I start the work i need to set my DEV environment. Being a C# developer for most of my life I am taking baby steps towards Java programming and that too with android. Interesting....
What we need ?
1) Android SDK
2) Eclipse
3) ADT Plugin for Java.
There is an excellent tutorial at the android developer community for setting up the environment, but I found my self stuck at a couple of places....so thought i should blog it myself...
1) Download the SDK from the location
http://dl.google.com/android/android-sdk_r08-windows.zip
Unzip the contents of the SDK (I choose to unzip the contents inside Program Files\AndroidSDK directory, so that I dont accidentally delete the contents by placing it somewhere else)
and execute the SDK Manager.exe, it will start downloading the platform(which takes around 2 hrs with a 150 KBPS actual download speed)
after installation the SDK folder will be populated with the platform details, you can see the various supported platforms inside the PLATFORM folder.
2) Download and Install Eclipse latest release - Eclipse website has detailed information on the installation. http://www.eclipse.org/downloads/ (download the one which says "Eclipse IDE for Java Developers)
After successful installation
Go to Help --> Software updates -->(or Help Install New Software in Eclipse - Gallileo) add the site "https://dl-ssl.google.com/android/eclipse/" to the updates directory and click the ADD software button, it will list down the details available to install and click NEXT & finish the installation...it will install the ADT plugin.
3) After installation the menu Android will appear in Window --> Preference menu, Navigate to it and Click the Browse button and set the path of the SDK folder --> click ok and apply --> restart Eclipse.
4) create a new AVD image - This is the Emulator that will open when you execute your android APP
select window --> Android SDK and AVD Manager and create a new device. Make sure that you choose the right version for your project.
Now we are ready to start a project
After create a new android project , set the target of Run configuration (Run-->run configuration --> android --> new configuration) to the AVD you just created.
when you RUN you app, the Emulator will start and you are ready to roll on...
Given 3 int values, a b c, return their sum. However, if any of the values is a teen -- in the range 13..19 inclusive -- then that value counts as 0, except 15 and 16 do not count as a teens. Write a separate helper "def fix_teen(n):"that takes in an int value and returns that value fixed for the teen rule. In this way, you avoid repeating the teen code 3 times (i.e. "decomposition"). Define the helper below and at the same indent level as the main no_teen_sum().
Given 3 int values, a b c, return their sum. However, if any of the values is a teen -- in the range 13..19 inclusive -- then that value counts as 0, except 15 and 16 do not count as a teens. Write a separate helper "def fix_teen(n):"that takes in an int value and returns that value fixed for the teen rule. In this way, you avoid repeating the teen code 3 times (i.e. "decomposition"). Define the helper below and at the same indent level as the main no_teen_sum().
def fix_teen(num):
if num >12 and num <20 and not num ==15 and not num ==16:
return 0
else:
return num
def no_teen_sum(a, b, c):
return fix_teen(a) + fix_teen(b)+fix_teen(c)
The number 6 is a truly great number. Given two int values, a and b, return True if either one is 6. Or if their sum or difference is 6. Note: the function abs(num) computes the absolute value of a number.
Given 3 int values, a b c, return their sum. However, if one of the values is 13 then it does not count towards the sum and values to its right do not count. So for example, if b is 13, then both b and c do not count.
Return the sum of the numbers in the array, except ignore sections of numbers starting with a 6 and extending to the next 7 (every 6 will be followed by at least one 7). Return 0 for no numbers.
def sum67(nums):
if len(nums) == 0:
return 0
sum = 0
sum671 = 0
for num in nums:
if num == 6 or not sum671 == 0:
sum671 += num
if num ==7 and not sum671 == 0:
sum-=sum671
sum671=0
sum +=num
return sum
We want to make a row of bricks that is goal inches long. We have a number of small bricks (1 inch each) and big bricks (5 inches each). Return True if it is possible to make the goal by choosing from the given bricks. This is a little harder than it looks and can be done without any loops.
def make_bricks(small, big, goal):
if big ==0:
return small >=goal
elif big*5 == goal:
return True
else:
rem = 0
if goal > big*5:
rem = goal - (big*5)
else:
rem = goal % 5
return small >= rem
Given a day of the week encoded as 0=Sun, 1=Mon, 2=Tue, ...6=Sat, and a boolean indicating if we are on vacation, return a string of the form "7:00" indicating when the alarm clock should ring. Weekdays, the alarm should be "7:00" and on the weekend it should be "10:00". Unless we are on vacation -- then on weekdays it should be "10:00" and weekends it should be "off".
We have two monkeys, a and b, and the parameters a_smile and b_smile indicate if each is smiling. We are in trouble if they are both smiling or if neither of them is smiling. Return True if we are in trouble.
def find(num,n):
dif = abs(num-n)
if dif <= 10:
return True
return False
def near_hundred(n):
ret = find(100,n)
if not ret:
ret = find(200,n)
return ret
Given an array of ints, return a new array length 2 containing the first and last elements from the original array. The original array will be length 1 or more.
Return the "centered" average of an array of ints, which we'll say is the mean average of the values, except not counting the largest and smallest values in the array. Use int division to produce the final average. You may assume that the array is length 3 or more.
def centered_average(nums):
sortednums = sorted(nums)
sortednums.remove(sortednums[0])
sortednums.remove(sortednums[-1])
sum = 0
for num in range(len(sortednums)):
sum+=sortednums[num]
return sum/len(sortednums)
You and your date are trying to get a table at a restaurant. The parameter "you" is the stylishness of your clothes, in the range 0..10, and "date" is the stylishness of your date's clothes. The result getting the table is encoded as an int value with 0=no, 1=maybe, 2=yes. If either of you is very stylish, 8 or more, then the result is 2 (yes). With the exception that if either of you has style of 2 or less, then the result is 0 (no). Otherwise the result is 1 (maybe).
The web is built with HTML strings like "<i>Yay</i>" which draws Yay as italic text. In this example, the "i" tag makes <i> and </i> which surround the word "Yay". Given tag and word strings, create the HTML string with tags around the word, e.g. "<i>Yay</i>".
Given an array of ints length 3, figure out which is larger between the first and last elements in the array, and set all the other elements to be that value. Return the changed array.
The squirrels in Palo Alto spend most of the day playing. In particular, they play if the temperature is between 60 and 90 (inclusive). Unless it is summer, then the upper limit is 100 instead of 90. Given an int temperature and a boolean is_summer, return True if the squirrels play and False otherwise.
You are driving a little too fast, and a police officer stops you. Write code to compute the result, encoded as an int value: 0=no ticket, 1=small ticket, 2=big ticket. If speed is 60 or less, the result is 0. If speed is between 61 and 80 inclusive, the result is 1. If speed is 81 or more, the result is 2. Unless it is your birthday -- on that day, your speed can be 5 higher in all cases.
def lone_sum(a, b, c):
list = [a,b,c]
sorted_list = sorted(list)
sum = 0
if not sorted_list[0] == sorted_list[1]:
sum += sorted_list[0] + sorted_list[1]
if not sorted_list[1] == sorted_list[2]:
sum += sorted_list[2]
elif not list == sorted_list:
sum -= sorted_list[2]
return sum
Given a string, return the count of the number of times that a substring length 2 appears in the string and also as the last 2 chars of the string, so "hixxxhi" yields 1 (we won't count the end substring).
def last2(str):
if len(str) < 2:
return 0
last2 = str[len(str)-2:]
count = 0
for i in range(len(str)-2):
sub = str[i:i+2]
if sub == last2:
count = count + 1
return count
Given 2 arrays of ints, a and b, return True if they have the same first element or they have the same last element. Both arrays will be length 1 or more.
Given a string, we'll say that the front is the first 3 chars of the string. If the string length is less than 3, the front is whatever is there. Return a new string which is 3 copies of the front.
Return True if the given string contains an appearance of "xyz" where the xyz is not directly preceeded by a period (.). So "xxyz" counts but "x.xyz" does not.
Given a non-empty string and an int n, return a new string where the char at index n has been removed. The value of n will be a valid index of a char in the original string (i.e. n will be in the range 0..len(str)-1 inclusive).
Given a number n, return True if n is in the range 1..10, inclusive. Unless "outsideMode" is True, in which case return True if the number is less or equal to 1, or greater or equal to 10.
def in1to10(n, outside_mode):
a=n
if outside_mode:
if a <=1 or a >=10:
return True
else:
return False
else:
if a >=1 and a <=10:
return True
else:
return False
Given three ints, a b c, return True if one of b or c is "close" (differing from a by at most 1), while the other is "far", differing from both other values by 2 or more. Note: abs(num) computes the absolute value of a number.
def pos_neg(a, b, negative):
if negative and a<0 and b<0:
return True
elif not negative and ((a<0 and b > 0) or (a>0 and b < 0)):
return True
return False
def cat_dog(str):
catcount = 0
dogcount = 0
for i in range(len(str)-2):
if str[i:i+3] =='cat':
catcount+=1
if str[i:i+3] =='dog':
dogcount+=1
return catcount == dogcount
Given a string and a non-negative int n, we'll say that the front of the string is the first 3 chars, or whatever is there if the string is less than length 3. Return n copies of the front;
Given a non-negative number "num", return True if num is within 2 of a multiple of 10. Note: (a % b) is the remainder of dividing a by b, so (7 % 5) is 2.
We have a loud talking parrot. The "hour" parameter is the current hour time in the range 0..23. We are in trouble if the parrot is talking and the hour is before 7 or after 20. Return True if we are in trouble.
The parameter weekday is True if it is a weekday, and the parameter vacation is True if we are on vacation. We sleep in if it is not a weekday or we're on vacation. Return True if we sleep in.
Given two strings, return True if either of the strings appears at the very end of the other string, ignoring upper/lower case differences (in other words, the computation should not be "case sensitive"). Note: s.lower() returns the lowercase version of a string.
For this problem, we'll round an int value up to the next multiple of 10 if its rightmost digit is 5 or more, so 15 rounds up to 20. Alternately, round down to the previous multiple of 10 if its rightmost digit is less than 5, so 12 rounds down to 10. Given 3 ints, a b c, return the sum of their rounded values. To avoid code repetition, write a separate helper "def round10(num):" and call it 3 times. Write the helper entirely below and at the same indent level as round_sum().
Given 2 strings, a and b, return the number of the positions where they contain the same length 2 substring. So "xxcaazz" and "xxbaaz" yields 3, since the "xx", "aa", and "az" substrings appear in the same place in both strings.
def string_match(a, b):
loopcount = len(a)
if len(b) < loopcount:
loopcount = len(b)
ret = 0
for i in range(loopcount-1):
if a[i:i+2] == b[i:i+2]:
ret+=1
return ret
Given a string, return the string made of its first two chars, so the String "Hello" yields "He". If the string is shorter than length 2, return whatever there is, so "X" yields "X", and the empty string "" yields the empty string "".
Given an array length 1 or more of ints, return the difference between the largest and smallest values in the array. Note: the built-in min(v1, v2) and max(v1, v2) functions return the smaller or larger of two values.
Return the number of times that the string "code" appears anywhere in the given string, except we'll accept any letter for the 'd', so "cope" and "cooe" count.
Given a string, return a new string where "not " has been added to the front. However, if the string already begins with "not", return the string unchanged.
Given an array of ints, return the sum of the first 2 elements in the array. If the array length is less than 2, just sum up the elements that exist, returning 0 if the array is length 0.
def array123(nums):
str = "".join(["%s" % el for el in nums])
if str.find('1') >= 0 and str.find('2') >= 0 and str.find('3') >= 0:
return True
return False
Given 2 strings, a and b, return a string of the form short+long+short, with the shorter string on the outside and the longer string on the inside. The strings will not be the same length, but they may be empty (length 0).
When squirrels get together for a party, they like to have cigars. A squirrel party is successful when the number of cigars is between 40 and 60, inclusive. Unless it is the weekend, in which case there is no upper bound on the number of cigars. Return True if the party with the given values is successful, or False otherwise.
Now that the solutions are downloaded, i dont know how to attach them as a file link here, so i need to extract all the QUESTION - ANSWER part and post it ....there goes the parsing again.....
this is the program that i used to parse the output and save the contents...
import sys
import re
import os
I am not sure whether this is a intellectual property right, but these are the exercises that I solved in coding bat, a site by Nick Parlante ( who was a inspiration for me to seriously look at Python )
ok I have been trying for an hour to hack into coding bat with my user name and password - using python urllib2 module, there seems to something that keeps me out of their pages.
I am just trying to download their tutorials and post it in my blog (the actual reason for creating this particular blog post), so i have downloaded this python module called mechanize which is very promising, have to try it out and see whether it works...
[EDIT:]
and it works !!! this is the download link for the web site
http://wwwsearch.sourceforge.net/mechanize/
and here is the coding that I used to get access to the web site and download the content
#/usr/bin/env python
import sys, os, re
from urllib2 import HTTPError
#s = mech.retrieve('http://codingbat.com','d:/aa.html')
#[EDIT]
#this page will throw up error stating the user or tag is expired, what you need to do is login to the web site and copy the link for the "DONE" page here
mech.retrieve('http://codingbat.com/done','d:/url.html')
content = open('d://url.html','r').readlines()
i=0
for line in content:
urls = re.findall(r'href=[\'"]p?([^\'" >]+)', line)
for url in urls:
if url[0:4] == '/pro':
i+=1
print "Processing",'http:/codingbat.com'+url
mech.retrieve(r'http://codingbat.com'+url,'d://myhack//'+str(i)+'.html')
#make sure you create a folder d:\myHack which will used to save the files.