Profile cover photo
Profile photo
Azeem Khan
102 followers -
Researcher & Entrepreneur.
Researcher & Entrepreneur.

102 followers
About
Azeem's interests
View all
Azeem's posts

Where art thou IPv4?
------------------------------

I have been developing some web application using PHP with Netbeans as my IDE for the last few months. Normally the logic is clean enough that if I need to debug some code, echo and var_dump() is enough. Once in while print_r() is necessary but usually json_encode() does the job. Recently however I reached their limitations.

I wanted to integrate some code from a project on github. The code looked okay at first glance and it was peppered with copious comments in docblocks but no tests accompanied it. Nor were there any comments from others on how well it worked. So I decided to take a deeper look. Since my PHP skills are not that great yet, I ran into some difficulty with some parts of the code. Moreover, when I tried to use it, I found some un-anticipated behaviour. Out came my trusty var_dump(); die() duo. Unfortunately, that quickly became tedious also because the code had many moving parts and jumped constantly.

So I decided to use xdebug. And that's where things became frustrating.

My setup is as follows. My development machine is Ubuntu 16.04 LTS x64. I run my web application on an Ubuntu 14.04 (virtualbox) virtual machine using Vagrant. The VM is on a NATted interface that can access the Internet but except for my host (i.e. development) machine, no other machine on the LAN can access it. Since that caused some problems with testing of an Android app with the web application, I decided to bind a port on the host (i.e. development) machine with port 80 on the guest (i.e. virtual) machine. Finally, I map my web application directory on the host machine directly onto the web server path on the guest machine. I do all this using Vagrant so the relevant lines of code in Vagrantfile look something like this:

config.vm.network "private_network", ip: "192.168.56.101"
config.vm.network "forwarded_port", guest: 80, host: 8000
config.vm.synced_folder "./", "/var/www", :mount_options => ["dmode=777"]

(There is no 666 mode for the files during the mount because I also execute codeception on the guest machine for my unit tests)

After looking at myriad documentation thanks to Google searches, I finally decided on the following for xdebug.ini on the guest machine

zend_extension=xdebug.so
xdebug.default_enable=1
xdebug.remote_enable=1
xdebug.remote_handler=dbgp
xdebug.remote_host=10.0.2.2 ; /sbin/route tells me that this is the default gateway
;xdebug.remote_connect_back=1 ; Use remote_host or remote_connect_back. With a local VM remote_connect_back should work also.
xdebug.remote_port=9000
xdebug.remote_autostart=0
xdebug.remote_mode=req
xdebug.remote_log=/tmp/xdebug.log

I also "touch"ed the /tmp/xdebug.log and transferred the ownership to www-data (i.e. apache).

I would like to point out that the documentation for setting up netbeans for xdebug is either incomplete in most places or out of date. This is not good. After testing that phpconfig() reported xdebug as working and installed, I configured Netbeans exactly as mentioned in http://www.papayasoft.com/2013/02/25/debugging-vagrant-virtualbox-vm-netbeans/

The /tmp/xdebug.log file on the guest told me there was a client connected but Netbeans just kept waiting for a connection. After 45 minutes of not being able to get it to work, I did a sanity test.

netstat -an | grep 9000

I was taken aback when I saw that this port was open on tcp6. I had no idea Netbeans would default to IPv6 for opening the debug channel. A quick Google search told me that all I needed to do was append the -J-Djava.net.preferIPv4Stack=true to netbeans_default_options in the etc/netbeans.conf and restart NetBeans IDE. And it worked.

Lesson learned: When documentation is fragmented on how to configure something, do sanity check at every step.

Post has shared content
Watch this! Seriously... Watch It!

Post has shared content
Nice to know the place where one of my favourite poems was written.

Robert Frost was inspired to write, The Road Not Taken, while here in this tiny New England cottage. Nestled on the shore of Westmore Vermont's Lake Willoughby. “I see it’s a fair, pretty sheet of water,
Our Willoughby!”

The Road Not Taken
BY ROBERT FROST 

Two roads diverged in a yellow wood,
And sorry I could not travel both
And be one traveler, long I stood
And looked down one as far as I could
To where it bent in the undergrowth;

Then took the other, as just as fair,
And having perhaps the better claim,
Because it was grassy and wanted wear;
Though as for that the passing there
Had worn them really about the same,

And both that morning equally lay
In leaves no step had trodden black.
Oh, I kept the first for another day!
Yet knowing how way leads on to way,
I doubted if I should ever come back.

I shall be telling this with a sigh
Somewhere ages and ages hence:
Two roads diverged in a wood, and I—
I took the one less traveled by,
And that has made all the difference.
Photo

Post has attachment
The experiment continues.

Post has attachment
Once I got a bit of a break, I thought it would be fun to try something new on my desktop.

Post has shared content
Today’s #AndroidDev #Protip  is from +Katherine Kuan on screen pinning.

In Android 5.0 Lollipop, we’ve introduced the screen pinning feature, which temporarily restricts users from leaving a task or getting interrupted by notifications. Here are two ways to take advantage of it.

1. As a user, you may pin a screen before you hand off your device.
Pinning a screen keeps the device locked to the current task. It minimizes the chance of accidentally hitting a system nav button to inadvertently leave the app. However, this feature is not meant to enforce secure lockdown of the device because using the system UI, a user can still exit screen pinning mode. Any Lollipop user can enable the screen pinning feature by going to Settings app > Security > Screen pinning. Next open the desired app, and then open the Overview space (recents). Pin the screen by touching the circular pin icon. See images below. 

2. As a developer, you may prompt the user to pin a screen from inside your app.
You can extend your app (if it’s an immersive game for example) with the screen pinning API. You can surface a way for users to start and stop screen pinning mode in your app, without requiring them to go to the Overview space. Within the Activity code, call startLockTask()[1]. A dialog prompt appears to the user before the mode starts. It’s possible to detect that the mode has been started when isInLockTaskMode() [2] is true. Afterwards, the user can exit this mode via the system UI or by clicking on app UI that calls stopLockTask() [3]. A secure screen lock may be presented upon unpinning, depending on the selected behavior in the dialog prompt (and the device’s current security settings). 

Note that screen pinning is a lock on the task, and not a lock on the app or the activity. In this mode, you can’t create or switch to a new task (even in the same app). Follow best practices on using tasks in your app. [4]

Check out the developer site for more details on the behavior of the screen pinning mode. [5]

[1] http://developer.android.com/reference/android/app/Activity.html#startLockTask()
[2] https://developer.android.com/reference/android/app/ActivityManager.html#isInLockTaskMode()
[3] http://developer.android.com/reference/android/app/Activity.html#stopLockTask()
[4] http://developer.android.com/guide/components/tasks-and-back-stack.html
[5] http://goo.gl/a2F8qM
Photo
Photo
2014-12-17
2 Photos - View album

Post has shared content
The Assembly Elections Results for Maharashtra just came out yesterday. A big question: Could NCP and Congress contesting as allies together would have come back to power? Perhaps not. They would have won only 37 more seats (assuming the same voters voted for the two). Not at all enough to handily defeat the BJP. This and other fun examinations of the results will be coming soon. Keep watching this space.

Post has shared content
The Assembly Elections Results for Maharashtra just came out yesterday. A big question: Could NCP and Congress contesting as allies together would have come back to power? Perhaps not. They would have won only 37 more seats (assuming the same voters voted for the two). Not at all enough to handily defeat the BJP. This and other fun examinations of the results will be coming soon. Keep watching this space.

Post has attachment
It is always interesting to look at what makes some problems particularly difficult to solve. Usually, a number of solutions that only partially address the issue come up. Sometimes a very offbeat but intriguing proposal is put forward. Only sometimes they succeed.

Post has attachment
Most people can probably remember a web page that looks pretty bad when it is printed. Thankfully, such web pages are becoming fewer thanks to smarter web browsers and correctly written CSS (cascading style sheets). I recently used CSS at  +azeemtechnologies to create web pages which were expressly designed only for printing. Here is what happened.
Wait while more posts are being loaded