Monday, July 17, 2006

javascript function default value for variable


function foo(a, b, c) {
var b = (b == null) ? "default" : b;
var c = (c == null) ? 100 : c;
...
}

Saturday, May 06, 2006

vi indent multiple lines

use the shift operator: >>

enter the following to shift (right) the next 10 lines by the set shiftwidth:


:10>>


you can set the shiftwidth to 2 spaces like this:


:set sw=2

Thursday, April 13, 2006

controlled 'crements

Have you ever wanted to create a function that would increment an integer position by a certain number as long as it didn't go over a max or under a minimum?

Here's a function I wrote recently that does this:


/**
* Increment or decrement a given position by a change amount within rules
*
* @author Richard AT d2p.us
* @param int $position
* @param int $change_by
* @param int $max
* @param int $min
* @param string $incOrDec
*/
function incrementDecrement(&$position, $change_by, $max, $min = 1, $incOrDec = "inc"){
if ($incOrDec == "inc"){
if (($position + $change_by ) <= $max){
$position = $position + $change_by;
}else {
$position = $max;
}
}else {
if (($position - $change_by ) >= $min){
$position = $position - $change_by;
}else{
$position = $min;
}
}
}


Of course, this doesn't return anything, I have it changing the original position because I pass by reference, but change this to suite you.

no libphp4.so after make install

So you've run ./configure with your favorite parameters, done 'make', and then under root done a 'make install' but libphp4.so doesn't get updated (for Apache).

You might be missing this parameter: --with-apxs OR --with-apxs2, depending on your Apache version.

run 'make clean dist' and then start over again, this time with these parameters added on. Then when you run 'sudo make install', you should see a line like this in the output:

cp libs/libphp4.so /usr/libexec/httpd/libphp4.so

Check ./configure --help for more.

Thursday, March 30, 2006

Jerry Taylor from Tuttle, OK...

look out! CentOS is comin' to get you! Better call the FBI!

The Register: article 1
The Register: article 2
The Register: article 3
(strongly recommend reading the comments on following pages)

"Oklahoma is not as much a third world country as it seems. There are many of us who do in fact posess opposable thumbs, can walk on two legs, and have the capacity to dress ourselves and form simple complete sentences; though some of the more vocal representatives of this state would lead you to believe otherwise.

I have nothing else to offer but my most sincere apologies for the rampant idiocy displayed in recent past, and a promise of hope that the younger generation of Oklahomans emerging into industry today do not reflect quite so much a lack of Clue as displayed by the exchange between the City Manager of Tuttle and CentOS." - Reid Linnemann (from Oklahoma)

Wednesday, February 01, 2006

Down with frameworks

http://discuss.joelonsoftware.com/default.asp?joel.3.219431.12

To this I have only to add...

"Things should be made as simple as possible, and no simpler." - Albert Einstein

Wednesday, January 04, 2006

Hook'em Aggies

Tuesday, December 20, 2005

PHP on Apache and Pear not using same version of PHP

There are so many ways you get this error, usually masked as something else.

What happens is, you compile and install a new version of PHP. It installs for you the mod_php or libphp4.so file so that apache can use it... and as long as you have a php.ini, it does. A problem scenario might be when you attempt to use Pear to install something, in my case Image_Color, and it says it 'gd' is not enabled in PHP -- despite that I just enabled it, and my phpinfo says it's in there.

Most sites, if I was lucky enough to find any, suggested that it was using the wrong php.ini. But pear uses (probably) /usr/bin/php.ini

What probably happened was:

1. you didn't specify a '--bindir=/usr/bin' to the new php

2. you didn't copy the new php you created when you compiled php to wherever it's looking for it (/usr/bin/)

If you do a search for 'php' you'll get probably way more listings than you hope. But if you look for phpize, you might find the directory where the new php files reside. run this:

% find / -name phpize
OR
% locate phpize

You can locate as long as you're locate.updatedb has been run since you configured php.

For me, it was in /usr/local/bin. I copied php* to /usr/bin and viola.

Hope this helps.