Following the Yellow Brick Road

Location services, another word for allowed electronic stalking. Yet it is something that is getting more traction. Sure it may not seem like a big deal to some, to others it is the lifeblood, and still to others, it is an answer to a question no one asked. So what is so amazing about social media/location services and why should anyone follow this yellow brick road?

Well, first off, lets answer that with some common sense. First off, I do not really care to know if you checked in at your bathroom. I also really do not care if some vending machine is giving you your favorite drink. I think the movie “Easy A” sums it up best:

Mr. Griffith: [to Olive] I don’t know what your generation’s fascination is with documenting your every thought…but I can assure you, they’re not all diamonds. “Roman is having an OK day, and bought a Coke Zero at the gas station. Raise the roof.” Who gives a rat’s ass?

Exactly! Some social media use goes way overboard and way too much information. It is like everyone in a room talking extraordinarily loud saying nonsense and spouting the first thing to come into their mind. Yes it can be funny at times, but it soon becomes annoying. People turn this off, and soon ignore all other information coming from these sources, even if it is important and pertinent. Make it worth the time to read/listen.

Restaurants are already seeing the value of this. Checking in at the place can give you a discount, free appetizer, etc. Movie theatres would be wise to step up with this as well, maybe even distribution companies too. Imagine this: Checking in at a theatre with a mention of which move you are seeing = free popcorn. Heck, my wife would tweet that without hesitation. And what does it really cost the theatre for the popcorn? (Besides, I am convinced that they make all their money on soda anyway, you pay $8 for a large cup that contains mostly ice and maybe a teaspoon of actual soda). Not only would the theatre be getting basically free advertising, so is the movie!

Not sure how to start this up? Try Mashable: HOW TO: Set Up a Foursquare Special. Great information in that article. Make it worthwhile, and make it relevant. Remember Mr. Griffith’s very astute observation.

Who Do You Like

By now, everyone and their dog has heard about Microsoft’s coup to acquire Skype for $8.5B. Based on what you read, Microsoft is going to have either the best X-Box Live experience, or create an Office web suite that will one up the online meeting space. Or the other news making the rounds, Google’s web based music service. Come on, be honest, which one did you really know about? And that is the whole thing. Two amazing things happened this week, and only one got tons of press, coverage and was talked about more. So who do you like?

And that is what it comes down to for you, or your business – who do you like? Are you following and friending people just so you can beat Ashton Kutchner’s records, or are you trying to build relationships? Social connections should be less of a race to get the most people and more of building a cohesive community. This community should be focused on your business goals mixed with ways for the community to be involved in the project or become part of the direction. Social connections are also more mobile, so that should also be a main focus. Gone are the days of the young geeks huddled in the basement, logging on chat boards while playing Dungeons and Dragons. It is no longer the “geeks” who are connected, it is everyone. They are connecting via the phones, pads, and laptops. Just today, as I pulled in fill up my tank with outrageously expensive gas, the station had 10 cars at the other islands. Seven of those people were out filling up the tanks, texting, chatting, checking emails, etc. They all had their phones out and using them, not to make calls, but connecting to their community.

This is the new direction of the connected world. It is not in front of a computer screen, but out and active. Now that Microsoft has purchased Skype, and Google is starting a web based music service, there will be less and less reasons to focus traditional read/write web applications. Interactions will build relationships, and in turn, build who likes you and bring lasting business relationships.

Count the Number of Cakes – Finding complex results with CakePHP

CakePHP offers a good selection of tools to help you retrieve the data. Recently, I came into a situation where I needed to find and paginate results based on a single, distinct column in the table. Distinct data can be tricky, especially if the tools do not allow you to select the distinct based on a column. Distinct will check all columns returned, and coupling in time stamps, 99% of the time all rows will be distinct. So how do you grab the data? Well, first lets examine the sample data that is needed to be extracted first.

The sample data is in a MS SQL Server database. The table contains a record ID, title id, author id, genre, type, last check out date, and edit date. It is possible to have duplicate title, author IDs in the table. We need to extract all DISTINCT title IDs, along with the other information listed where the type is not a paperback, and provide a paginated list. I am sure this would be better architected if needed in the real world. Paginate will only get us so far, as this would only show all records.

class BooksController extends AppController {
    var $paginate = array(
        'order'        => array('Book.id' => 'desc'),
        'fields'    => array('Book.id', 'Book.title_id', 'Book.author_id', 'Book.genre_id', 'Book.type', 'Book.check_date', 'Book.edit_date'),
        'limit'        => 15,
    );
    . . . 
    function index(){
        $this->set('hardback_books', $this->paginate());
    }
}

We need to use more to build a conditional query so the paginate will query against this. We can use CakePHP’s data source to help in this. Now, we could also just write this query out ourselves, but this is helpful to know so when you have to build sub-queries for other items. All data is in MS SQL Server, and we can use normal SQL expressions, but we need to grab DISTINCT data, which goes by rows, not columns, which means we will need to do 2 sub-queries in addition to the main one. So we first need to grab a list of the TOP 1 items. This will be our inner query.

        SELECT TOP 1 * 
        FROM [books] AS [bk_inner] 
        WHERE 
            [bk_inner].[title_id] = [Book].[title_id] 
            AND 
            [bk_inner].[type] <> 'paperback' 

Next, we need to encapsulate that query with an outer one that will select all items which match up to the main query ID.

    SELECT * FROM 
    (
        SELECT TOP 1 * 
        FROM [books] AS [bk_inner] 
        WHERE 
            [bk_inner].[title_id] = [Book].[title_id] 
            AND 
            [bk_inner].[type] <> 'paperback' 
    ) AS [bk_outer] 
    WHERE bk_outer.[title_id] = Book.[title_id] 

So we have the queries, and it needs the main query needs to constrain the results that exists in the sub-queries.

SELECT TOP 15 
    [Book].[id],
    [Book].[title_id], 
    [Book].[author_id], 
    [Book].[genre_id], 
    [Book].[type],
    CONVERT(VARCHAR(20), [Book].[check_date], 20)
    CONVERT(VARCHAR(20), [Book].[edit_date], 20)
FROM [books] AS [Book] 
WHERE EXISTS 
(
    SELECT * FROM 
    (
        SELECT TOP 1 * 
        FROM [books] AS [bk_inner] 
        WHERE 
            [bk_inner].[title_id] = [Book].[title_id] 
            AND 
            [bk_inner].[type] <> 'paperback' 
    ) AS [bk_outer] 
    WHERE bk_outer.[title_id] = Book.[title_id] 
) 
ORDER BY [Book].[id] desc

We have the final full query. Now how do we get that? First, we need to invoke the getDataSource() method.

class Book extends AppModel {
    . . . 
    function getHardbackBooks(){
        $dbo = $this->getDataSource();

Next we need to use the buildStatement() to build each statement. Since CakePHP will build a sub query with this, we have to do this twice: once for the inner query, and once for the outer query. The “table” for subquery2 will actually be subquery1, so we need to add that as a “table” in the array.

$subquery1 = $dbo->buildStatement(
	array(
		'fields' => array('TOP 1 *'),
        'table' => $dbo->fullTableName($this),
        'alias' => 'bk_inner',
        'limit' => null,
        'offset' => null,
        'joins' => array(),
        'conditions' => 'bk_inner.title_id = Book.title_id AND bk_inner.type <> \'paperback\'',
        'order' => null,
        'group' => null
	
	),
	$this
);

$subQuery2 = $dbo->buildStatement(
    array(
        'fields' => array('*'),
        'table' => '(' . $subquery1 . ')',
        'alias' => 'bk_outer',
        'limit' => null,
        'offset' => null,
        'joins' => array(),
        'conditions' => 'bk_outer.[title_id] = Book.[title_id]',
        'order' => null,
        'group' => null
    ),
    $this
);

Now, we need to make sure we add an EXISTS:

$subQuery = ' EXISTS (' . $subQuery2 . ') ';
return $subQuery;

Return the data from the model to the controller. In the controller function we need to add a new condition to the paginate. In the conditions, we do not need to use a paired item value to set it, we can use the straight SQL returned from the model.

class BooksController extends AppController {
    var $paginate = array(
        'order'        => array('Book.id' => 'desc'),
        'fields'    => array('Book.id', 'Book.title_id', 'Book.author_id', 'Book.genre_id', 'Book.type', 'Book.check_date', 'Book.edit_date'),
        'limit'        => 15,
    );
    . . . 
    function index(){
        $data = $this->Book->getHardbackBooks(); 
        // Set to the paginate object conditions
        $this->paginate['conditions'] = array($data);
        $this->set('hardback_books', $this->paginate());
    }
}

And it returns the items based on the paginate parameters, ready to use in the view. It provides a DISTINCT list. And yes, I know I used more than 400 words in this one. It was closer to 500 without the code. Oh well, maybe tomorrow will be shorter.

Two People Get On an Elevator

This week it is going to be a little different for all posts. I am still going to follow the format from the past weeks, but all posts this week will be 400 words or less. Including the code posts I will be doing.

Up for this week:
Monday – Two People Get On an Elevator; Planning ideas and thoughts
Tuesday – Count the Number of Cakes; focusing on coding
Wednesday – Who Do You Like; ideas and code segments for people like me, social lepers
Thursday – Following the Yellow Brick Road; examinations on location services, social integration and strategy
Friday – 400 Words to Madness; fun stuff to finish up the week

Some of the best ideas are planned in 400 words or less. At one company, this was called the elevator pitch. You have that short of a time to sell someone on your idea. Have you planned it through? Do you even know what it will do beyond your own comprehension? These are things to remember when trying to plan for the pitch. Not everyone is able to just quit their job, work on their own project and be able to fund their ideas, equipment to get up and going, and market this thing. Many people need to have some kind of investor(s) backing. So how would you sum up some of the greatest products in less than 400 words.

One semester I had to come up with ideas to do this. We had to take products that already existed, examine what they did, what benefit they provided, and why they were in demand. These products were not necessarily ones that we knew of. And we had to present these benefits to the rest of the class, and had to do it in under 4 minutes. We could not talk fast, and we had to be coherent. Our grades were going to be determined by anonymous feedback from the rest of the class. If the pitched worked, we would get good grades. If not, we would fail.

In the real world, it is much the same. You have about 400 words to sell your idea. You have made the plans, models, diagrams, etc. Now you need to get someone to back this idea. Much like everything else, you must plan for this. Highlight good points, ROI, and ease of use. Practice on other products. In 400 words, describe the product and your vision.

Riddle Me This

Ok, for Friday I thought I would post a few riddles to help me wind down from the week.

After a very long day of work, a man goes to bed. Before he went to bed he wound his clock and set the alarm for noon the next day. If he went to sleep at 10 pm, and fell asleep immediately, how many hours of sleep did he get?

What occurs once in every minute, twice in every moment, yet never in a thousand years?

A man without eyes saw plums on a tree. He neither took plums, nor left plums, how can this be?

A man pushes his car to a hotel and loses his fortune. What happened?

A woman and her husband are together. The woman shoots him, then drowns him, then hangs him. Five minutes later they walk out the front door to grab dinner and catch a play. Can you explain this?

An island is in the middle of a lake. The lake is old and in a remote part of the country. Bridges to the island, there have been none. There is a tractor on this island. This tractor provides hay rides around the island. The tractor was not transported to the lake by plane or boat, so how did it get there?

And if you have a good riddle to add, please share.

Everywhere and Nowhere

The Desert
Courtesy of Ducklips Photography

Ever get the feeling that the internet is everywhere and nowhere? Have you ever tried visiting the Internet in person? How many people have achieved this goal, (besides anyone from the Matrix)? In reality, the internet is just a long set of cables, switches, routers, firewalls, etc. Not too exciting of a place to go. The “location” of the internet is not as important as your location. And this can mean you as a person, you as a company representative, you as a salesperson, you as leader. Each facet has its own little niche of things that can happen. Last night, I saw a new Pepsi commercial. A lady was on the beach and there was a very long line to the drink vendor/cabana. So she quickly got on the phone and put in her location (actually a little off of where she was) and that she just saw David Beckham at the beach. Everyone from this line gets the updates on their phones and run to try and find him, clearing the line so she could get her Diet Pepsi. Not all location check ins will have this affect, obviously. But as either an entity or person providing services/products, you can strive for that.

Two major events happened this past week, (actually three – the Royal Wedding, but that is not covered here), Osama bin Laden was killed and a local inadvertently tweeted the whole event; and Facebook and Assange are fighting over whether or not Facebook has let the government in the backdoor to spy on the Facebook community. Each one has a lesson for location services.

Continue reading Everywhere and Nowhere

I am Not All Alone In the World

Chicken - Ducklips Photography
Courtesy of Ducklips Photography

As I scour the web and read, I come across many different articles. One thing that has been in the news for some time now is the unrest in the Arab world, and the different demonstrations, and subsequent backlash from those events. But it is not just about politics, it is about using the social media to be more than a way to play Farmville or Angry Birds. I love the social media outlets just as much as the next person. It is fun, I love joking around with my friends. The Hirdweb Facebook page is another extension of this blog, and I use it to suit my needs. However, many businesses set up a page, then let it flounder after a few months. It is not enough to just set up a social campaign, or page, or feed, the company must keep it going. And that can be easier said than done.

Doing any type of campaign, whether it is a traditional spot, or a new social campaign, there needs to be some type of sustainable presence and interaction. Whatever the product or service, if you want the people to keep coming back, it has to be more than just “Here is my product/service! Hope you enjoy” type of message. Some campaigns do not provide products or services, they provide messages, movement, and reshaping ideas. No matter what the message is, no matter what the end result target may be, a sustained drive will lead to better success than a quick one hit and bail.

Continue reading I am Not All Alone In the World

You Did What?

Today’s topic is kind of short, but a very important one. If you are not living under a rock, then you know about Sony’s problem with their Playstation online services getting hacked and being down for some time. A new concern now is that this has exposed the credit card numbers of the membership. Something that can definitely cost some good will and trust. However, Sony is a major corporation, and can recover from this. Can your business, if something like this were to happen?

I still see multiple instances of applications (And not just PHP applications) where carelessness has overtaken common sense. The web is no longer just a set of reading materials. It is now more than that with interactive applications and a flow of data that travels in all directions. So why is it that a huge problem is a lack of security for this interaction? The biggest thing I still see is with forms. Multiple sites ask to sign up for something, like a list, and email notification, account to get in to the site, etc. And one of the most powerful things today is information. And this does not mean just credit cards and government identification numbers. These can include names, emails, addresses, cities, passwords, secret phrases for confirmation, etc. Harvesting this can lead to identity fraud, selling to spam lists, etc. Secure your forms! It does not take much time, and can pay off, especially for the small businesses who will not have the money or name recognition of the larger corporations.

Easier said than done, I suspect some are saying. Well, yes and no. This should not be an after thought it should be first. In the PHP language, functions exist to help in this. Some ideas for securing forms: mysql_real_escape_string, pg_escape_string. In fact, if you are using PHP, then make sure to understand the different options available for your database.

That is not all though. You should also use a parametrized approach for inserts and updates. A quick example of this:

$sql = "UPDATE sometable SET somefield = ? WHERE value=?";
$parameters = array($_POST['data1'], $_POST['data2']); 
$dbo->query($sql, $parameters);

Now that was not too hard was it? However, security is not something to pass over. You should understand what data you are collecting, and validate the data, and then securely save the data. Validating it can be as easy as making sure it is an integer value, email, certain number of characters. Items like that can go a long way to verify what you are getting is what you need, and will not harm your application. For example, if a form had a field for first name, last name, country, email address, you can safely validate those fields. First name, last name should only be characters. Those fields should not have special characters, numbers, etc. Email address should be validated against a regular formed email address. You can even go one step further to verify it is a valid email address and exists somewhere out in the cloud.

Big lesson though, secure the data. Secure your application. Do not let a shortcut become your Sony Playstation meltdown.

Measured for Success

Keeping in the theme from last week, every day will have a specific theme, and I will keep the same ideas of last week. So without adieu, here is this weeks plan:

Monday – Measured for Success; Planning ideas and thoughts
Tuesday – You Did What?; focusing on coding
Wednesday – I am Not All Alone In the World; ideas and code segments for people like me, social lepers
Thursday – Everywhere and Nowhere; examinations on location services, social integration and strategy
Friday – Riddle Me This; fun stuff to finish up the week

Birds Fighting Over Food
Image courtesy of Ducklips Photography

And today’s topic is figuring out what is the measure for success. If we look at last week and my posts, I wanted to have a post every day of last week, and I got through Thursday. I missed Friday, and that should have been the easiest one to do. So based on my own goals, was last week a success? I would have to say no. I put a goal of 5 posts in 5 days. I did 4 posts in 5 days, so I fell short. And that is what is important to understand when trying to plan a new application: what is the measurement for success, and can it actually be measured. When planning for an application, it is important to understand what will define the success of the application. It is much like a goal. It should be conceivable, achievable, measurable, and desirable (others do exist, but these are important when planning on gathering statistics). Another important part of this measurement is the fault tolerance allowance. This includes the level of error, or missing the set goal, that you are willing to accept. For this, let’s examine two different scenarios.

Continue reading Measured for Success