Category Archives: PHP

Stack from Queues

Ran across a question on how to implement a stack by only using queues on SO, so I decided to give it a go in Java and PHP. It’s actually pretty straight forward:

  • Initialize two queues.
  • On every push operation, if both queues are empty, add to the first queue.
  • If one of the queues is full (one will always be empty), pop off all the elements from the full queue and add them to the empty queue in the same order (as they were popped). This guarantees the full queue will always be sorted like a stack, so when a pop occurs, it is popped in the “LIFO” order, not “FIFO” order.

Code after the break. Continue reading

OS X .htaccess

For some reason, I could not get .htaccess files to work on my system for the longest time. I’ve since upgraded to Leopard, and I eventually just gave up on it (I could do that, since I’m only running a development environment).

Anyway, the solution depends on which version you’re running:

For Tiger, edit /private/etc/httpd.conf AND /private/etc/users/username.conf for the correct directives

For Leopard, edit just /private/etc/apache2/httpd.conf

Days of pulling hair solved because I was looking in the wrong places.

Update: because of the upgrade from Tiger to Leopard, ALL of the above directories were present on my system, but only /private/etc/apache2 was being used.  This is because Leopard uses apache2 and Tiger uses apache 1.3.  Obviously, apache2 uses /private/etc/apache2 instead of /private/etc/httpd.  If you had installed Leopard from scratch, this would not be a problem.

Installing PHP on Mac OS X

I’m back from my surgery. Thankfully, the laptop from my new employer arrived just in time to keep me occupied during recovery. It’s a 17″ MacBook Pro with the 1920×1200 resolution screen (Sah-weet!). 4 GB of RAM. I must say, this is probably the only machine that could have EVER switched me to being a Mac user. I will write a comprehensive review of what (still) bothers the hell out of me (after two weeks of use) in OS X, and what I find really cool (hint: the Unix prompt is #1). Anyway, I digress…

I just had the pleasure of installing PHP on Mac OS X. It took me about 3 hours to compile PHP 5.2.4 with MySQL, GD, and XML DOM API. By 3 hours, I mean, to find all the libraries, download them, compile them and install. I know OS X ships with PHP 4, but c’mon — PHP 4 will be discontinued by the end of the year.
Continue reading