A face-lift and an update

It’s been right around a year since I posted last in the blog, and I figured it was time for an update, after someone commented on my How to Handle Online Harassment blog post and a code error prevented me from approving and replying.

A couple new things have happened that have kept me out of the how-to-tech world as much as I have been in the past:

First I was married around this time last year. The wedding itself was an exercise in fusing current technology with the 1940s. The wedding ceremony music was timed to the second from start to finish so it could begin on 11/11/11 @ 11:11am. (If only the sound booth guy would have followed instructions, everything would have worked out fine). Everything was instrumental, but varied from Vivaldi’s Four Seasons, to Smashmouth’s Accidentally In Love. I walked out, of course, to the opening credits music from The Matrix: Revolutions. It had to be done.

The reception music was all controlled from my Motorola Atrix Android phone, using some Brookstone Outdoor Wireless Speakers, and a subscription to Grooveshark.com. A slideshow video was created using Animoto.com to add a little more flair and excitement to the otherwise dull “here’s all our photos from our entire life – YOU MUST WATCH THIS BORING THING” video. I hate those – especially the ones that require 3 or 4 songs to finish – mine was 1 song and only spanned our adult lives from just before we met up to the wedding. You can view it below (if you have Flash):

The decorations for the wedding (if they had to be ordered) were all homemade with the materials being ordered online, and mostly from etsy.com. I made our Save the Date notifications and our wedding invitations in Adobe Fireworks, and we created a Facebook page to keep everyone up to date, and a Google Document for handling the RSVPs using the Custom Form interface.

Source: appboy.com

The second major tech-related event in my life was receiving my first iPad (3rd Gen) as my wedding gift to myself when it was released in March. I have had it with me every day, all day, and have been trying to use it as a content production device, but there are just no good apps for anything other than photo editing for my various interests. There are indeed a ton of apps out there for other peoples’ interests, but coding and photography are where mine lie, and I have yet to find a coding app that meets my three feature criteria: SFTP, PHP code highlighting, SVN control – all within the same app.

If you’re aware of any apps that contain all 3 of those features, please let me know in the comments below. I have been searching for nearly 9 months now, and have run across several that meet 2 out of 3 – and as the song goes, “2 out of 3 ain’t bad,” but since there is no file system that spans multiple apps, I need all 3 for it to effectively replace my work laptop.

I did consider starting a “working in the cloud: iPad edition” series, but I don’t have the money that someone like iPad Today has for trying and testing all kids of app recommendations, and there are already fairly comprehensive blogs dedicated to this subject, like AppAdvice.com.

In other tech news, I started backing various projects on Kickstarter.com. So far I have backed 3 projects that I considered useful or unique items.

First to ship, but the 2nd project I backed, was the SmarterStand from smarterstand.com. So far I have not engaged in 100% use of the product because I currently use a DoDoCase for my daily iPad protection. However, I foresee a future blog post here reviewing the product once I do decide to use it daily.

The first product I backed, and likely next to ship, was the popular Pebble Watch. I have been waiting for this since May 2012, and look forward to the day it actually ships. I don’t know if I will get involved in writing any applications for it, but I do plan to test it both with my Android phone and my iPad.

And most recently, a product that hasn’t even met its funding goal yet: Light by Moore’sCloud. If you’re reading this before 12/21/2012, please pledge to back it also…not because of the Mayan Calendar, but because there are 25 days to go (at the time of this post) and they are only 26.3% funded. It is a mobile-controlled (iOS at the moment) lamp that runs LAMP, with an app for controlling the color, timers, and wifi for alerts & additional functionality. It’ll match any part of an image for color choice, as well as cycle through other custom choices. You’ll have to watch the video on their page to get all the details of this beautifully designed product.

And finally in other news, as I mentioned at the start of the post, I was forced to update the blog in general because I had a legit comment on my How to Handle Online Harassment blog post, and I needed to approve and reply to it. In doing so, I removed several plugins, updated several more, and decided to go with the “twenty eleven” blog theme from WordPress this time. It’s simpler, and now my blog works with the WordPress iPad app.

In updating and replying to the aforementioned comment, I noticed that someone cited my article in their own article back in April 2012, along with many other sources. Their article was titled “Social networks: the rise of online harassment“. This marks the first time I’ve been cited in something as a “source” instead of as a link. So, thank you Anna Maria Alba for considering my blog post, and its comments worthy of citation.

Technorati Tags: , , , , , , , , , , ,

Jasper: Just a store platform experience, reworked

Jasper LogoFor the past 3 years, I’ve been working on a store that uses the Yahoo! Store platform. At first, the user interface for the web page design and page object models was easy to grasp (both the prefab versions and the custom ones I had access to), but going through the entire rewrite process was a pain – the biggest of which was the requirement of perfection. If a mistake was made in any field names or data-types it held, the whole object model had to be scrapped and started over. They’ve made minor improvements over the past 3 years to their Merchant Solutions side of things, but they have been extremely minor. One thing that hasn’t changed is the interface to edit pages.

There are two methods of doing the editing, depending on the Yahoo! Store platform that you have. If you’re on the Legacy version, you must go to the page itself, and click edit. This provides you with a series of fields and input boxes for each type of field. No intelligence in the design of what those fields are for or differentiation in how they interact.

If you’re on the Merchant Solutions platform, then you have the option of going directly to the page still, or you can do it in a flat-file pseudo database-like UI which is nothing more than a search-by-field interface, which presents you with a different-looking (but still the same) interface for editing the page.

Over the next few months, I’m going to embark on a web-based interface for importing the legacy store feed (objinfo.xml, which can’t be customized) and see what can be done with the data as far as modifying it, preparing it, cleaning it, and exporting it back to the store. I’m also going to attempt to code it entirely using Kodingen.com. I’ve done a highly customized version of this concept for the company I currently work for (at the time of this post), but none of the code will be reused from that project, and this project will have different, and limited features (in some areas, and expanded in other areas), but for a different data model. In some areas, this application will be more limited (since it’s working with a standardized data format, rather than a customized “catalog.xml” feed from Merchant Solutions. Once this basic version is solid, I may start working on a customized version, or even offering a customizing service to handle the catalog.xml file.

Some things I’d like to do differently with this basic version is:

  • create an install process (a la phpBB)
  • extensive automation, and possibly some AI concepts
  • learn more about object-oriented design and how it can be extended conceptually
  • experiment with some various php and javascript frameworks

There are plenty of other feature sets that I’ve learned and developed in addition to these in the past and plan to use as well. So we’ll see how this goes, and I’ll post some updates here. Depending on what I plan to do with it, I may or may not open-source it. If I do, I’ll host it on Google Code.

Technorati Tags: , , , , , , , , , , ,

How to Connect to SQL through Windows Authenticated ODBC in PHP

For about the last year, I’ve been creating a CMS (content management system), for the automatic management and maintenance of my company’s eCommerce site, on the Yahoo! Store platform. The software imports the entire store automatically, runs a series of cleanup processes with about a dozen different criteria, saves the changes it has made, exports the modified pages, and makes them available to download from Jada’s interface. This automation cuts the need for about 3-4 people doing a weeks’ worth of work, and does it all automatically in 10-30 minutes. The one thing it doesn’t do, is the one cleanup process that takes the longest, and requires the most human thought: comparing every product’s available options on the site, and checking them against actual inventory in the order management software.

Until now.

Our current order management software runs as a MS Access front-end to a MSSQL 2005 server backend through and ODBC DSN connection. This connection has been limited to MS Access and MS Excel application/queries, and thus, was the limiting factor to writing this most-complex cleanup process into Jada. The most difficult part in my development was finding an understandable article describing how to make an ODBC call, and then actually get the data back, in the same simple manner that one makes a MySQL query. The real issue has been once the connection is closed, the result cannot be accessed. I had to find that out the hardway, via Microsoft’s convoluted documentation on using ODBC.

Here’s the code I’ve used to make the ODBC connection in PHP (unfortunately my blog’s template can’t handle actual code right now):

Code Breakdown

We’ll start creating a function that makes an ODBC connection, passes it an SQL query, then parses the data into a table/array and return the array.

Function call

function odbcQuery($sql, $attempt="") {

When we call the function, we’ll provide the SQL Query we want executed, and an optional description of what we’re trying to do with the query. In this way, if it errors, an semantic error will be displayed along with the technical one to help locate the code easily.

Database Connection

// Establish an odbc connection with the database
$link = odbc_connect("My_DSN_Name", "", "");

When running odbc_connect() it takes 3 parameters:

  • the DSN; Server,Port; or Server/SQLInstance
  • username
  • password

When connecting using Windows Authentication & a DSN (as this example is about), there are some caveats and things to remember:

  1. On the web server, the User running the Web Service process needs to be a User with permission to access the SQL Server.
    1. In my case, the user running the web server is SYSTEM, and so the user trying to access the SQL server is “DOMAIN\COMPUTERNAME$“.
    2. There is no password for a SYSTEM account, and so on the SQL Server needs to have a user created named “DOMAIN\COMPUTERNAME$“.
    3. Due to some security concerns, I’ve decided to give the account read-only access to the database I want to access. You’ll need to consult your own IT Administrator or security advisor for your security concerns.
  2. In the odbc_connect() statement, you then only need the name of the DSN (which I assume has already been configured on the Web Server you’re using) , followed by two null-quotes: “”.

This creates an active link via ODBC to the SQL Server…supposedly

Database Connection Checking & Error Handling

if (!$link) {
	die('Could not connect: '.odbc_error().': '.odbc_errormsg());
} else {

Next, we check the link . If it just flat-out doesn’t exist, then we kill the program, throw an error message that will read: “Could not connect: <;insert odbc error code>;: <;insert odbc error text>;”. Otherwise, we move on…

Sending the SQL Query & Checking Response

$data = odbc_exec($link, $sql);
if($data === false) {
	echo "ODBC Query: ".$sql."

"; die("ODBC Query failed: ".$attempt."
Error: ".odbc_error()); } else {

Now that we have a valid link to the database, we’ll send a request for data using the odbc_exec() function. This function sends the connection resource ($link) and the SQL Query we want run ($sql). It will return a “ODBC result identifier” or false.

Since a result identifier could, I assume, be the number 0 (zero) I want to ensure that $data is actually false and not just zero. That’s where the triple === comes in. When doing conditional statements, using == will convert the data being compared into a true/false value, where zero or nothing = false and anything else = true. When you use === you test for an actual boolean value, meaning anything including zero = true and false = false.

If the query failed, and resulted in a false result, we’ll display an error message: “ODBC Query: <;insert actual SQL Query>; // ODBC Query failed: <;insert query description>; // Error: <;insert ODBC error code>;”. Otherwise, we’ll move on…

Parsing the Query Results – Column Headers

// Initialization
$row = $fields = $records = $result = array(); 	

// Get the result's column names
$count = odbc_num_fields($data);
for($x=1;$x<=$count;$x++) {
	$fields[] = odbc_field_name($data, $x);
}

We start off by initializing all the variables we're going to use in the next bit of code, to make sure they're empty.

Then we'll run odbc_num_fields() over the $data to get the number of columns we need to iterate through. For columns, the counting starts at 1, so the for-loop starts at 1.

Iterate through each column name and add it to an array, called $fields:

Array (
	[0] => field_name_1
	[1] => field_name_2
	[2] => field_name_3
)

Parsing the Query Results - Records

// Get the result's data: array[record#][column#] = value
$count = odbc_num_rows($data);
for($x=0;$x<$count;$x++) {
	odbc_fetch_into($data, $row, $x);
	array_push($records,$row);
}

Then we run odbc_num_rows() over the $data to get the number of rows we need to iterate through. For rows, the counting starts at 0, so the for-loop starts at 0.

Iterate through each record row and insert it to a temporary array $row using odbc_fetch_into(). Then take $row and put it into an array of records, $records giving you something like this:

Array (
	[0] =>; Array (
		[0] =>; record_1_column_1
		[1] =>; record_1_column_2
		[2] =>; record_1_column_3
	)
	[1] =>; Array (
		[0] =>; record_2_column_1
 		[1] =>; record_2_column_2
 		[2] =>; record_2_column_3
  	)
	[2] =>; Array (
 		[0] =>; record_3_column_1
 		[1] =>; record_3_column_2
 		[2] =>; record_3_column_3
  	)
 )

Making the data useable

Now that we've got two tables/arrays of data - the field/column names, and each record's array of data - it's time to make it usable in a format that we can consistently expect to be returned. There are two ways to do this. We can create an array listind every record as an array with column_name keys and values

// Return data in the format: array[record_id][column_name] = value
foreach($records as $rid =>; $record) {
	foreach($fields as $key =>; $name) {
		$result[$rid][$name] = $record[$key];
	}
}

or we can list every column as an array of record id's as keys and values.

// Return the data in the format: array[column_name][record_id] = value
foreach($fields as $key =>; $name) {
	foreach($records as $record) {
		$result[$name][] = $record[$key];
	}
}

Personally I find the first option to be more consistent with my results when calling a 2-dimensional result from MySQL queries, so it is the one I have gone with in my example at the start of the post, and in this description.

The foreach() statements describe a compilation of a $result array in this manner:

  1. For each item in the $records array, store the record_id as $rid, and the record array as $record.
  2. Then for each item in the $fields array, store its cardinality as $key and it's value/name as $name.
  3. Then compile an array, iterating through each of the fields, storing this $record's associated cardinality $key's value into the $result array's storage for this record's id ($rid) under the appropriate field name.

It's a lot easier to grasp than it sounds. Basically, take array from the Query Results - Records section, and replace the # with the column name in each: [#] =>; record_y_column_x, but store it as a different array, called $results. The resulting array would look something like this:

Array (
	[0] =>; Array (
		[column1] =>; record_1_column_1_data
		[column2] =>; record_1_column_2_data
		[column3] =>; record_1_column_3_data
	)
	[1] =>; Array (
		[column1] =>; record_2_column_1_data
 		[column2] =>; record_2_column_2_data
 		[column3] =>; record_2_column_3_data
  	)
	[2] =>; Array (
 		[column1] =>; record_3_column_1_data
 		[column2] =>; record_3_column_2_data
 		[column3] =>; record_3_column_3_data
  	)
 )

Close the connection, Return the result

		odbc_close($link);
		return $result;
	}
}

Now that we've stored the data we need from the volatile $data variable returned from the SQL Query into $result, we can close the connection to $link using odbc_close(), and then return $result for the program to do with it what it will.

Conclusion

This is just an example code that explains one way of many to extract a variable 1-2 dimension array of data from your SQL Query, using a Windows-Authenticated ODBC DSN connection. There are many other methods to do this, as well as security fixes, data scrubbing, and other modifications that one would probably want to do.

This is the first function I've written in any language to access an SQL Server via ODBC. This is also a function that has worked in tests, but that I have not yet put into production. I encourage you to take this bit of explanation and massage it into something that fits your needs in the code that you're writing, and don't rely on what I've got here as a written-in-stone example of good production-level code. This sample will change many times before I actually implement it.

Happy Hacking!

Technorati Tags: , , , , , , , , , , , ,

TweetSuite WordPress Plugin + Ping.fm (Preview)

A couple weeks ago, I found out that Twitter had a Search feature that showed real-time tweets for a keyword. I gave it a little thought, considered what it would take to actually write the software – and then wised up, and decided to see if someone already did the hard work.

Sure enough, Dan Zarrella over at danzarrella.com had. He wrote one for Tweetbacks, and then expanded on it with TweetSuite. So I gave them a shot.

I started with Tweetbacks on the FreeformFrog.com Blog and everything seemed to be working fine – until one day when the Tweetbacks stopped. It just stopped finding them – even though I knew they were getting tweeted – because I was using Ping.fm to syndicate my blog posts to the appropriate social networks.

I gave it a couple weeks, and then decided I was going to fix it. I was tired of not having my TweetBacks working – especially during my efforts pushing a Social Networking campaign at job.

So, I added @danzarrella, and asked…

@danzarrella do you have plans to integrate ping.fm posting in TweetSuite? If not, mind if I take a crack at it?
from @neotsn at  from web

A few minutes later, I got a response…

@neotsn go to town
from @danzarrella at

Technorati Tags: , , , , , , , , , , , ,

twitter & tsn.7

With a new My Spot page comes new possibilities. This time around, I’m going to make a concerted effort to actually write in new code and attach a new database backend that pulls from the phpbb database and the users’ accounts on the-spot.net.With this new plan, there will be increased ability to add features and remove features on the user-level…that is to say, you can choose what you want to see on the page.

There will also be some integration to popular social sites right on the My Spot page, like twitter and flickr – community based sites with an API that doesn’t require you to visit their site in order to view content.

Last night, I worked with the twitter.com API and with the RSS reader that I’ve hacked up in PHP, and turned out the twitter stream for the-spot.net’s twitter friends. That will go on the front page of the My Spot page so that everyone on tsn can know what all the other tsn members are twittering about.

The next thing I’m going to be doing with that is working on a way to allow the users to update their twitter status directly from tsn. That’s going to take a bit more work than displaying the feed, but it will be a good challenge.

On the previous version of the site, there was a flickr flash app that showed the new photos from the tsn flickr group. That will be coming back as well.

I’m also going to try to make the User Control Panel more accessible and integrate the Buddy List into the My Spot page so you can see when your favorite posters are online (since the information box at the bottom displays the last X minutes, and not “Currently” online).

I’m still trying to gather new ideas from everyone about what they’d like to see on the page…and I hope to make it modular like that previous My Spot page was so they can just be plugged in to the template based on information in the new database determining whether or not they wish to see that.

if you have any ideas – leave comments, or message me directly.

Blogged with Flock

Tags: , , , , , , , , , , , , ,

Technorati Tags: , , , , , , , , , , , , , , , ,