Stuff android devs probably don’t know about

There are a couple of things I have found to be very useful while developing android applications. In my recent interactions with the android brethren, I noticed that a majority of them haven’t heard of these tools or didn’t know its true potential. Here, I am listing them out, so that you can benefit from it too.

1] ADB WiFi

ADB Wifi sceenshot
Allows you to connect your android device over wifi. This is a nifty little utility that comes to your rescue in case you have forgotten your ‘cable’ at home. This is also useful if you don’t like the tangled mess of cables on your desk. Simply connect your device and laptop to the same WiFi network and start the app. Once connected, you won’t notice the difference. This also reduces the amount of time your device is physically connected to the PC, which can otherwise cause your battery to degrade very quickly. The app requires your phone to be rooted, but what the heck, you are an android developer and you must have rooted the phone already. There are a number of variants of this app on Play Store.
ADB Wifi on Play Store

2] AirDroid

If you are an android developer, you must have heard of AirDroid. It is one of the top utility applications on the play store. It allows you to seamlessly connect any device over wifi and do lots of cool stuff. As a developer you will find it most useful to copy files to and from the devices, install and take backup of apps and get other important info from the device. It has many other uses for non-developers too.
AirDroid on Play Store

3] x86 based emulators

Everyone knows that the standard arm based emulators that come with the Android-SDK are painfully slow. It can take from anything between 30 seconds to 3 minutes to run an application on the emulator ( depending upon apk size).  This can be quite frustrating for most people to wait for a long time to test their changes. But have no worry, the x86 emulator comes to the rescue. These emulators run directly on the x86 / x64 machine on your pc and are pretty fast. At times even faster than developing on a real device. You have two options here, either use the x86 Intel Atom image that comes with the SDK or use custom images in Virtual Box. Both have their own pros and cons, but I found the custom images in Virtual Box to be faster. The custom images also have play store app (which SDK emulators lack). Among the variety of custom images, I love the one hosted at http://androvm.org/blog/.

Things to do when you are stuck at a technical problem

TLDR;
1. Google it!
2. Read the documentation
3. Search on Stack Overflow
4. Do nothing (consciously)
5. Explain the problem to your friend
6. Step Back, Think Again
7. Write an email / blog about it.
8. Throw money at it

Every now and then I get stuck at a problem which makes me pull my hair. I eventually get it, but after wasting a lot of time trying just one thing and not quickly switching to an alternative. I wish I could remind myself this each time I was stuck.
So here’s list of things to do whenever you are stuck at a problem.

1. Google it!
Chances are that others are plagued with the same problem as you, and someone out there has written a solution to the problem. And assuming you are expert at finding stuff (if you are an engineer, then you probably are!) you will likely find it in the first attempt. If you dont, try changing the search keywords to “What you would title the blog post if you were writing the solution”. Remove dependent specifics (such as file path, line numbers or literals), and put other specifics such as “error code” or “error message” first with the name of the technology (such as android, c++, node js, etc.)
The success of this option depends more on chance than your Googling skills, but its still worth the time it takes (next to none, I know!). And often you will find a solution, only to realize that it doesn’t work in your case. At this time you can think more about how the author solved the problem and try to apply it to your case or email the author asking for help. They usually reply if you ask politely.
Also, if this is a quick question, ask it on SO.

2. Read the documentation
This is the option we try to avoid the most. Who wants to read 10 pages about how to do socket programming in C++, lets just Google an example, download and run it. And then sit and curse the author at the first error.
So here’s the truth. You have to read the documentation. It says exactly how to use a thing. Here’s the stuff author wanted you to know before you begin using his tools/library/code. So sweat it out and read it.
P.S. Don’t give up on this option until you are absolutely sure you have read it and it doesn’t address your problems.

3. Search Stack Overflow
So Google Search returned nothing, and the documentation didn’t help, it probably makes sense to search for similar problems on stack overflow. Use tags to find similar problems on SO. Good answers on SO, don’t just give away the answer, they also explain why the problem occurred and Why the solution works. This could probably give you a hint or increase your understanding of the problem. You can do this on your other favorite QnA sites too.

4. Do nothing (consciously)
Take a break. Have a cup of coffee. Go for a long walk. Take a shower. Meditate / Pray. Whatever suits you and is appropriate at the time of the day. Do something that calms you down and you don’t consciously think about the problem. While you are doing your thing, your sub conscious mind is working at the problem in the background. Chances are you will get new ideas. When you do get them, write them down.
This option helps when you have multiple things to do (like in college). Spend some time on a problem and if stuck, move to something else. Come back to it the later that day (or next day) and you will have a few new ideas to try out.

5. Explain the problem to your friend
The first three methods focused on solving the ‘Lack of information’ problem. But may be, you are stuck at a logic problem and you just need clarity of thought. Or you just need a different perspective. So find your buddy, and explain to him the problem you are facing and what you have done. Chances are either he can provide a fix to your problem or give you new ideas to try out.

6. Step Back, Think Again
Ask yourself why you wanted to do it in the first place ? Can you do away with it? Can you change some of the requirements (technical / non-technical) ? Step back a bit and look at it from a different perspective. May be, its not intended to work this way. May be you are using the wrong tools / language to solve the problem.

7. Write an email / blog about it / ask on Stack Overflow
At this point, you have exhausted most of the sources. You must be ready to apply considerable effort to solve it now.
Document the problem in an email to the author of the code / library, or blog about it or ask on SO. Write down what your understanding of the problem is and what you have done to solve it. Note down any assumptions. If uploading a code sample, make sure to create a Short, Self Contained, Concise (Compilable), Example . Doing this will give you a clarity of thought as well as throw the problem out in the open for people to see and easily try out. Update the post, as and when you try out new things or see different results. Keep an eye out for replies / comments and add more information to it as requested.

8. Throw money at it
At this point, you have spend a few days (at least) trying to solve the problem. If you are still getting no where with it and have the financial resources, put the problem on a job site like freelancer.com or elance.com. There are good chances that some experts in the field would be willing to solve the problem for you for a fee. Or by chance if you don’t get any “bids” you can say for sure that the problem cannot be solved.

Happy Coding!

Setting up cocos2d-x with Eclipse and Visual Studio on Windows

Getting started with cocos2d-x can be tough. There’s too much information on the internet that may or may not work for you.
Unfortunately, there isn’t a perfect tutorial that will help you get started, so you may have to mix and match accordingly.
I have been asked about setting up cocos2d-x many times before and this is the collection of resources that I usually point them to –

A very good tutorial to setup cocos2d-x on windows and eclipse here-

http://www.raywenderlich.com/11283/cocos2d-x-for-ios-and-android-getting-started

http://www.raywenderlich.com/11338/cocos2d-x-for-ios-and-android-space-game

The official cocos2d-x wiki –
http://www.cocos2d-x.org/projects/cocos2d-x/wiki

More Help here –
http://www.jesusbosch.com/2012/06/how-to-set-up-android-and-win32-cocos2d.html
–For CDT part you can also try OpenCV’s help http://docs.opencv.org/doc/tutorials/introduction/android_binary_package/android_dev_intro.html#android-dev-intro

———————
For setting up in Visual Studio
http://www.jesusbosch.com/2012/06/how-to-set-up-android-and-win32-cocos2d.html
http://www.cocos2d-x.org/projects/cocos2d-x/wiki/Cocos2d-x_Application_Wizard_for_Visual_Studio_User_Guide
———————————

Other notes while setting up cocos2d-x on windows with eclipse:

Always run cmd and cygwin with administer privileges.
1] Unzip ndk and add to “path” variables
2] Install Cygwin and select “make” for sure among the utilities that you install
3] Run “create-android-project.bat” in cmd.exe . If it gives error in location of sdk or ndk, then edit the .bat file and change location in there.
4] After creating the project, run the ‘build native.sh’ script using the command
sh build_native.sh
5] If you get permission denied error for any file, then manually select the file and change its permission to Full Control for Everyone. (Alternative run following command in the target folder “chmod 777 -R * “)
6] When you import the project in eclipse then also add the ‘cocos 2d sdk’ library project
7] If you get error while running the project and it points to some file in assets then change permission for that file. or Type this in command line – chmod 777 -R *

Migrating from SVN to Git

Using a live SVN repository

1] Create directory for the git project. Navigate to the directory and do
git svn init -t tags -b branches -T trunk [svn-repo-url]
eg: git svn init -t tags -b branches -T trunk https://subversion.assembla.com/svn/my-repo-name/

and then do a
git svn fetch
This will download all the commits in git. If you get this error

error 0: REPORT request failed on ‘/svn/project-name/!svn/vcc/default’: Path https://Asloob-PC/svn/project-name is not canonicalized; there is a problem with the client.

its because of upper case letters in the url. In this case, my svn was hosted in Visual SVN server locally and the url was https://Asloob-PC/svn/my-project/ I just changed it to https://127.0.0.1:443/svn/my-project/.  Do confirm the port no.

2] Push to git server
Create a repository on GitHub / Bitbucket / Any other git service  and push the changes
git remote add origin https://asloobq@bitbucket.org/asloobq/my-project.git
git push -u origin –all

Using a svn dump file

If you want to migrate a svn dump file to git use the following method. Basically we are going to host it locally on Visual SVN server and then use the above method. Do install Visual SVN server before proceeding.

1] Creating SVN repository from dump the file.
On command prompt go to the path where svn repositories are stored . For me its G:\Applications\Repositories
svnadmin create [project-name]
svnadmin load > [dump-file-path]
Use lower case characters for name of the repository. Launch ‘Visual SVN server’ and check if the repository is shown. Copy the repository url

2] Migrate to git
Use the above method to migrate using the live svn repository.

Git: A Handy Guide for Beginners

When I was new to git I was looking for a place where I could find all the basic git commands in one place.  Now, that I am slightly acquainted with it I decided to create one myself, which I can refer to and others can benefit from it too.

My main sources for learning git were stackoverflow, Git-Ref, and Git-SCM . Although, there are a number of awesome GUI based tools available like EGit and Source Tree I prefer using a combination of the Git Bash and Git Gui tools that come bundled with the default Git software for windows. Although, the other tools make the task very easy and quick, you don’t get enough information if something goes wrong. And most help for Git is available for the command line version and not for the tools.

Enough, of rambling and onwards with the guide.

Initial Setup

1]Initializing a git repository in an existing directory
git init

2] Push up an existing repository
cd /path/to/my/repo
git remote add origin https://asloobq@bitbucket.org/asloobq/test.git
git push -u origin --all # pushed up the repo and its refs for the first time
git push -u origin --tags # pushed up any tags
That’s two hyphens (-) before all and tags, btw.

3] Downloading the code first time (cloning repository).
git clone [url]
eg. git clone https://github.com/asloobq/cocos2d-x-CCLayerPanZoom

4] Setting up user info.
git config --global user.name "John Doe"
git config --global user.email johndoe@gmail.com
That’s two hyphens (-) before global, btw.

Basic Committing, Reverting, etc.

1] Check which files have changed in current working copy
git status

2] Add new files to staging area (staging area has list of files which will be committed ).
git add [file path]

3] Remove files from staging.
git reset HEAD [file path]

4] Commit changes.
git commit -m "commit message"

5] Undo the previous commit but leave changes as it is.
git reset --soft HEAD^

6] Revert a particular file to a particular commit
git checkout [commit SHA id] [filepath]
eg. git checkout 0624b44a447db26862acc635cc69e83f16e610f2 Classes/Main.cpp

7] Revert changes on a file to the current revision
git checkout [filepath]

8] Amend a commit. Suppose you made a commit in which you added the wrong files or you left out the correct ones. Then, you just need to ‘git add’ the correct files and ‘git rm’ the wrong files and say amend.
git rm wrongfile.cpp
git add correctfile.cpp
git commit --amend

Branching

1] Get list of local branches.
git branch

2] Get list of remote branches.
git branch -r

3] Create a local branch to track a remote branch (Basically create a copy of the remote branch so that you can work on it).
git branch -b [local-branch-name] [remote-branch-name]
eg. git branch -b develop origin/develope

4] Switch to a local branch.
git checkout [local-branch-name]
Checkout is a very useful command, you can use it to switch to branch, revert files, create branches, etc.

5] Push branch. When you do a push/pull/fetch, you are trying to sync the git repo on the server with your local repo. A push will transfer your changes on the local branch to the remote branch.
git push origin [local-branch-name]
(Assuming this local branch is already setup to track a remote branch, if not it will create a new branch on the server)

6] Pull changes. This is the git equivalent of ‘SVN Update’. It downloads the latest commit from the server and merges it with your local branch.
git pull origin [local-branch-name]

Pull rebase. This is a better version of pull. It reverts your local repo to the point of last push from your side. Then, it downloads the commits from the server and applies it on your repo. And then, it applies your new commits over the repo. This essentially results in less no of merges and a clean trunk. Be sure to have your working directory clean by stashing it before doing a rebase.
git pull --rebase
In case, you have to resolve a merge, you can do the same and use git rebase --continue to exit.

7] Fetch. This will do the half the job that ‘Pull’ does, ie. get the latest commits for all the branches but it will not merge them into your local copy. Good to see which branches have been updated.
git fetch

8] Reset branch to older revision.
git checkout [commit SHA id]
This will change the code, but will leave you without any branch (you cant commit unless you are on a branch). So this is just to View the state of the repo at that commit.
If you want to branch off from that state (so that you can make commits on it) use
git checkout -b [local-branch-name] [commit SHA id]

9] Reset branch to current revision (clear all changes).
git reset --hard #Revert changes to modified files.
git clean -fd # Remove all untracked files and directories.

10] Copy changes from another branch up to a particular commit.
git merge [commit SHA id]
Scenario: You are on your deploy branch and want to pull in some changes from the master branch, but not merge the two branches together then you can simply use git merge [commit SHA id of the commit in master].

11] Cherry pick one commit from another branch
git cherry-pick [commit SHA id]
If you need to *copy* just one commit from another branch to your current branch, use this command. The commit will be cherry-picked and applied to the Head of your current branch.

12] Merge one branch into another.
git merge [local-branch-name]

13] Resolve merge conflict. I recommend installing TortoiseSvn which comes with the tortoisemerge tool.
git mergetool

Miscellaneous

1] Stash changes, if you don’t want to commit to them and would like to switch branch or pull changes from server.
git stash

2] Pop Stash
git stash pop

…More commands are on the way. If you’d like me to add anything to the list or if I have made a mistake anywhere, do let me know. Happy Coding!

Pro Tip: Read the git messages carefully. More often than not, it gives you commands to undo the action or to do the next logical thing.

Lootera (Movie) – Micro Review

Lootera is like a breath of fresh air amidst the crowd of ‘Chennai Express’ and other south-style movies doing the rounds of multiplexes currently. Set in the 1950s (post-independance) era, it is a love story between a thief (a lootera) and a zamindar’s daughter. The storyline is quite simple but the beauty lies in the detailing and the little moments that make it a pleasure to watch.

The performances by all the actors is very good and feels very natural. Ranveer Singh does a good job, and shows a lot of rage through his eyes. Sonakshi Sinha too gets to display her acting prowess which were rarely seen after the first Dabangg movie. She looks very pretty here and I feel these kind of roles really suite her.  The innocent, old-style romance is very well brought out in the movie. The background music has been done very well and heightens the ‘mood’ of the scene well.

Although the movie is out of the multiplexes by now, I would recommend getting your hands on a DVD as soon as it comes out.

How to export svn repository from visualsvn server to assembla in windows?

1] Go to Visual SVN installed directory. Mine is

C:\Program Files\VisualSVN Server\bin

It should contain executables like svn.exe and svnadmin.exe

2] If the path to your installed directory has a space in it (like mine above in Program Files) then you need to add the path to environment variables. If not skip to step 9

3] Go to Start->Computer (Right Click) -> Properties.

4] Then on left bar select “Advanced System Settings”.

5] In “advanced” Tab select “Environment Variables”.

6] In lower column of System variables locate a variable named Path. Select it and Click Edit.

7] WARNING: do remove any existing text from this path. Simply go to the end, add a semi-colon ; and paste the path of your VisualSVN server

; C:\Program Files\VisualSVN Server\bin

8] Click OK thrice and save the changes.

9] Now fire up VisualSVN Server (GUI).

10] In the left side bar, right click on “Visual SVN Server (Local)” and say properties.

11] Note the path of “Repositories root”.

12]Start command prompt in the “repositories root dir”.

13] Now come the magical words

svnadmin dump repo_name > repo_name.dump

(If you have not added the visualSVN folder path to environment variables, then you may need to call svnadmin along with its path. Like this,

<..path..>\VisualSVN Server\bin\svnadmin dump repo_name > repo_name.dump

)

14] A nice dump file will be created for you in the repositories root folder.

15] Create a space in assembla and import the dump file there.

Congrats!

P.S. In case the dump file is too large (>10MB) or you can’t directly upload the file to Assembla, then you need to upload the file using another service (Eg. Dropbox) and import it in assembla using its download link. One word of caution though, you need to gzip the dump file before uploading. Using windows’s default zip functionality or using WinRar didn’t work for me. I had to gzip it using a Cygwin terminal in windows.

How to import gmail or yahoo contacts to twitter

Stage 1:
Import facebook contacts to yahoomail!

http://www.ehow.com/how_6960454_import-facebook-friends-twitter.html

(rewriting the part about importing facebook contacts to yahoo mentioned in above link)
Import Email Addresses from Facebook to Yahoo! Mail

Step1
Create a yahoo account or log in to one if you already have one.

Step2
Log in to your Facebook account.

Step3
Type in “Address.yahoo.com” in your browser’s address bar and click “Enter.”

Step4
Click the Facebook icon on the next page.

Step5
Click “OK” in the pop-up window that reads, “Do you want to share your contacts with Yahoo?”

Step6
Click “Done” on the page that tells you how many email addresses you have successfully imported.

Stage 2: Importing from yahoo to twitter!

Step 1: Sign in Yahoo. Click on Contacts on the left Tab. Select Tools List Box-> Export.Now click Yahoo! CSV: Export Now

Step 2: Open the file with notepad and save it as a Text File.

Step 3: Open the file in Notepad. Perform Replace of “”, with space. Again perform replace of “” with space. Now you should see records of each contact on a single line with First Name, Last Name and email address.

Step 4: Delete the first line which says “First Name”, “Last Name”, etc.

Step 5: Now browse the text file and cut the records which dont have @email.com after the email id. For example “myyahooid@yahoo.com” will appear as only “myyahooid” in the text file. Cut and paste these records in a different file.

Step 6: Check for Irregularities in the file like blank line, etc. It should be very uniformly distrubuted. This is an important step.

For example each line should be like this

“firstname”,”lastname”,”emailid@gmail.com”,
Step 7: open Microsoft Excel Sheet. Select Date Tab -> get external data FROM TEXT and select the above text file.

Step 8: Press Next on Step 1 of Wizard. In Step 2 check box saying Comma . Say next and finish. Press OK.

Step 9: Delete the first two columns of first name and last name

Step 10: Copy the whole column of email address and paste in a notepad file. Now you should simply have a list of email address. Next we need to separate the ids with a comma.

Step 11: Find Replace “.com” with “.com,” (without the double quotes)

Step 12: Additionally find replace any other domains like “.in” with “.in,”

Step 13: In Twitter goto Find People-> Invite by email. And paste the email addresses(not more than 50 at a time) and say invite.

Now only thing remaining is the list of yahoo ids. I think you can figure them out yourself! 🙂

Have a nice day!