Pear not working with MAMP
Posted by Stuart in Zend Framework on September 9, 2011
When running the version of Pear that comes with MAP you may get the following:
Notice: unserialize(): Error at offset 267 of 1133 bytes in Config.php on line 1050
ERROR: The default config file is not a valid config file or is corrupted.
The solution is to delete the conf file, located here (path may vary slightly):
/Applications/MAMP/bin/php/php5.3.6/conf/pear.conf
That’s it.
Enable Safari Debug/Developer Menu in Windows
Posted by Stuart in Troubleshooting on August 25, 2011
In Safari 3: “D:\Program Files\Safari\Safari.exe” executable: /enableDebugMenu
In Safari 4: “D:\Program Files\Safari\Safari.exe” executable: /enableInternalDebugMenu
In Safari 5: Preferences -> Advanced -> Show Develop menu in menu bar
MacBook seem sluggish? Monitor page outs to see if you need more RAM
If your Mac is sluggish and unresponsive you are probably using all of your RAM. To check this examine the amount of paging out going on. You can do this from the command line with “sar”.
The sar command is used to sample and report various cumulative statistic counters maintained by the operating system. sar stands for “System Activity Reporter”.
Example:
sar -g 60 100
-g tells sar to monitor page outs.
60 means “check every 60 seconds”
100 means “do this for 100 minutes”
Sample output:
01:55:34 pgout/s
01:56:34 0.0
01:57:34 71.3
01:58:34 40.0
01:59:34 470.2
02:00:34 143.7
02:01:34 104.0
02:02:34 11.4
02:03:34 5.1
02:04:34 26.8
02:05:34 119.6
02:06:34 80.6
02:07:34 5.9
02:08:34 0.0
02:09:34 16.1
02:10:34 0.0
02:11:34 0.0
That output tells me that I’m paging a large amount of memory periodically and lets me know that I would definitely benefit from a RAM upgrade.
Access GET Params via Javascript
function $_GET(q,s) {
s = (s) ? s : window.location.search;
var re = new RegExp('&'+q+'=([^&]*)','i');
return (s=s.replace(/^\?/,'&').match(re)) ? s=s[1] : s='';
}
// Grab the GET param
var someparam = $_GET('someparam');
IE6 – Modal Window stuck behind background
So with some modal windows (like with jQuery Modal or dialog) they can appear “greyed out” and unclickable. This is because the modal window gets placed behind the overlay. The reason for this is related to the containers that the modal is in. To get around it, move the modal outside of all containers except the body. You can do it physically or, if you don’t have access to all of the code, via javascript.
Here is a jQuery based js snippet to do just this with a jqmodal window:
$('body').append($('#someModal'));
This will grab the item with the id of someModal and append it to the body, moving it outside the flow of other containers on the page.
Redirect Subversion to Standard Output for Troubleshooting
$cmd = '/usr/bin/svn list https://someserver.com:8443/svn/proj/trunk/ --username "admin" --password "fobdg$f_Aa" 2>&1';
exec($cmd, $output);
$output = implode("\n", $output) . "\n";
echo $output;
?>
PHP Debugging in Chrome with ChromePHP
Posted by Stuart in Zend Framework on January 10, 2011
Easy PHP console logging in Chrome (similar to FirePHP in Firefox).
- Download the ChromePHP Extension (you will click this extension “on” when you want to use ChromePHP).
- Download the ChromePHP class itself and stick it in your path (example:
/Applications/MAMP/bin/php5.3/lib/php/ChromePhp.php). - (a most critical step that is not made clear in the ChromePHP install instructions) Create a place for ChromePHP to store log files:
mkdir /Applications/MAMP/htdocs/chromephplogs - Start logging:
include 'ChromePhp.php';
ChromePhp::useFile('/Applications/MAMP/htdocs/chromephplogs', '/chromephplogs');
ChromePhp::log('hello world');
ChromePhp::log($_SERVER);// using labels
foreach ($_SERVER as $key => $value) {
ChromePhp::log($key, $value);
}// warnings and errors
ChromePhp::warn('this is a warning');
ChromePhp::error('this is an error');
Notice the use of ChromePhp::useFile() in the above code… this is critical as ChromePhp simply will not work correctly without it. useFile() accepts 2 arguments… here is the code itself:
/**
* this will allow you to specify a path on disk and a uri to access a static file that can store json
*
* this allows you to log data that is more than 4k
*
* @param string path to directory on disk to keep log files
* @param string url path to url to access the files
*/
public static function useFile($path, $url)
{
$logger = self::getInstance();
$logger->addSetting(self::LOG_PATH, rtrim($path, '/'));
$logger->addSetting(self::URL_PATH, rtrim($url, '/'));
}
Open a file in the Browser, from within Vim
An example of opening a file you are working on in Vim right into your default browser:
:!open http://localhost:8888/foo/bar.js
I believe in Windows you would need to do:
:!start http://localhost:8888/foo/bar.js
RegEx to Strip HTML Comments
The title is longer than the code!
<!--(.|\s)*?-->
That is imperfect but works with the comments I need to strip. Best thing about it is that it handles line endings so multiline comments don’t confuse it.
Using wget with cron to hit a page
*/5 * * * * /usr/bin/wget -q -O /dev/null http://12.120.186.8/index/parsexml
*/5 = every 5 minutes
* = every hour
* = every day
* = every month
* = every day of the week
Cause the program wget (located at /usr/bin/wget) to quietly (-q) activate sending any output (-O) to nowhere (/dev/null) oh, and we are accessing the url http://12.120.186.8/index/parsexml





