Samsung Moment vs. HTC Hero


Just my two cents on Sprint’s two (so far…) Android phones…

As a longtime Sprint customer, I waited patiently for an Android phone to arrive. The HTC Hero was finally announced and the Samsung Moment shortly after. At first glance, the Hero was a much slicker device — both in hardware and software. Coming from a Blackberry though, I was hoping for a real keyboard.

A friend ( who owns some HTC Windoze phone with a slide out keyboard… ) convinced me that slide out keyboards weren’t worth the extra thickness, so I jumped on the Hero as soon as it was released. And I was not disappointed. The Hero is a very cool device with a nice interface. HTC has done some cool things to pretty up the standard Android interface and give it some of the eye candy we’ve come to expect from modern OSes.

So, the day the Samsung Moment came out, I went and made the switch. According to the sales rep, you can exchange ONCE in the first 30 days. And boy am I glad I did. The Samsung is MUCH faster! It boots faster, loads apps and web pages faster, and it is much more responsive to screen gestures.


The Keyboard — I couldn’t get past the virtual keyboard on the Hero. My gigantic thumbs didn’t quite get along with the little buttons – especially in portrait mode. And the auto correction it rams down your throat was a saving grace in some instances, but a curse in others. If you weren’t paying attention it would auto correct a word to something completely different and you might not notice until your message was long gone.

The Screen — the AMOLED screen on the Moment is as bright and vibrant as advertised. The Samsung definitely wins with 16.7 million colors compared to 65k on the Hero. AMOLED is supposed to consume less power too. Check goes to the Moment.

HTC Hero

HTC Hero

The Interface — HTC’s SenseUI is pretty cool. The social networking integration was pretty nice — it was nice to connect my Google contacts to Facebook and have it use people’s profile pics, update their status in the contact list etc. HTC wins in this category… if you care about that sort of thing. I don’t. Even on my desktop — I run a minimal desktop with all the eye candy stuff turned off. Performance is much more important to me. The Moment sports a plain ol’ vanilla Android interface.

The Camera — HTC wins here too — 5MP compared to 3.2MP on the Moment. But again… not important to me. I’ve rarely used the camera on any phone I’ve owned. Not sure why… I’ve probably missed some good memories. If you take a lot of cell phone pics, check goes to the Hero.

So for me, the Samsung is the better phone — the speed, screen, improved reception and slide out keyboard win out over thickness, weight and a boring interface.


CakePHP Models and requestAction





This may be kind of a “no duh” for some Cake veterans, but it was new to me, so I’ll share…

When it comes to accessing a different Model from a given Controller I had always wondered which was the better practice – include the other Model in the $uses array or using $this->requestAction() to get data from the other Model’s Controller.

For example, let’s say in the classic blog example you are in the PostsController and need to access some data from the AuthorsController. (Probably a bad example because in this case they would probably be joined by an Association, but pretend for a minute that they are not.)

I had always gone with this method – let the AuthorsController handle the Author data:

<?php
class PostsController extends AppController {
     var $name = 'Posts';
 
     function someaction($pid = null) {
 
          $post = $this->Post->findById($pid);
          $authname = $this->requestAction('/authors/getname/' 
                              . $post['Post']['author_id']);
     }
}
?>

And again, that’s a very simple example, you would obviously have an association here…

The alternative would be to add the Authors Model in the PostsController’s $uses array:

class PostsController extends AppController {
     var $name = 'Posts';
     var $uses = array('Post','Author');
 
     function someaction($pid = null) {
 
          $post = $this->Post->findById($pid);
          $author = $this->Author->findById($post['Post']['author_id']);
     }
}

The requestAction() method is probably a cleaner choice for occasional use, but I had a project where an Object could have 20 different associations. What I wanted to do though was let the user choose which “modules” to use. So those 20 different assocations could vary – I didn’t want to hard code them in the Models.

So the user chooses their modules and they are stored in a table. That table is then read and I was executing a loop through each of them and doing a requestAction for each of them to get the data from their respective Controllers. But the page was taking 20+ seconds to load. Looking at Cake’s debug output I noticed that for each of those requestAction’s, Cake was completely rebuilding the session data! (I store sessions in the DB)

The point? If you need to access data from multiple Controllers and can’t/don’t want to set up the appropriate associations for all of them, add them to the $uses array and turn on Model caching.

The Cake documentation clearly states that requestAction can lead to poor performance, but I guess I needed to see it for myself.


Convert UPC-E Barcodes to UPC-A with PHP


Recently I had the need to convert 8 digit UPC-E barcodes to 12 digit UPC-A barcodes for an inventory app I was working on.

After lots of Googling, I found this one written in Visual Basic: http://upcdata.info/?action=e2a

And did my best to convert it to PHP. The results are below. Let me know if it does/doesn’t work for you.

      function fixedUPC($upc) {
 
           $valid_digits = substr($upc,1,6);
 
           $last_digit = substr($valid_digits,-1);
 
           switch($last_digit) {
               case "0":
               case "1":
               case "2":
                   $upc_a = substr($valid_digits,0,2) . $last_digit
                       . "0000" . substr($valid_digits,2,3);
                   break;
               case "3":
                   $upc_a = substr($valid_digits,0,3) 
                           . "00000" . substr($valid_digits,3,2);
                   break;
               case "4":
                   $upc_a = substr($valid_digits,0,4) 
                           . "00000" . substr($valid_digits,5,1);
                   break;
               default:
                   $upc_a = substr($valid_digits,0,5) 
                           . "0000" . substr($valid_digits,5,1);
           }
           return substr($upc,0,1) . $upc_a . substr($upc,-1);
       }


Dynamic Database Connection with CakePHP





Recently I was working on a project where I had a central Cake application for a group of clients and each client had their own database.

I wanted to have all users sign into a central user’s table associated with the application, but then for the bulk of the controllers in the app have the database config change based on a field in the user record.

So if Bob Smith from Company A signs in to our app, he needs to use database configuration ‘company_a’.

Since we are using Cake’s built in Auth component, we always have access to the user record in the Session from the controller. But for the life of me, I could not figure out how to get at the Session data from the Model!

I saw several comments in my search that said to just abandon the Cake MVC model and get what I needed from $_SESSION. I had no qualms about doing that, but $_SESSION had no data. I believe this is because Cake overrides PHP’s default session handlers so session data stored by Cake is not going to end up in $_SESSION. Feel free to comment if I am wrong about that.

So I had the data I needed in the controller, but at that point the model has already been instantiated.

But it became a timing issue — ‘mydatabase’ had to be a valid database connection before the controller is even instantiated.

So to fix, a ‘dummy’ database was needed to make the initial connection, then we can make our adjustments in the controller.

function beforeFilter() {
     $config = array(
          'login'    =&gt; 'myusername',
          'password' =&gt; 'mypassword',
          'database' =&gt; $this-&gt;Auth-&gt;user('company_name')
     );
 
     $db =&amp; ConnectionManager::getDataSource("mydatabase");
     $db-&gt;disconnect();
     $db-&gt;setConfig($config);
     $db-&gt;connect();
}

Drag and Drop with jQuery and CakePHP

Recently I had a need for a data report with shopping cart-like behavior — let the user paginate through a list of items, drag items of interest to a “basket” and then take action on all items in the basket.

To do this, I used the “draggable” and “droppable” functionality in jQuery UI. jQuery makes drag and drop (and everything else) ridiculously easy.

The only trick here was managing the “basket” contents with CakePHP.

My data was laid out in a table, so I took the item name and wrapped it in a div with a ‘draggable’ class like this:

<div class="draggable"><?php echo $item['Item']['name']; ?></div>

Then at the top of the page, I created my “basket” — just a stylized div with a “droppable” class or id, like so:

<div id="basket" class="droppable">Drag items of interest here.</div>

Then in the document ready function, just initialize the drag and drop:

$('.draggable').draggable({ revert: 'valid'; });
$('#droppable').droppable({
     accept: '.draggable',
     hoverClass: 'draggable-active',
     drop: function(event, ui) { doSomeFunction(ui.draggable); }
});

Demo coming soon…


Disable Pidgin Notifications in Ubuntu 9.04

I love the new libnotify notifications in Ubuntu Jaunty Jackalope, but don’t really want my IM messages popping up on the top right of the screen — especially at work.

So how do you get Pidgin to just quietly blink in your system tray like it used to?

Pidgin uses libnotify as a plugin to make those notification happens, and you can turn it off like any other. Go to Tools->Plugins and find “Libnotify Popups” and uncheck it.

Then to get your old notifications back check the “Message Notification” plugin. Then go to Tools->Preferences and set “Show system tray icon” to Always on the Interface tab. Then you can right-click on your Pidgin icon in the system tray and check “Blink on New Message” so you at least know when someone is trying to chat with (distract) you.


Ubuntu — Upgrade Pidgin to fix Yahoo!

I’m not a huge fan of Yahoo! IM, but I do have clients and co-workers that use it so I really need it to work in Pidgin. A recent protocol upgrade at Yahoo! broke Pidgin 2.5.5. I found several ‘fixes’ out there that included changing the named pager server to an IP address. But none of those worked for me.

In typical fashion I checked the official sources last but the Pidgin website has an updated version that has fixed the Yahoo! problem — http://www.pidgin.im/download/ubuntu/

In brief, we just need to get the latest version (2.5.7) from Pidgin rather than from Ubuntu sources.

Simply run these two commands in a terminal:

sudo apt-key adv --recv-keys --keyserver keyserver.ubuntu.com \
    67265eb522bdd6b1c69e66ed7fb8bee0a1f196a8
echo deb http://ppa.launchpad.net/pidgin-developers/ppa/ubuntu \
    `lsb_release --short --codename` main | \
    sudo tee /etc/apt/sources.list.d/pidgin-ppa.list

And then update apt and upgrade pidgin:

sudo apt-get update

sudo apt-get install pidgin