AWG Blogs

Saturday, October 17, 2009

Change Directory with String Replacement

Found out through experimentation how to change directories in the bash shell using sed string replacement. I need a quick way to switch from production to staging sites which have the same path but for the user home directory.

First I tried:

echo `pwd` | echo `sed -e 's/production/staging/' ` | cd


That didn't work.

Then I tried:

cd $(echo `pwd` | echo `sed -e 's/production/staging/' ` )


That worked. Go figure...

Sunday, October 4, 2009

Add Hyperlink using jQuery

You can test this out in Firebug. Say you have a td element, <td id="foo" />,
you can add a link to this using jQuery:
jQuery("<a />").attr("href", "http://yahoo.com").appendTo("#foo").text("link to yahoo").after("<br />");

Monday, September 28, 2009

WSS 2.0 to WSS 3.0 Migration

I had a WSS 2.0 site (no custom parts) that I needed to upgrade AND migrate to another server. So I pretty much followed the advice on http://geekswithblogs.net/redwards/archive/2007/10/26/116365.aspx .

The above article is unclear about how the DB was transferred however, so had to wing it. Basically what I ended up doing was copying the .mdf and .ldf files of the WSS 2.0 content DB over to the Data folder of a SQL Express 2005 server --NOT the WSS 3.0 embedded DB (I tried that, but it gave me errors when I ran stsadm).

Note, after the DB was added and all set up in the Central Administration, I had to change the site collection administrator. The migrated site still had the OldServer\Administrator as the Primary site collection administrator. Other than that pretty seamless...

Sunday, September 20, 2009

Getting memcached to Run at Startup on Ubuntu

For some reason memcached would start and then die shortly after on reboot. This is on an Ubuntu 8.04 with updated packages for Apache2, PHP5, and memcached installed through apt-get.

The only way I could fix the problem was to remove memcached from the rc scripts:

update-rc.d -f memcached remove


Then add the following line to /etc/rc.local:

/usr/bin/memcached -d -p 11211 -u nobody -l 127.0.0.1 -m 64


I'm sure this will have to be adjusted if I ever need more memcached processes or if I need the PID file. Speaking of which, I suspect that the canned scripts that came with this memcached 3.0.1 from Ubuntu are too convoluted with regard to the PIDs, which already have problems of their own.

This bug report set me in the right direction.

Monday, August 24, 2009

Eclipse Simpletest plug-in Path errors

I struggled with this one until through experimentation I found out the problem. I have the Simpletest plug-in 0.2.5 for Eclipse.

I had

require_once dirname(__FILE__) . '\MyClass.php';
class test extends UnitTestCase {
function test_pass(){
$tc = new MyClass();
$boolean = $tc->my_method() == "hello";
$this->assertFalse($boolean);
}
}

But when running, I kept getting:

PHP Fatal error: Class 'MyClass' not found in ...test.php...[line number]

I finally found out through trial and error that to fix this fatal error I simply needed to replace the opening short tag with the full php tag <?php . That means I'm going to need to do this to all my class files. Might as well make that a best practice from now on.

Sunday, August 23, 2009

IIS 7 and Permissions Quirks

I just enabled IIS 7 on Windows Vista SP 2 and enable FastCGI. I create a new website and point it to a folder under my Documents folder with a test.php file. I open the page http://localhost/test.php in IE and get:

HTTP Error 401.3 - Unauthorized
You do not have permission to view this directory or page because of the access control list (ACL) configuration or encryption settings for this resource on the Web server.


Ok, so I add IIS_IUSRS to folder ACL, but that doesn't fix it. I then added the Users group to the ACL and that fixes it. Strange indeed because my user account is already in the ACL and I'm in the Administrators group, which is also already in the site folder ACL. Now I just have to wonder whether this is a Windows bug, or whether there's some other user under the Users group that's being impersonated by some process. Hmmmmm.

Sunday, August 9, 2009

Use encodeURIComponent in AJAX

In the XMLHttpRequest "send" method it's best to encode the parameters using the Javascript function encodeURIComponent as opposed to escape or encodeURI. For details why, see
http://xkr.us/articles/javascript/encode-compare/ .

I learned this by researching why the solution at http://www.captain.at/howto-ajax-form-post-request.php did not work for me. For example, if I use escape, the '+' symbol converts to a space in the database; and if I use encodeURI, any '&' will cause all subsequent characters to not make it into the database -- because those characters aren't converted with the other two Javascript methods.