web development war stories from the frontlines to the backend

The Clickable SPAN

tags: , ,

It seems like the standard pattern for calling a JavaScript function when text is clicked is the following: <a href="#" onclick="callSomeJSFunction();">Click Me</a> The problem I have often encountered is that clicking the link causes the browser to jump to the top of the page if you have scrolled at all. Users do not like unexpected [...]

I recently purchased a VPS from SliceHost.com. After ruling out a shared host and deciding on a VPS setup, SliceHost seemed to offer the most for my money. My initial setup is the 256slice, which offers 256mb RAM, 10GB of storage, and 100GB of bandwidth for $20 a month. Being able to build my own [...]

Spending most of the day optimizing a page that (when I began) took 8.6 seconds to execute. Using some basic profiling techniques helped tremendously in not wasting my time and efforts attempting to optimize a portion of code that won’t yield appreciable gains. The time intensive code for applications I write generally fall into either [...]

Had to quickly get the execution time of certain segments of code so I whipped up this basic profiling class below. Usage would go something like: <?php $profiler = new cProfiler; $profiler->start(); // … long block of code … $et = $profiler->end(); echo ‘longBlock et = ‘.$et.’<br>’; ?> Class listing cProfiler.php: <?php class cProfiler { [...]

PHP Array to String

tags: ,

The function below facilitates the process of converting an array to a string. Very useful for building SQL insert queries with arrays of data. <?php function array2str($array, $pre = ”, $pad = ”, $sep = ‘, ‘) { $str = ”; if(is_array($array)) { if(count($array)) { foreach($array as $v) { $str .= $pre.$v.$pad.$sep; } $str = [...]

The following line splits a string by any combination of whitespace (including newlines) and commas: <?php $splitArray = preg_split("/[\s,]+/", $input); ?>

PHP Document Root Trick

tags: ,

Create and place this file in your document root, include it in all other files to easily have access to the directory your site is located without using clumsy and unreliable $_SERVER or $_ENV entries. _require.php: <?php $oldCwd = getcwd(); chdir(dirname(__FILE__)); define(‘SITE_DOCROOT’, getcwd()); chdir($oldCwd); ?>

Get It Done

tags: , , , ,

Today’s comic at xkcd was entitled “Real Programmers”, which was hysterical. It got me thinking about a lot of blogs where flame wars erupt because fanboys think their current way of doing things is best, and yours is crap. Everyone has an opinion about which language/framework/web server/OS is The Best. It’s fine to have such [...]

« Previous Page  Next Entries »

Recent Posts

Categories

Archives