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.

Posted in Android | Leave a comment

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.

Posted in CakePHP, PHP | 1 Comment

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);
       }
Posted in PHP | Leave a comment

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();
}
Posted in CakePHP | Tagged | 1 Comment

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); }
});

Posted in CakePHP | Tagged , | Leave a comment