Hi, my name is Terry Smith and I'm a developer and aspiring entrepreneur.


Archive for the ‘Startup Ideas’ Category


29
Jul

Programming your own PHP framework, Part 1

Posted by Terry on 07/29/2009 at around 2:33 PM

I’ve always been torn about posting code on this site, since I’ve historically (if I can use that word) wanted to keep it about business ideas.  However, since I’ve started working for b5media, I’ve had a lot less time to work on my own projects; therefore I think I’ll start talking about some code.

These posts are geared towards people who know programming (specifically to people who code in PHP, but if you can read the code, you can port it to most other languages).

As with most engineers, I like to re-create tools I use on a regular basis.  Some I’ve tried and failed at for various reasons (3D game engine), but one of the ones I’ve always wanted to try is a PHP framework of my own.  So last weekend, I sat down and wrote a basic framework that I would enjoy using.  This series of articles will talik about how I did that.  So, without further ado:

There are several components of a web framework: URL rewriting, database abstraction, an MVC framework, a templating system and plug-ins.  All of these are optional and you can pick and choose which you want to include in your framework and how you want to include them. 

In this first article, I will cover URL rewriting. 

The most important thing here is to remember that you can style your URLs in almost any way you choose.  In my case, I have elected to combine some of the existing frameworks’ systems and structure my URL in the form domain.com/controller/module?var1=value&var2=value.  This solves one of my personal pet peeves with existing frameworks.  Many of them are an either or (technically an exclusive or) system.. your GET variables are either all in the query (ie. domain.com/index.php?controller=test&module=function&var1=value&var2=value) or they are all in a directory format (domain.com/controller/module/var1/value/var2/value).  Most frameworks do a poor job of mixing and matching.

Step 1: .htaccess/mod_rewrite

Note: As you can see, I am gearing this tutorial towards what I know (Apache + PHP).  However, I have made the code as easy to read and understand as possible so that you can port it to other languages, web servers, etc.

The first step is to configure Apache to allow for our rewriting.  This is done through mod-rewrite, which on Apache 2+ can be enabled by going into the apache2/mods-enabled directory (on Debian systems usually located in /etc/apache2/mods-enabled) and create a symlink to the file ../mods-available/rewrite.load with the following command:

ln -s ../mods-available/rewrite.load

Now you can re-load Apache, and mod_rewrite should be enabled.  The second part of this step is to create an index.php file in your web directory and route all traffic through it.  To do this, create a .htaccess file in your web directory with the following inside:

<IfModule mod_rewrite.c>
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^.*$ /index.php [L]
</IfModule>

This will route all traffic for non-existent pages and directories to index.php where we can parse the URL and route it appropriately. If you are having trouble getting this to work, ensure that you have the AllowOverride variable in your Apache configuration set to “All”.

Step 2: Parsing the URL

Open up your index.php file in your favourite editor (I still use vim).  Interestingly enough, the first step to deconstructing the URL is constructing it.  Since there is no since variable (that I’m aware of) to get the full URL, we need to put all of the info variables together first.  We can do that like so:

$path = parse_url(
     (isset($_SERVER['HTTPS']) ? 'https' : 'http') . '://' .         // Scheme      
     $_SERVER['PHP_AUTH_USER'] . ':' .                               // User      
     $_SERVER['PHP_AUTH_PW'] . '@' .                                 // Password      
     $_SERVER['HTTP_HOST'] .                                         // Hostname      
     $_SERVER['REQUEST_URI']                                         // Path and query string
);

Here, we’re using PHP’s parse_url function to break apart the full URL into parts that PHP can handle a little better.  Specifically, we can now break apart the file request:

$temp = explode("/", substr($path['path'], 1));
$controller = strtolower((@$temp[0]) ? $temp[0] : "welcome");
$module = strtolower((@$temp[1]) ? $temp[1] : "index");

In this case, I’m only allowing two parts to the URL: the controller and the module.  You could expand this to include any number of parts.  I am also setting the default controller and module so that a request to domain.com/ or domain.com/controller will still have a place to go.  I finally convert the controller and module to lowercase so that I can identify the file name there the controller lives (more on this in the MVC part of this series).

Finally, I can route this to a class/function.  In my case, I am going to send it to a class called {$controller}Controller and a function called ($module}Handler.  We do want to make sure that it’s a class we’ve defined in our directory structure as well, to protect again any vulnerabilties (so users can call any class/function)  So I want to make sure that those exist:

if(!file_exists(CONTROLLER_DIR . "{$controller}Controller.php")) {      
     $controller = "Error";
     $module = "index";
}
if(!method_exists("{$controller}Controller", "{$module}Handler")) {
     $controller = "error";
     $module = "index";
}

If it doesn’t exist, we re-direct this user to errorController class and the indexHandler function.  This class/function would ship by default with the framework and could be customized later.  Provided that it passes that test, we can finally send it off to the appropriate place:

$class = $controller . "Controller";
$controller = new $class;
$method = "{$module}Handler";
$controller->$method();

In this case, I am using PHP’s __autoload function to load in the appropriate files/classes (again, more on this in the MVC part).

Step 3: Explore

That’s it!  You have a basic URL re-writing framework.  There is obviously a lot more to come, but this should give you a taste of the flexibility a PHP framework can give you (especially one you’ve designed).

Feel free to explore all of the other options for structuring URLs your own way.  In the next part, we’ll cover the MVC framework so we can put this to good use.

Note: I by no means consider myself an expert in PHP.  I view these articles as equal parts instruction for those of you in the dark and learning opportunity for me.  Feel free to comment or critique, especially if you can make it faster/cleaner/more secure!

15
Jun

An Engagement Story

Posted by Terry on 06/15/2009 at around 9:31 PM

So there it was, the big day. The day I popped the ultimate question and asked my then girlfriend to become my then fiancee (now wife). I was living in San Jose, California, life was good and Ashlyn was coming to visit for a few days where we would enjoy the beach and check out Disneyland. Sound romantic? Well I’m getting ahead of myself; it was actually the day before I was going to ask the question and I didn’t have the ring. Yup, you read that right: on the day I proposed, I didn’t have the ring to propose with. It was back ordered. I had a ring (Engagement Ring Jr.), but not the ring.

By the time we got back to my apartment after I picked her up from the airport, she was tired and just wanted to pack for our trip to Disneyland and go to bed. Unbeknownst to me, she goes to the bedroom and begins to empty out my suitcase (where, being smart, I had “hidden” the ring). So as soon as I heard the unzipping of the bag, I ran to the bedroom as she was reaching into the “hiding” spot and, in true Terry style… I tackled her.

Yup… tackled.

She had found the box; no definitive proof of what it was (she suspected), but she had felt it and, based on my response she knew it was probably something for her. So I had to improvise. Ashlyn had brought down a summer dress (her “California dress” she called it) so I asked her to go into the closet and put it on.

The closet. The bathroom was open, but the closet seemed more appropriate for some reason. Please don’t ask.

It was a walk in closet so we closed the large mirrored door so that she had enough light and still couldn’t see me and vice versa. So I got down on one knee and waited. When she finished changing into her California dress, I was waiting outside the closet on my knee with Engagement Ring Jr. and I asked her to marry me.

That sounds a little more romantic at the end right? Well it almost was. She got so excited that she forgot to say “yes” and kind of left me hanging for a few minutes while she danced around and cried a little before I asked “Soo… is that a yes?”. And it was!

The end result was the same, but it was the method of getting there that makes the story.

3
Apr

Next Generation Video

Posted by Terry on 04/03/2009 at around 1:28 PM

I’ve been putting a lot of thought into what the next big progression in online video will be… in terms of user generated content, it’s pretty clear that things are moving closer and closer to real time with UStream, Justin.tv and Qik.

But in terms of production video and movies, we’ve made little to no headway in a legal direction.  Hulu is a huge step for content providers, but for the internet community it was simply the next logical step.  But as has clearly been shown now, the ad model is extremely volatile and susceptible to downturns in the economy.  Granted, every business is, but advertising is one of the first things to come out of most companies’ budgets when profit falls.

So where do we go from here?  Torrenting is certainly popular, but since the industry has made it quite clear that is not an avenue they are willing to pursue, there have to be other legal directions we can go.

It is my opinion that the movie industry is going to go three directions for content delivery in the not too distant future, each one catering to a different market. So, without further ado:

1. Mail based delivery – These are the Netflix-esque companies who will do physical delivery, but it will be coordinated through online inventories as opposed to brick and mortar shops.  Netflix is an amazing service, but there is a level of rapport that needs to be built before people will be satisfied using this as an option.  However, this is the next logical step for those used to brick and mortar stores.

2. Set top boxes – The Apple TV and Boxee’s of the world are making quite a bit of headway here, but they don’t go far enough.  Now, given, this is due largely to the fact that most households do not have the bandwidth to do total streaming video, but we’re getting there.  This is where we really need to get the content providers on board.  And that won’t be easy because as with the recent Boxee fiasco, content providers are not yet ready to have their digital/internet content appear on televisions.  Which leads me into my third option…

3. Totally digital content – This is the content that can be watched anywhere.  And it’s as simple as an AVI or MPEG file, but it needs to be readily downloadable and, more importantly, portable.  I should be able to download a movie to my computer, watch it there, put it on my iPod, keep watching at the gym, etc.  Essentially, what this boils down to is my ownership of what I purchased and that I can do whatever I want with it as long as I’m not giving or selling it to others.

The biggest problem is this: I am perfectly willing to go to the movies and see a really good movie (ie. the new X-Men Origins: Wolverine).  But if I don’t really want to see it in theatre, I should have other options of seeing it.  Maybe not right away, but when it currently comes out in a digital format like on a DVD, I should be able to open up my set top box or app on my computer and buy that same movie for a reasonably low cost (maybe $4.99 or $9.99).  Make it REALLY easy for me to get to, make it easy for me to pay for and ensure that I can download it as fast, if not faster than I can currently torrent that movie and you’ve got yourself a business.

And enough with the DRM… People will ALWAYS find a way to get it for free if they really don’t want to pay for it.  But if you can do it for a reasonable price, with faster delivery than torrenting, and make it easy for me to own that content then in my opinion, you’re going to get a majority of people willing to pay for that service.  The ultimate goal is to make it easier to use your service than for people to get it illegally.

If there are any movie studio execs/content providers reading this, send me an e-mail and we can chat a little more ;)

24
Mar

New Workout Schedule

Posted by Terry on 03/24/2009 at around 4:58 PM

Now that I’m doing Jeremy Wright’s new Twitter organized #10morepounds weight loss challenge, I needed to change the direction of my workout a bit.    I’ve been doing 5 days a week and will continue with that, however, I was previously doing 1/2 resistance and 1/2 cardio each day to both lose weight and try to add a little mass. 

Since my goal for the next 10 weeks has shifted primarily to losing weight, I’ve changed my workout and thought I’d share:

  • Day 1: Cardio – 20 minutes treadmill, 20 minutes bike, 10 minutes stairs
  • Day 2: Half and Half - Resistance (chest, upper back and shoulders) then cardio (20 minutes treadmill, 20 minutes bike)
  • Day 3: Cardio, repeat Day 1
  • Day 4: Half and Half – Resistance (biceps, triceps, lower back) then cardio (repeat cardio from Day 2)
  • Day 5: Cardio, repeat Day 1

You may notice a few things… first, I’m leaving leg muscles to the cardio since it’s almost always based around legs (I sometimes throw rowing in there instead of one of the exercises).  Second, my cardio levels are almost the same each day.  On cardio days I’m doing a much higher intensity than on half and half days.  Third, I’m not specifying any specific resistance workouts because there are so many of them and you need to find something you’re comfortable with.  There are a ton of good sites out there for resistance training guides and walk-throughs. 

My only suggestion is use free weights over machines.  Machines are very focused, which isn’t really what you want (unless you have an injury).  What you want is to be imperfect because you’re going to work a wider range of muscles burning more fat and getting a better overall workout.

This week, as per Jeremy’s recommendations, I’m also hoping to start eating grapefruit for breakfast and drinking a lot more water instead of iced tea (even if it is 0 calorie).  I’m also going to try to kick my Starbucks habit but that’ll be even harder than losing 10 pounds.

Hope this helps you in your endeavours if you’re following along!

17
Jan

Startup Idea #13: Internet in the Cloud

Posted by Terry on 01/17/2009 at around 12:32 PM

I’ve been reading A LOT of news lately about The Cloud.  Haven’t heard of it?  The Cloud is this revolutionary concept of all your data living on the internet in distributed services in services like S3, dropbox, etc.  From my understanding from recent articles and hype (which we all live and swear by, right?), it’s a fairly new concept propelled by Amazon and other companies to make it so you don’t have to store data on your own computer.  This concept has been applied to documents, e-mail, and even web sites!

So I thought: wouldn’t it be great if the whole internet lived in a distributed, cloud computing environment?  Where we no longer had to host our own websites on our own machines?  Could you imagine if we had the ability to host our websites on other people’s servers 10 years ago?  And add more servers by clicking a few buttons and then setting up a custom image, just like Amazon does today?  We would be so much farther ahead of the curve!

So welcome to Web 3.0: where you no longer host your own your documents, and eventually you may not even host your own websites.  And as more websites move to The Cloud it will be even easier for people to host them elsewhere and scale them, with just the click of a button and the installation and customization of your software image (EC2 in this case).  It’s a whole new world we live in, and I can’t wait until the entire internet lives in The Cloud.

/s

18
Dec

Startup Idea #12: Modeling in the Cloud

Posted by Terry on 12/18/2008 at around 3:07 PM

Sorry for the lack of ideas lately, I’ve been working hard to get another version of Jaxified out and haven’t really had any bulbs go off.  However, while lying in bed before I got up this morning, this gem came to me:

Product photos are tough, especially when they need to be modeled on a person or manikin.  I think this could fairly easily be moved into a cloud application.  Make a manikin model, and have the user upload a front/back to the t-shirt.  If you have a t-shirt model as well, you could simply texture it with the uploaded images and automatically get a rendered model wearing your shirt.

I’m sure this could easily be applied to other products, and would need to be in order to build a successful business, but the cost savings in a down economy like this could be huge if you sell it right.

As always, thanks for reading and feel free to leave feedback, additions, etc. in the comments.

25
Nov

Startup Idea #11: Serious Pay Per Action Advertising

Posted by Terry on 11/25/2008 at around 12:51 PM

This is the time for PPA advertising to come to the forefront, when people really want to see results for their advertising dollars.  Now AdSense has PPA, but I think it’s time for a good startup to come out with a dedicated PPA system that’s easy to use.

The difference between my idea and what’s out there now comes principally in the ease of use.  You could create a system to allow the user to actually navigate through their own site and track their actions.  It’s difficult, but doable.  Then, when users click an ad, they would also need to complete one of the actions on the account before the advertiser pays.  This would of course result in less actual completions, but advertisers would be willing to pay considerably more for actual results.

This is actually one of my more interesting posts for the reason that I’ve already built a system like this, but didn’t have the time to pursue it, nor do I now.  So if you’re really interested, let me know and I can get you into the system to try it out and we can work out a deal.  It’s written in PHP and uses MySQL on the backend (with S3 to store ad images).  There isn’t a publisher section but the ad display code is written.  There is also no payment system, but those are relatively easy to implement.

As always, thanks for reading.  If you’re interested, e-mail me at terry [at] icedteapowered [dot] com.

23
Nov

Startup Idea #10: Book to Text

Posted by Terry on 11/23/2008 at around 11:47 PM

Hello all!  I’ve been really busy with Jaxified trying to get things in order for our next version, and it’s coming along really well, but I apologize for the lack of updates.  Let me make it up to you with this doozy (sp?) of a good idea (so I think):

With the progression of OCR and scanning technology, it should be really easy to take a book, unbind it and scan it into a document (PDF likely).  But it’s still extremely complicated and moreover time consuming (especially using one of those handheld OCR readers for big books).

So the idea is simply that: Create a website that gives people a shipping address.  Have them create an “order” on the website and, on receipt of payment, give them a shipping label to print out complete with a barcode for tracking.  When you receive the book, you get the ISBN (this is important for later), unbind it, scan it in using some OCR technology and convert it into a PDF. 

Once this process is complete, you rebind the book and send it back.  You also e-mail the user a link to where they can download the PDF.  For assurance, you could also give them a preview of the scanned pages (select a few at random) for the user to review and accept before making the final payment.  Once you’ve got the book scanned in, every subsequent user who sends the same book can just get a copy of the same PDF to save time and money (but because the user already has the book, you’re not selling an electronic copy of it, you’re selling a scanning service).

I’m sure the legal issues surrounding this are gray, but for students and lots of others this would be a huge hit, especially with some good OCR technology that you could actually search through for text, etc.

If anyone has any thoughts, let me know; I’d be up to using this myself if someone did it.

As always, thanks for reading.

8
Nov

Startup Idea #9: Ads in Social Space

Posted by Terry on 11/08/2008 at around 6:23 PM

Back in the day I used to be good friend’s with a guy who ran PlanetFreeStuff.com which referred you to people to do things you do every day (check your credit, sign up for a credit card, etc).  In exchange you accumulated point you could use on Amazon.com.  Anyways, long story short, he got too busy, the site took up too much time and it got pulled offline.  Then about 2 years ago I took the site and built it up again.  It performed decently but was past it’s prime.  Offers were dead.

Now with the resurgence of social networking we have a chance to bring that back, but in a less annoying form.  Someone should build a site that allows people to add their Facebook, LinkedIn, MySpace, Twitter and other accounts and analyzes that user’s reach.  Based on that information, you could post links to advertise on the user’s profile (Facebook: “so and so” posted a link, Twitter would just be a post, etc.).  How much are advertisers willing to pay for that reach?

I imagine there’s a huge profit to be made there.

Thanks to Timoty Leung (Twitter, blog) for the inspiration through our discussions.

3
Nov

Startup Idea #8: (Fun) Health Calculator

Posted by Terry on 11/03/2008 at around 12:24 PM

This is kind of a fun idea I had a while back; it shows off my darker sense of humour…

There are a lot of reports out there that come out every day that say “x food is bad for you, causes cancer, etc.” and 6 months later you find out that, while bad for you, “x food [also] causes you to live up to 3 years longer on average.”.

So I propose a fun themed, user contributed list of all food reports and what they say the food does to you.  Users can vote a report up or down to validate it’s source and then when the average Joe (I really hate this name after the election season) comes along, they can input what they ate that day and then BAM: You tell them congratulations, based on what you’ve eaten you’ll have y number of cancers in x number of years, but you’ll live until this long! Enjoy!

Again, it’s a fun and quirky way to see what’s going on out there.  It could be complimented by some real daily food alerts and reports and paid for by advertising or subscriptions to the real alerts.  As usual, there are a lot of ways to monetize the user base when you have one.