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 [...]
04 Feb
by: Eric in Infrastructure, PHP, Ruby on Rails
tags: apache, centos, memcached, mysql, php, rails, ruby, slicehost
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 [...]
04 Feb
by: Matt in Development
tags: optimizing, php, profiling, sql
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 [...]
04 Feb
by: Matt in Development, PHP
tags: execution time, microtime, php, profiling
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 { [...]
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 = [...]
04 Feb
by: Matt in Development, PHP
tags: explode, php, preg_split, regex, regular expression, split, whitespace
The following line splits a string by any combination of whitespace (including newlines) and commas: <?php $splitArray = preg_split("/[\s,]+/", $input); ?>
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); ?>
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 [...]
WP Cumulus Flash tag cloud by Roy Tanck and Luke Morton requires Flash Player 9 or better.