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 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 Wrap Text in a jQuery Mobile List

I’ve been doing some development in jQuery Mobile, and though it’s still in Alpha, it’s a great library. That said, there are still some serious bugs in it and some other less than ideal things happening. In any case, working with jQuery Mobile has certainly helped my debugging skills along.  🙂  One of the toughest issues that almost had me pulling out my hair was figuring out how to wrap text in a jQuery Mobile list.  Read on for the fix.

Continue reading…

More Syntax Highlighting for Coda

Coda ships with syntax highlighting support for a lot of great languages, but some are noticeably left out of the mix. I was recently helping a buddy set up an environment to develop C programs on an external server, and while Coda seemed a clear better alternative to using Nano (particularly since we could still compile and run the programs from Coda’s built-in terminal), the program lacked syntax highlighting for the C language.

Adding highlighting for C (and a host of other languages) turned out to be pretty easy.

To add support for other languages, download this zip file, unzip, and copy the Modes folder into Contents > Resources of the Coda package distribution. To access the contents of the package, right click on the Coda application and select “Show Package Contents”. Then navigate to Contents > Resources.

Screen-shot-2010-09-15-at-3.44.01-PM

If you are asked, overwrite existing folders and files. Note that if you only want to install certain syntax highlighting modes, just copy and paste what you need (of the .mode files in the downloaded Modes folder) into the Modes folder in the Coda package. I forgot which languages were standard to Coda so I’ve just included all of the ones I have in the download.
Continue reading…

Office 2007 MIME Types

Here’s a list of MIME Types for Office 2007 files (those pesky files extensions that end with an x). Useful for file type checking in web applications and the like.

  • .docm – application/vnd.ms-word.document.macroEnabled.12
  • .docx – application/vnd.openxmlformats-officedocument.wordprocessingml.document
  • .dotm – application/vnd.ms-word.template.macroEnabled.12
  • .dotx – application/vnd.openxmlformats-officedocument.wordprocessingml.template
  • .potm – application/vnd.ms-powerpoint.template.macroEnabled.12
  • .potx – application/vnd.openxmlformats-officedocument.presentationml.template
  • .ppam – application/vnd.ms-powerpoint.addin.macroEnabled.12
  • .ppsm – application/vnd.ms-powerpoint.slideshow.macroEnabled.12
  • .ppsx – application/vnd.openxmlformats-officedocument.presentationml.slideshow
  • .pptm – application/vnd.ms-powerpoint.presentation.macroEnabled.12
  • .pptx – application/vnd.openxmlformats-officedocument.presentationml.presentation
  • .xlam – application/vnd.ms-excel.addin.macroEnabled.12
  • .xlsb – application/vnd.ms-excel.sheet.binary.macroEnabled.12
  • .xlsm – application/vnd.ms-excel.sheet.macroEnabled.12
  • .xlsx – application/vnd.openxmlformats-officedocument.spreadsheetml.sheet
  • .xltm – application/vnd.ms-excel.template.macroEnabled.12
  • .xltx – application/vnd.openxmlformats-officedocument.spreadsheetml.template

How to Remove the Top Border from Drupal Tables

I’ve been very busy developing a couple projects over the past couple days, but here is a quick little trick to get around one of Drupal’s quirks. If you’re unfamiliar with Drupal, it’s a fantastic CMS (content management system) built on PHP and MySQL. For those blog-savvy among us, it is to general websites what WordPress is to blogs. I use Drupal to get sites up quickly and with great functionality, and I highly recommend it to anyone who is looking to build powerful, custom websites without “re-inventing the wheel.”

Anyway, Drupal has this strange quirk in its source that creates a small grey border on the top of tables inserted in a page’s content.  A quick trip to my inspector revealed how to remove the top border from Drupal tables.  Simply add the following line to your CSS.

body tbody { border-top: none; }

All there is to it. 🙂