Archive for 'Code'

Serving Localhost from Mac OSX to Parallels

MAMP LogoOn occasion during development, I like to check how my .css and javascript functionality works in IE. Right now, IE only has about 25% of the total internet market for browsers (w3schools.com) for 2011; and it is slowly deteriorating. But I don’t want to disparage users for using inferior products, so I like to test against them. Besides, 25% of market share is not ALL bad.

I did some digging on Google and found a few helps, but nothing as specific as I wanted. So here I present how to get Parallels to server up MAMP pages from my OSX MacBook Pro. 
Read more

Goal Driven Relevant Decision Making

I had a real epiphany today. I suddenly realized that I am so busy doing work at work, I don’t have time for growth. I find that there is no room for judgment or creativity on my part. I am told what to do, how to do it, and the order to do it in. And the priorities may change from one day to the next. I am not allowed to provide input or innovation. It’s almost mechanical. The only thing I really get to decide is determining how long it’s going to take, but even that gets negotiated. To make matters worse, I get thrown the task of fixing other coders bugs. I feel like an extension of someone else. Like I am there to be the clone of someone who feels they need another body. They decide what needs to get done, how they want it done, whether or not it sounds too difficult, and how to implement: design, function, and format. In a word, micromanaged. Didn’t that go out of style with the 90′s?

How did I come to that realization? It has taken some time to realize, but it hit me full force today when I couldn’t even think outside the box for a simple reordering algorithm. I was given the opportunity for a brief moment and I froze! I have allowed myself to get to this point. It’s not from lack of effort however. I always put forth ideas, best practices, and user interaction improvements. The problem is, someone else has control and I always get overridden. I don’t even know if my ideas get passed on to the powers that be. I am not included in any discussion, asked what I think, or allowed to propose designs or functionality. Again, I am told what to do, every step of the way.
Read more

CakePHP Shell Not Seeing MySQL with MAMP Pro MAC

MAMP is a great product. It makes using the MAMP stack on MAC very easy. I liked it so much I actually purchased MAMP Pro. Installing was a breeze, configuration is simple, and it is up and running in no time. However, for some reason, when I am trying to connect to MySQL from a CakePHP shell, the database connection cannot be found.
Read more

Single Login For Multiple User Types with CakePHP

I started working on a project that requires a single login for multiple user types. Because of the way my mind organizes things, I was having difficulty getting my mind around multiple models pointing to the same table in the database. It just felt messy. But I found this to be the best solution. I can provide single user login and keep the user functionality separated.

In this case, I have managers and tenants both pointing to the users table. I simply add a ‘type’ column to the user table to track what type of user it is. Then in my callback methods on the models, I set the conditions for the beforeFind and the beforeSave within each model to it’s corresponding type. This keeps both the data it displays and the data it saves in check and accurate. Here is what my manager model looks like.

<?php
class Manager extends AppModel {

 var $name = 'Manager';
 var $useTable = 'users';

 // only return users where type = Manager
 function beforeFind($queryData) {
$queryData['conditions']['Manager.type'] = 'Manager';
return $queryData;
 }

 // Ensure the Type is set to Manager before saving this record
 function beforeSave() {
$this->data['Manager']['type'] = 'Manager';
return true;
 }

}

?>

The same would apply to the tenants model. This works like a charm. It helps to provide excellent separation between user types without writing a lot of extra code to manage and check for the differences in user types.

Happy coding!

Open Source CakePHP Components

CakePHPI am getting more focused in my engineering career. Lately I have been feeling a strong desire to contribute to the open source community. Of course by open source community I mean contributing code and making it available to anyone who wants to use it… for free. As such, I decided to pick something I am passionate about. I have decided to create components, helpers, and other bits of code that are usable with the CakePHP framework. I have also decided to make these snippets of code available on GitHub.
Read more

Domain Validation Class Updated

Around three weeks ago, I sent an email to iana.org about their TLD file. (http://data.iana.org/TLD/tlds-alpha-by-domain.txt) This is the file that contains a list of all the valid top level domains (TLDs) on the Internet.  Here is a snippet from the email I sent requesting how to best access this file for my domains class:
Read more

Hidding Table Row While Preserving Colspan

Someone asked me today how to write the CSS for a <TR> so that the <TD colspan”2″> would still maintain the colspan when the display was changed from none to show. It turns out the solution is easier than you might think. He actually came up with the solution, but I took it a step further and updated it so include a toggle. Now you can repeatedly change the row from hidden to visible. Keep reading to see the solution.
Read more

Source Code Management with Git

Linus Torvalds is the man who started Linux. Known in it’s early stages as the Open Source Unix. Since then, it has evolved into something even bigger than I think he even imagined. Maintaining the source for a project that large can be time consuming and difficult. Linus said that he would maintain revision control with tar balls and it was easier than using CVS. But he needed something that would work in a distributed fashion and allowed for easy merging. But there were no open source options available.

This, GIT was created. It is designed from the ground up to be a true distributed repository. Think of torrent source coding. There is no one central location, but everyone has the master branch at any one time.

I have been a big fan of subversion, but after listening to this talk, given by Linus at Google, I am considering switching to GIT. And to think, I recently paid $60 for a Subversion application to run on my mac. Ouch!

Real World Email Validation for PHP

Learn PHPHave you ever gone to a website that asks for your email? You really want to get in to the portion of their website that has the information you want, but the only way they let you in is by giving them an email address. So you are faced with a moral dilemma. Do you give them your real email address, do you give them your friends email address, or do you make one up? If you are like me, you probably make one up like a@b.com or noway@example.com. Most of the time this will get you in where you want to go without the hassle of being bombarded with all of their junk mail. Now I don’t worry about giving them my really email since I use gmail. I can just filter it. usually google filters it for me, so I am good.
Read more

Parsing Comma Separated Value (CSV) Files with PHP

Learn PHPI hate trying to parse CSV with PHP. I get PO’d ASAP because everyone should be using TSV instead. I know, it can be as difficult to comprehend all of the acronyms as it is to figure out the comma separated values. Not impossible, just very time consuming.

I have had multiple occasions where someone gives me a file and asks me to parse it. The issue is its in CSV format. CSV Sucks! The problem is when you get someone trying to be cute so they put a comma (,) in one of the records.

So let me back up. CSV started out as a basic format to make data portable. A CSV file is basically a database in a way. Each line in the file represents a record. Each field within the record is delimited by a comma. Or so it is suppose to work. So typical CSV looks like this:
Read more