Sunday, May 26, 2013

Read this: an insight on how Steve Jobs does negotiations

Here's an insight on how Steve Jobs does negotiations
http://qz.com/87184/the-steve-jobs-emails-that-show-how-to-win-a-hard-nosed-negotiation/

Thursday, May 23, 2013

Productivity tip: know what you're gonna do tomorrow

Always keep a note of the first thing that you will do on the next day. It makes it easy to get started quick and a huge productivity booster.

Finishing a task today is always good, but knowing what specific thing to do tomorrow is also a very important thing. Programming is a lot about thinking and making decisions. Take advantage of the time you're eating breakfast, taking a shower, or driving. These are moments that your mind is very open and most times those are the times that you can think of "outside of the box" solutions.

Monday, April 15, 2013

FedEx Rate Service API using plain old PHP and cURL (the quick and easy way)

Here's a quick way to try out the FedEx Rate Service API (SOAP version) without getting lost in WSDLs and all that zipped PDF documentation jazz. Certainly you will need to look at that PDF when you get into details, but where the fun in that right? Let's get dirty with code quick!

One nice thing about SOAP is beneath all that layers complicated stuff, it's all just plain XML being posted into a URL. "Nice" and "SOAP" doesn't usually come in one sentence, but SOAP is here and most of the time there's really no choice when you're working with an external API, so I'm just being positive here :) So as long as you know what you're doing with the XML then you'll do just fine.

Here's the sample code:


<?
//your account details here
$key = '';
$password = '';
$account_number = '';
$meter_number = '';

$xml = '<?xml version="1.0" encoding="UTF-8"?>
<SOAP-ENV:Envelope xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/" xmlns:ns1="http://fedex.com/ws/rate/v13"><SOAP-ENV:Body><ns1:RateRequest>
<ns1:WebAuthenticationDetail>
<ns1:UserCredential>
<ns1:Key>'.$key.'</ns1:Key>
<ns1:Password>'.$password.'</ns1:Password>
</ns1:UserCredential></ns1:WebAuthenticationDetail>
<ns1:ClientDetail>
<ns1:AccountNumber>'.$account_number.'</ns1:AccountNumber>
<ns1:MeterNumber>'.$meter_number.'</ns1:MeterNumber>
</ns1:ClientDetail>
<ns1:TransactionDetail><ns1:CustomerTransactionId> *** Rate Request v13 using PHP ***</ns1:CustomerTransactionId></ns1:TransactionDetail><ns1:Version><ns1:ServiceId>crs</ns1:ServiceId><ns1:Major>13</ns1:Major><ns1:Intermediate>0</ns1:Intermediate><ns1:Minor>0</ns1:Minor></ns1:Version><ns1:ReturnTransitAndCommit>true</ns1:ReturnTransitAndCommit><ns1:RequestedShipment>
<ns1:DropoffType>REGULAR_PICKUP</ns1:DropoffType>
<ns1:ServiceType>FEDEX_EXPRESS_SAVER</ns1:ServiceType>
<ns1:PackagingType>YOUR_PACKAGING</ns1:PackagingType>
<ns1:TotalInsuredValue><ns1:Currency>USD</ns1:Currency></ns1:TotalInsuredValue>
<ns1:Shipper><ns1:Contact><ns1:PersonName>Sender Name</ns1:PersonName><ns1:CompanyName>Sender Company Name</ns1:CompanyName><ns1:PhoneNumber></ns1:PhoneNumber></ns1:Contact><ns1:Address><ns1:StreetLines></ns1:StreetLines><ns1:City></ns1:City><ns1:StateOrProvinceCode></ns1:StateOrProvinceCode>
<ns1:PostalCode>94040</ns1:PostalCode><ns1:CountryCode>US</ns1:CountryCode></ns1:Address></ns1:Shipper>
<ns1:Recipient><ns1:Contact><ns1:PersonName>Recipient Name</ns1:PersonName><ns1:CompanyName>Company Name</ns1:CompanyName><ns1:PhoneNumber></ns1:PhoneNumber></ns1:Contact><ns1:Address><ns1:StreetLines></ns1:StreetLines><ns1:City></ns1:City><ns1:StateOrProvinceCode></ns1:StateOrProvinceCode>
<ns1:PostalCode>98052</ns1:PostalCode>
<ns1:CountryCode>US</ns1:CountryCode><ns1:Residential>false</ns1:Residential></ns1:Address></ns1:Recipient><ns1:ShippingChargesPayment><ns1:PaymentType>SENDER</ns1:PaymentType><ns1:Payor>
<ns1:ResponsibleParty>
<ns1:AccountNumber>'.$account_number.'</ns1:AccountNumber>
</ns1:ResponsibleParty>
</ns1:Payor></ns1:ShippingChargesPayment>
<ns1:RateRequestTypes>ACCOUNT</ns1:RateRequestTypes><ns1:PackageCount>1</ns1:PackageCount><ns1:RequestedPackageLineItems><ns1:SequenceNumber>1</ns1:SequenceNumber>
<ns1:GroupPackageCount>1</ns1:GroupPackageCount>
<ns1:Weight><ns1:Units>LB</ns1:Units><ns1:Value>20</ns1:Value></ns1:Weight>
<ns1:Dimensions>
<ns1:Length>10</ns1:Length>
<ns1:Width>10</ns1:Width>
<ns1:Height>10</ns1:Height>
<ns1:Units>IN</ns1:Units>
</ns1:Dimensions>
</ns1:RequestedPackageLineItems>
</ns1:RequestedShipment></ns1:RateRequest></SOAP-ENV:Body></SOAP-ENV:Envelope>';

$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, 'https://wsbeta.fedex.com:443/web-services');
curl_setopt($ch, CURLOPT_POSTFIELDS, $xml);
curl_setopt($ch, CURLOPT_VERBOSE, 1);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0);
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 0);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_POST, 1);
$result_xml = curl_exec($ch);

// remove colons and dashes to simplify the xml
$result_xml = str_replace(array(':','-'), '', $result_xml);
$result = @simplexml_load_string($result_xml);

print '<pre>';
print 'Rate: $';
print (string) $result->SOAPENVBody->RateReply->RateReplyDetails->RatedShipmentDetails[0]->ShipmentRateDetail->TotalNetCharge->Amount;
print '<hr/>';
print_r($result);

Saturday, January 26, 2013

Cherry Mobile Titan review: impressive phone + affordable price

Samsung Galaxy Note 2 (left), Cherry Mobile Titan (right)
I've been using my Cherry Mobile Titan for a couple of weeks now and I can say that I am really impressed. This phone replaced my Samsung Nexus S which is already showing its age in terms of speed and battery life.

These are the reasons why I bought the Titan:

  • Affordable price (PhP 6,500, or USD 160)
  • Dual core 1ghz processor
  • Excellent battery life (2350mah) - lasts more than a day on normal to heavy use
  • ..and partly because the Cherry Mobile kiosks are everywhere!

My first choice was actually the CloudFone 430x (PhP 7,777) because it has a nice screen and gigantic battery, but it was out of stock everywhere. Judging from the CloudFone's unavailability, I felt that I might have a hard time with the warranty if I get a faulty unit. The MyPhone A919 seems comparable but its bezels look too big, has a smaller battery (2000mah), and it is more expensive (PhP 7,999).

The Titan was actually an impulse buy. It's a lot cheaper than the other ones I'm considering so when I went to the Cherry kiosk (at the nearby Riverbanks mall) and realized they have stocks, I couldn't resist the urge for a new gadget. I was thinking if it would at least last the whole day for me without recharging, the battery life would be worth the money.

Form Factor
I was actually hesitant at first because I thought a 5-inch phone would be too big for my pocket. My 4-inch Nexus S fits my pocket very well and it's very lightweight. The Titan does feel big and quite hefty on the pocket, but it still fits and I got used to it. I appreciate the bigger display and compared to a 4-inch screen, it feels more comfortable to browse and read on a 5-inch screen. I prefer its simple no-nonsense look compared to other big Chinese phones that look like S3 knockoffs. Overall, it looks like the Galaxy Note 1, but a bit heavier.

Display
The display is a 5-inch LCD screen (not IPS), with 480x800 resolution. This is not the best screen and resolution. The viewing angles are not very good, for example when you place the phone flat on a table, there are angles where the screen looks very washed out. The screen resolution (PPI) is not as bad as you might think. Since it's a big screen, I don't mind if it's not as sharp as the Nexus S. I don't mind because I'm more comfortable reading on my Kindle anyway. For general use and occasional reading, the screen works well.

Battery
This is where the Titan shines. Based on my daily usage, I usually end the day with 50% battery remaining. I still charge it overnight because I don't think it will last 2 full days. This is excellent since when I was using the Nexus S (1500mah), I had to recharge before the day ends and that was a bummer for me. I have data ON all the time (2G/Edge most of the time, 3G only when I need it), Wifi always ON, and the usual phone/text/browsing/reading. So far I've never seen the phone go low batt as long as I charge it every night.

Performance
Coming from a single core 1ghz Nexus S, everything feels faster on a the dual core Titan. Apps like Chrome browser and Facebook work well with little to no lags. When you do heavy multi tasking, you will see some lags maybe due to the standard 512mb RAM, but it's not a deal breaker.

Software
I'm glad that Cherry (or its Chinese OEM) didn't mess too much with the stock Android 4.0 (ICS). Coming from a Nexus device, this feels as stock as you can get. Unlike Samsung which puts a skin on top of Android, this doesn't change the stock Android look. They just added some settings for SIM management, display controls, and a nice reboot scheduler which I find useful. So far I haven't had any issues with the software which is quite surprising (in a good way) for a budget Chinese smartphone.

Conclusion
Affordable price, excellent battery life, almost stock Android OS, dual core processor, big 5 inch screen, dual sim. What more can you squeeze for PhP 6,500? This phone is bang for the buck :)

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 http://bit.ly/hnkindle :)

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.