Friday, August 31, 2012

A Quick Recipe :)

Exercise to have a strong body. Eat good food to have good health. Sleep well to have a bright mind. Do great work and you will have a great career. You will be paid well so you can pay for a gym/sport/activity, good food, good shelter - things you will need to be excellent at your work, to fulfill your purpose. Save and prepare so you can provide for your family. Live a meaningful life. Pass on your values to the next generation.

Sunday, August 26, 2012

Different ways of sending HTTP API requests (PHP/Curl/Wget)

I was recently debugging an API request in our application and I had to try using different tools to send an HTTP request to see what's the cause of the problem. It's funny how some API's look very complicated at first (hmmm SOAP anyone?) but in essence it is just an HTTP request with a specific format. Let's look how I connect to the Plesk RPC API using curl on PHP, and also curl and wget on the shell/command line:

What this does is:
- Post XML content to a specific URL
- Set headers (for login values, content type, etc)
- Disable SSL certification check (useful for development)

Curl on PHP:
$curl = curl_init();
curl_setopt($curl, CURLOPT_URL, 'https://domain.com:8443/enterprise/control/agent.php');
curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);
curl_setopt($curl, CURLOPT_POST,           true);
curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($curl, CURLOPT_SSL_VERIFYHOST, false);
curl_setopt($curl, CURLOPT_HTTPHEADER, array(
"HTTP_AUTH_LOGIN: my_username",
"HTTP_AUTH_PASSWD: my_password",
"HTTP_PRETTY_PRINT: TRUE",
"Content-Type: text/xml"));
curl_setopt($curl, CURLOPT_POSTFIELDS, "<xmldata>");
$result = curl_exec($curl);

Curl on shell:
curl --insecure -H 'HTTP_AUTH_LOGIN:my_username' -H 'HTTP_AUTH_PASSWD:my_password' -H 'HTTP_PRETTY_PRINT: TRUE' -H 'Content-Type: text/xml' --data '<xmldata>' https://domain.com:8443/enterprise/control/agent.php

Wget on shell:
wget --no-check-certificate --header 'HTTP_AUTH_LOGIN:my_username' --header 'HTTP_AUTH_PASSWD:my_password' --header 'HTTP_PRETTY_PRINT: TRUE' --header 'Content-Type: text/xml' --post-data '<xmldata>' https://domain.com:8443/enterprise/control/agent.php

You can even use PHP's fopen but I wasn't able to try that.

Friday, August 3, 2012

Android Jelly Bean (4.1) Tethering on Globe Prepaid

*Update: turns out you don't have to use FoxFi. Stock wireless hotspot will work, you just have to set the Globe DNS IP on your laptop.

One drawback of being early on Android OS updates is dealing with incompatible apps. The previous app that I used for tethering (intenet sharing using your phone's 3G connection), "WiFi Tether for Root Users" was not compatible with the new Android OS. So after some days of looking for solutions and trying out different apps, I found something that works! It's actually quite simple. I found out from some blogs that the main issue is that Globe (prepaid only) blocks the Google DNS (8.8.8.8) which Android uses whenever it's tethering. For some reason, this solution only works on FoxFi using bluetooth (at least on my Nexus S). The solution is to set your computer to use Globe's DNS while using the tethered bluetooth connection.

Step by step guide:
- Enable mobile data on your phone
- Download FoxFi on your phone and enable bluetooth tethering
- Pair your Android device with your computer. When pairing is successful, you should see a "Connect" button on the device's bluetooth settings on your PC. But don't click Connect yet.
- Get Globe's DNS IP. Download SetDNS on phone to see what's your current DNS. For Globe Prepaid, there are 2 DNS IP's. Take note of the DNS IP's, usually it's the 2nd one that works on the PC (202.x.x.x), or you can try each and see what works.
- On your PC, go to "View network connections" (just type it on start menu), right click on "BluetoothConnection", click Properties. Click the "Networking" tab, double click "Internet Protocol Version 4 (TCP/IPv4)". Then type the Globe DNS on "Preferred DNS Server". Click OK.
- You're all set! Now go back to the device bluetooth settings (on your PC), and click "Connect"

Special thanks to these blogs:
http://monotrematica.blogspot.com/2011/05/aaahh-tethering-finally-working-on.html
http://racoma.com.ph/archives/how-to-use-wireless-tethering-with-globe-prepaid

Wednesday, August 1, 2012

What's The Edge of a Senior Developer?

I've been working as a Web Developer for more than 5 years by now, I consider myself a senior developer. Back when I was just starting professionally, I've prided myself as being a go-getter, energetic, and very passionate about what I do. I'm always excited to try everything cool and new in programming. I remember when I look at some of my older workmates, I see that they seem to be just "doing their job" and have lost their passion.

I remember one uncle telling me that being a consultant does have its limits to where it can get you - at some point you have to move somewhere else, like management, in order to continue growing. That's if you want to climb the corporate route; not my cup of tea if you ask me, and, if given a choice, I would choose a smaller competitive company where I could focus more on actual work than process. I often look in introspect and ask myself that as I gain experience, how do I differentiate myself from younger, "edgier" developers? I was one at some point and I felt that I can do any challenge given to me.

So what's my edge if you ask me? Experience is an obvious one. What I pride myself is I can learn and understand anything. I don't see myself just as a "PHP Developer" or "Web Developer", I see myself as an experienced software engineer. I specialize in some fields but really, throw me anything that needs to be done and I will learn to get it done.

See the bigger picture. Some developers give up or get discouraged when they fail to learn or see something as too complicated; some get discouraged when they see grunt work or spaghetti code to work on. Well in the real world, programming isn't always cool and exciting; you have to understand that there really is grunt work and you can't always re-invent the wheel. Off course there are always better ways to do things, but it is not always the right thing to do. Optimize for the right situation. Most times, it is better to keep the old working code because you don't have time and resources to re-write and re-test everything. Just understand how the system is built and you'll see there's always a reason why it's built that way (it's not all stupidity!).

You get it done, and you see the whole system working, it's not a perfectly built system, it's not using the newest coolest stuff, but it's working and it's ready to ship, and that's what matters to the end user/ client/ customer. Isn't it beautiful that you took part in it?