How to kill a process by port in Mac OS

Sometimes I leave processes running which take up ports on my local machine (e.g., Redis server). I won’t be able to use the port until it’s freed up, but it’s sometimes a chore to figure out how to kill the process by port.

I found the following snippet super useful to kill a process by port in Mac OS:

Just replace the [port] above with the actual numbered port (e.g., 6379).

How to install the PHP MongoDB driver on Amazon EC2

I recently found myself with the need to connect to a Mongo DB instance from a PHP application running on Amazon EC2.  The PHP docs led me to this MongoDB extension, which seemed to be a good fit for my needs.  Still, the matter of installation was a little bit less clear, considering that the EC2 instance was pretty barebones and lacked a fair number of the “standard” libraries that would enable this single line installation to work.

After a bit of finagling, I got everything to work via the steps I’ve outlined below.

Continue reading…

How to Quickly Add Indices to Large MySQL Tables

Whenever a MySQL query contains a WHERE conditional, the database server must find all the matching rows before it can execute any operations.  In order to optimize this matching, a database administrator might define an index on any columns he or she knows will be used more frequently in WHERE conditions.

As an analogy, imagine if you had an unorganized stack of business cards, and someone asked you to find Jon Smith’s telephone number.  You might have to look through every single business card in order to find Jon Smith, because he could be anywhere in the stack.  On the other hand, if you sorted the cards in alphabetical order by last name, you would be able to jump much more quickly to where Jon Smith might be found.  Furthermore, every time you receive a new business card, you could quickly insert it into its proper place (based on last name) and be sure that future lookups would continue to be quick.  This is the basic idea of MySQL indices.

Now, the easiest time to define the ordering is before we’ve even received a single card.  But let’s say we’ve collected a million cards before realizing that we’d also like to be able to index business contacts by their company.  It would take a long time to organize all that data in the proper order!

Fortunately, there’s a snazzy little trick for quickly adding indices to large MySQL tables.  The basic concept is to create a new table, add the column indices you want, and then import the data from the existing table into the new one.  Here’s how it goes in MySQL:

Export MySQL Query Results to CSV

If you’re SSH’d into a MySQL server and want to export MySQL query results to CSV (readable by Excel), simply add the below snippet to the end of your query.

Note that '/tmp/results.csv' in the code above should correspond to a writeable destination, and the file can’t already exist.

How to Run Windows on a Mac for Free

VirtualBox is fantastic open-source software that allows you to operate a virtual machine with another operating system. Though it works on most platforms and can run most operating systems, I have a Mac and I needed a Windows OS to run Microsoft Visual Studio. It took a little while to figure out, but here’s a little tutorial on how to run Windows on a Mac for free.  I’ll outline the steps to install VirtualBox, set up a virtual machine to run Windows XP, install some extra features, and enable file sharing between the host machine and the virtual machine.

Continue reading…

How to Create Custom Mac Icons

Creating Custom Mac Icons

Creating customized Mac icons for your folders, files, and applications is very easy – the most difficult part is ensuring that you have the right tools for the job. But hey, that’s why I’m here. 🙂 I’ve done the research to find the best ways to create your own customized Mac icons. Here’s a little tutorial on a couple methods that I have personally tested and confirmed.

Continue reading…