Showing posts with label php. Show all posts
Showing posts with label php. Show all posts

Thursday, December 9, 2010

My Favorite Scripting/Programming Languages

Just random blabbering stuff.  These are ranked in order of "most fun" to "least fun" to work with (entirely subjective of course)…

  1. KiXtart 4.6x
  2. PHP 5.x
  3. VBScript / ASP
  4. SQL / T-SQL
  5. Wise Script 8
  6. Javascript
  7. Visual LISP / AutoLISP
  8. BAT / CMD
  9. PowerShell v2
  10. VB.NET

Ordered by what I work with most often:

  1. BAT / CMD
  2. VBScript / ASP
  3. Wise Script 8
  4. SQL / T-SQL
  5. Javascript
  6. PHP 5.x (sad, very sad for me)
  7. PowerShell v2 (this might change soon)
  8. KiXtart 4.6x (oh, the agony!)
  9. Visual LISP / AutoLISP (almost never)
  10. VB.NET (almost never)

Monday, October 25, 2010

Detect Windows 7 Users from Web Site

I had to tinker with this for two separate projects, so hopefully it’s of use to someone else.  Not really rocket science, but then again: web pages are never rocket science are they?

PHP code

function isWin7() {
if (strpos($_SERVER['HTTP_USER_AGENT'], 'Windows NT 6.1') == true) {
return true;
}
return false;
}

ASP code

Function isWin7() {
If InStr(Request.ServerVariables("HTTP_USER_AGENT"),"Windows NT 6.1") > 0 Then
isWin7 = True
End If
End Function

Sunday, October 17, 2010

Buy vs Build: The Devils You Know

Author’s note: I’m not sure if this should be a longer or shorter “post” (“article”?) because the core intent could either be stated as briefly as a tweet or as long as a book.  I’m sure there could be a full semester college course on this subject, but I’m not that good.  I’m throwing a dart at the best guess board to see how it works in the end. This article emphasizes intranet portal projects, but it applies to anything that incurs a choice between buying versus building your own.  I hope it helps (or at least entertains) – Enjoy!

One of my main interests, and sources of work, is herding cats.  Actually it’s information aggregation, or process automation. Most often this boils down to using the “web” as the hub or focal point for tying it all together.  Intranets are my biggest customer.  The discussion usually circles around concerns over costs and time when choosing between a retail or “COTS” solution versus a “custom” developed solution. It usually starts with a short discussion that goes like this:

Customer: “We really need to pull our information together and link things up.  We have separate databases for HR, work scheduling, customer lists, project status, Active Directory and security roles, financial projections, contract bid data mining, compensation modeling, and so on.  We’d like to connect all those things as well as add some sort of employee “self-service” features.  Should we buy something like SharePoint or have you build it for us from scratch?”

Me: “It depends” (don’t you LOVE that classic consultant responses!)

Seriously though, it really does depend.  I have a matrix of criteria to help evaluate which is the “way to go” towards arriving at the desired result.  But first, the cheesy diagram below illustrates that no matter which “way you go” you’re likely going to incur time and cost with making it “fit” into your environment, and “fit” in between what you currently have and you wish to have.  The question is then which direction incurs the least burden.

cots_vs_custom

So, just what exactly is this “matrix of criteria”?

Criteria

COTS

Custom

Budget “hard limit”

?

?

In-House Talent (developers, admins)

?

?

Features Gap

?

?

Interfaces

?

?

Pretty simple, right?  Well, not really.  Each of these criteria potentially involves a ton of digression and drilling down.  How much so depends upon the scale of the business, the scope and scale of the “things” being integrated, and tangible and intangible constraints.

Whoa!  (record scratch sound here…) - Did you just say “tangible and INtangible constraints”?!  WTF?

Tangible constraints are pretty familiar to us all: budgets, time, staffing, physical and logical space, and so on.  Intangible constraints are usually human-based: emotional aspects, protectiveness, skill levels and expertise, and secondary distractions like, oh, for example: Joe is on the team to discuss this whole project.  But Joe manages the HR database systems.  He was forced to sit on this team by his boss, whom he doesn’t like, but who insists that it might be time to consider moving the HR system into something more accessible and flexible for interfacing with other systems.  Joe sees this as a threat to his control, and thereby a threat to his existence and job security.

Yeah.  Something like that.

If you’ve ever sat in a planning meeting that involved discussion about changing something major, or something that’s been relied upon for years and years, you absolutely KNOW what I’m talking about.  It’s more prevalent in larger corporate environments than within small businesses, but it can show its ugly head anywhere really. I will go ahead and say this, even if it causes some of you to shake your head in disagreement:

The single biggest obstacle, and cost inflation factor, in any technology-oriented project is human emotion.

Yep.  If we just acted like logical robots and implemented technology without pausing to argue over rationale and subjective value, we could get those tasks done in less than half the time it typically requires.

But let’s get back to the focus of this post, which is how to rationalize a “buy versus build” decision, primarily with respect to intranet portal projects…

You’re probably thinking that I usually knee-jerk to making a “build it” recommendation.  You would be correct.  But if you assume that my decision scoring is something like 10:1, you’d be very wrong.  My average is roughly 60:40.  That’s not because I’m trying to capture new work and income, no.  It’s because it just happens to be a function of the nature of the evaluation of criteria within the clients environments I deal with most often.

Some of the typical factors that lead me to recommend a COTS solution however are (or should be) pretty obvious:

  • Do they already have complimentary systems in place that would make it easier to add the propose intranet solution?  For example, all data is currently in a single (or clustered) database, or other information management systems by the same vendor have been in place for a long time.  It’s usually best to add a matching brick to an existing wall, than to tear down the wall to change the brick color.
  • Do they have existing development and admin talent to match the proposed solution?  Do they have .NET and SQL developers, or do they have Oracle and PHP developers?  Will they be available for this project full-time or part-time?
  • Is the customer list of desired features an exact match with out-of-box features of the product?  Is it “close”?  How close?  How many of the desired features are typically the most difficult to develop from scratch, but which are already provided by the proposed COTS product?
  • Are there existing instances of the proposed product in use elsewhere in the company?

When these factors evaluate in one direction, I usually recommend going with the COTS solution and then work to help them plan for, and implement it in the test and production environments.  SharePoint, Drupal, Joomla, etc. are all good products and very much tested and proven in their own rite.

But when evaluation of the criteria leans the other way, it then opens up another discussion and round of evaluation to vett (God, I hate the word “vett”! But I have to use it here because I have a gun to my head) the issues related to custom development:

  • Time and Budget constraints
  • Degree of Access to interface resources (cooperation)
  • Variety of interface technologies (spread)
  • Hand-off Issues

Most of these should be easy to understand, but I’m going to dig a little deeper into them anyway (why not?).

Cooperation is huge.  If the team, or the delegated staff you’re going to be working with, are going to open up and provide access and information to help you interface with their systems and data stores, great.  That makes life so much better.  But when they circle the wagons to protect their turf, or simply don’t put forth any real effort to keep the ball moving, then it becomes a huge detriment.  This falls into a semi-intangible aspect of the project scoping and assessment.  Ultimately this boils down to TRUST.  You have to trust them and they have to trust you.  You can’t scope or predict anything that’s human-oriented without familiarity and that is based on trust.

Variety of technologies, or “spread”, represents more of a metric nature.  If all of the data stores share a common technology, like Windows or Linux servers, MS SQL Server, Oracle, or XML structure, or whatever, then it helps you narrow your ingredients for baking the solution.  If there are a dozen systems you need to tie into which each does their own platform, vendor and technology dance, you’re going to have a tougher time herding the cats.  Even if all of those systems support an XML-based interface, there’s going to be additional work with planning, testing, and validating each custom interface, separate from building the actual end state.

Hand-off issues involve how the solution will be managed and maintained going forward.  You know: after you complete the delivery.  Make sure this is spelled out!  So many times I’ve walked into a project proposal meeting and this is never mentioned.  Who is going to keep this machine running after you deliver it?  You?  Them?  A mix of both you and them?  If it’s a mix, that’s the most important to spell out in terms of what, when and why.  If they expect YOU to keep it running, what is your backup plan?  Are you the only person?  That’s great if you only care about a paycheck. It’s extremely bad for the customer if you drop dead or have surgery, as well as bad for you for instilling TRUST in the eyes of your clients.  I always try to shift the role to them and offer as much knowledge transfer as possible.  This is the only possible and practical “win-win” situation.

Conclusion

If you were expecting me to stand up and shout “always do this!” or “always do that!”, I’m sorry to let you down.  But this falls into my firm belief that most knee-jerk recommendations are bullshit.  There is no “one size fits all” in the business world.  Because (and this repeats another mantra of mine): a business is a name for a group of people.  People are not stamped from a machine.  People vary.  Business varies.  Problems vary.  Solutions vary.  Be adaptable and listen.  Take notes and analyze them before proposing a solution or recommendation.  Don’t be in a rush to give an answer in the same meeting where the questions were asked.  No worthy business will hate you for saying you’ll get back to them after reviewing the facts and factors.

Saturday, September 19, 2009

Making ASP “Die” like PHP

How clever was that title!  Not clever.  I know.  Oh well.

So, PHP has the age-old “die()” function to stop processing and puke up a message in the process.  Great for most general needs.  When you want the page to crash-out gracefully and say something intuitive and elegant to the user, like “hey, you fucked up, you idiot!”  Just kidding.  ASP doesn’t really have an identical function, but it does have the Response.End object method.  So you can make a really simple function (ok, Sub) to do pretty much the same thing.

Sub Die(strMessage)
If strMessage = "" Then
strMessage = "processing stopped."
End If
Response.Write "<span style="color: red; font-weight: bold">" & strMessage & "</span>"
Response.End
End Sub

' example of usage
If Session("LoggedOn") <> "TRUE" Then
Die "logon failure!"
End If


When would you want to use this?  One good example is on pages where you want to ensure some global condition exists before rendering the page.  A good example of that would be checking to see if the user is “logged in” or “validated” or a quantity in a form was selected, or whatever.  Maybe you want to ensure a page is only called from a specific other page, and not directly.  You can pass a hidden form object or querystring to shake hands, but if a sneaky asswipe user decides to shortcircuit your site by calling the second page directly, you can check for that form/querystring input and gracefully crash-out if it’s not provided.  I’m sure if you smoke enough of something you can think of other possible uses.  But this hopefully helps you in some random remote way.

Thursday, September 17, 2009

ASP/PHP: Make a List of U.S. State Abbreviations

I’ll be digging through my old projects to find anything interesting enough to bore you to absolute death (or gouge your own eyes out with a fork in order to stop that burning feeling experienced from looking at shlock like this).  Here’s an example for populating an HTML [select] form object list (aka “listbox” or “drop-down list”, etc.) with 2-character abbreviations for U.S. states.  Enjoy…

PHP version:

function StateCodes($default) {
$delim = ',';
$clist = "AL,AK,AS,AZ,AR,CA,CO,CT,DC,DE,FL,GA,HI,IA,ID,IL,IN,"
. "KS,KY,LA,MA,MD,ME,MI,MN,MO,MS,MT,NC,ND,NE,NH,NJ,NM,NY,"
. "OH,OK,OR,PA,RI,SC,SD,TN,TX,UT,VA,VT,WA,WI,WV,WY";
$tok = strtok($clist, $delim);
while ($tok != false) {
if ($default == $tok) {
echo "\n";
}
else {
echo "\n";
}
$tok = strtok($delim);
}
}


ASP version:



Sub StatesList(default)
Dim lst, x
lst = "AL,AK,AZ,AR,CA,CO,CT,DE,DC,FL," & _
"GA,HI,ID,IL,IN,IA,KS,KY,LA,ME," & _
"MD,MA,MI,MN,MS,MO,MT,NE,NV,NH," & _
"NJ,NM,NY,NC,ND,OH,OK,OR,PA,RI," & _
"SC,SD,TN,TX,UT,VT,VA,WA,WV,WI,WY"
If default = "" Then
Response.Write "" & vbCRLF
End If
For each x in Split(lst, ",")
If Ucase(x) = Ucase(default) Then
Response.Write "" & vbCRLF
Else
Response.Write "" & vbCRLF
End If
Next
End Sub

PHP: Functions For Giving Birth

These are two functions I found in my archives that I had written several years ago and felt like posting.  I’m sure there are others out on the Internet, maybe even better ones.  Who cares.  Here goes…


function ZodiacSign($date){
list($year,$month,$day)=explode("-",$date);
if (($month==1 && $day>20)||($month==2 && $day<20)) {
return "Aquarius";
} else if (($month==2 && $day>18 )||($month==3 && $day<21)) {
return "Pisces";
} else if (($month==3 && $day>20)||($month==4 && $day<21)) {
return "Aries";
} else if (($month==4 && $day>20)||($month==5 && $day<22)) {
return "Taurus";
} else if (($month==5 && $day>21)||($month==6 && $day<22)) {
return "Gemini";
} else if (($month==6 && $day>21)||($month==7 && $day<24)) {
return "Cancer";
} else if (($month==7 && $day>23)||($month==8 && $day<24)) {
return "Leo";
} else if (($month==8 && $day>23)||($month==9 && $day<24)) {
return "Virgo";
} else if (($month==9 && $day>23)||($month==10 && $day<24)) {
return "Libra";
} else if (($month==10 && $day>23)||($month==11 && $day<23)) {
return "Scorpio";
} else if (($month==11 && $day>22)||($month==12 && $day<23)) {
return "Sagittarius";
} else if (($month==12 && $day>22)||($month==1 && $day<21)) {
return "Capricorn";
}
}

function BirthStone($iMonth) {
switch($iMonth) {
case 1:
return "Garnet";
case 2:
return "Amethyst";
case 3:
return "Aquamarine";
case 4:
return "Diamond";
case 5:
return "Emerald";
case 6:
return "Pearl";
case 7:
return "Ruby";
case 8:
return "Peridot";
case 9:
return "Sapphire";
case 10:
return "Opal";
case 11:
return "Topaz";
case 12:
return "Turquoise";
}
}

// examples:
$my_birth_stone = BirthStone(3);

$my_birth_sign = ZodiacSign('1955-03-31');

Thursday, November 20, 2008

A Simple Finale

I closed out my last web project for my soon-to-be-defunct company "Harmonixx".  The last piece of the last project was to finish up a PHP function module that queries a MySQL table for matching records and generates a rotating ad panel component using javascript.  Most ad rotation code is simple.  Most database code is simple also.  But this particular page was more challenging due to some unusual constraints and requirements for the customer.  In any case, it was a nice finishing touch to a project and a business.  It'll be nice to go back to writing code for fun instead of being a job.

Sunday, December 30, 2007

And They Wonder Why Linux is so Appealing?

I got all excited to see if my PHP web apps would port over to Windows Server 2008 running on IIS7 outfitted with FastCGI. It sure sounded promising. I downloaded PHP 5.2.5 for Windows. I downloaded the QDIG PHP web app also. Followed the instructions here to the letter.

Then I tried it. And I tried it again. And again. And one more time. Then once more after that. Each on a different WS08 virtual machine, clean setup. I ran through a ba-zillion troubleshooting and diagnostic tips and suggestions and none of them were successful.

Here's all I could manage to produce...





I created a vanilla Ubuntu 7.10 web server, with Apache and PHP and copied in my "helloworld.php" and it just works. None of this stupid configuration crap.

So, maybe you're reading this from the comfortable office of your ASP.NET development empire and scoffing at this with some smirky comment like "It's Windows dumbass, nobody uses PHP on Windows". Exactly my point. Then you might follow up with "Everybody uses ASP or ASP.NET anyway", and I would fall out of my chair and wet myself laughing.

I have developed ASP and ASP.NET web apps for almost 10 years. I only recently embarked on learning LAMP (aka Linux+Apache+MySQL+PHP) and have found it to be not only extremely powerful and productive, but FUN. Yes. Fun! I forgot how fun it was to write code and make things happen. So much of the crap layered on IDE products to enforce CMMI processes, change management, workflows, team-centered collaboration, yada yada yada, has bled the fun out of web development to the point where it's become a dreaded chore in most cases.

I know I'm not alone. I have had discussions with so many developers that complain that the individual programmer role has been lost in the shuffle. Everything is assuming we're all building the next eBay. A thousand faceless coders with identical face piercings and tatoos, drinking the same over-caffeinated beverage and bouncing our heads to whatever is blasting in our ears from our iPods or whatever.

Don't get me wrong. I absolutely LOVE what Microsoft has done with Windows Server 2008. It is truly a wonderful product. It just makes sense. Everywhere you poke around inside of it, you will nod in satisfaction that they finally got it right (or at least, pretty damn close).

So I figured I might be able to bring the joy I've found with PHP on Linux back to the Windows world and marry the best of both worlds. Sort of like match-making your best friends and watching them get married; sitting back with a smile at having made something good happen for a change. Not so. Not yet anyway. I put the two of them in a room, dimmed the light, put on some Barry White music and handed them each a stiff drink. The result was a nasty error message and complete failure.

The fun is out there still. I will find it.