Category Archives: Web Dev

MySQL Exclusive Row Relationships

This post will explore how to find exclusive row relationships — rows that may be grouped together by some non-unique id that identifies some kind of grouping of those rows. For example, let’s say that we are managing a team of players, and that each team has to be unique. In other words, players A and B form Team 1, but players A,B,C form Team 2. Searching for existing teams with players A and B should only return Team 1, searching for teams with players A,B,C should return only Team 2, and searching for B,C returns an empty set. How to do this in SQL?

Continue reading

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.

MySQL Triggers

I came across an interesting problem: I needed to create priorities for records in a database so that they would be able to be displayed in a particular order. Moreover, I needed to find a way to reorder the priorities on the fly. My first instinct was for each record to have its own priority (PRI) column. But what would happen on an insert, if, say, the newly inserted item’s priority is somewhere in the middle? I would have to reorder the list. My table looks like this:

Table TEST
ID VARCHAR(10)
PRI INT(5)

I have never used triggers before, but from what I understood, they would have been the perfect solution.

Continue reading

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