Thursday, November 1, 2012

My Home Office Chair

Yes this is where I sit all day when I'm working/coding (at home). It's actually 2 monobloc (plastic) chairs, it's stacked so I get my desired chair height. Does it hurt to sit on it all day? Yes.

Nope this post is not about me being thrifty and not buying a good chair :P Desk chairs used to be my pet peeve when I was still working on an actual office (ie. not remote). I've worked with different companies that provided worst chairs (they shall not be named) and better ones (like Disney when I did onshore work at Florida). What I realized is that you can never get the best chair. You sit on a different chair and then it feels better, and after a while it feels just like the other one.

Sitting all day is not healthy no matter how good your posture is or how comfortable your chair is. What I like about my cheap chair is that it doesn't take too much time to realize that I need to stand up, take some walk and stretch a bit.

It also reminds me to always be thankful that I'm doing the work that I love the most, and being paid for it. When I think about that and other comforts that I am enjoying, a chair is such a little thing.

Surely I can't sit on this chair all day, but that's actually a good thing.

Multiple login types on CakePHP 2

The Authentication component has been rewritten on CakePHP 2. I think it's not as simple as the previous version but I guess it's better going forward since there are multiple ways of authentications nowadays especially when creating API's.

If you need to create multiple login types on the same website, it is actually simple. You may need this in case you have 2 separate tables for 2 different types of users accessing your website. One way to do this is to use a different session key for each login type:

if ($loginTypeOne) {
  $this->Auth->authenticate = array(
    'Form'=> array(
      'userModel'=> 'TypeOne',
  AuthComponent::$sessionKey = 'Auth.TypeOne';
} else {
  $this->Auth->authenticate = array(
    'Form'=> array(
      'userModel'=> 'TypeTwo',
  AuthComponent::$sessionKey = 'Auth.TypeTwo';  

I also posted this on this thread on StackOverflow.

Thoughts on Read Later services (Pocket/Instapaper) and Send to Kindle

Just wanted to share some comments I posted on Hacker News about read later services and the Kindle (i'm xtimesninety on HN):

I'd love an e-ink android tablet too. Reading on an LCD tablet is painful especially if you are already staring at a computer all day. I almost decided to buy the Nook Glow because I've seen it installed with android 2.1 but it seems most apps are incompatible, so I went with Kindle Paperwhite which does web articles pretty fine with it's Send to Kindle feature.

Btw there's a chrome extension of Send to Kindle so you don't have to email articles. Also if you like reading Hacker News on the kindle browser check out :)

I actually stopped using Pocket (phone/tablet) and just use Send to Kindle for everything. It doesn't bother me too much that I can't archive/mark as read articles, I just delete them from my kindle once I'm done. Also I just order the articles by most recent and just use search if I need to find a specific article. I wanted to avoid relying on hacks so I guess this setup will be stable for a while.

It's actually amusing that since back then I've used ipod touch, android phone, android tablet, and now the kindle, for specifically reading articles from the web. When I was in college I was actually printing web articles in batch during weekends, I just paste the plain text to MS word arranged in 3 columns in uniform font so it looks like a newspaper. Those were fun times since everything was so new to me :) that's way before all the instapaper/pocket came out.

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, '');
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",
"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>'

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>'

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 ( 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:

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?