How to extract domain from a URL in Excel

This is just a quick tip. Let’s say that you’ve got “http://www.google.com/search?q=1234” in cell B1 in Excel, but you want to display “google.com”. You can use this formula:

=SUBSTITUTE(MID(B1, FIND(“//”, B1)+2, FIND(“/”, B1, FIND(“//”, B1)+2)-8), “www.”, “”)

This isn’t perfect as it assumes you always use “http://”, ┬ábut it works pretty well for a quick, easy fix.

PHP: Fastest way to check if an array is empty

I just posted benchmarks for checking for an empty string that I ran when looking to improve the efficiency of an application. Another simple benchmark I ran was for ways to check if an array is empty.

Like strings, there are a ton of ways to check if am array is empty. These here are not exhaustive, but a few that I chose to test:

  1. !$array
  2. $array == false
  3. empty($array)
  4. count($array) == 0
  5. $array == array()

PHP: Fastest way to check if a string is blank

I run an application that requires a very high level of efficiency due to very high volume. I recently did an evaluation of efficiency for this application and performed a benchmark on a number of important aspects of the code. My findings were very interesting.

As you may know, there are a ton of ways to check if a string is empty. These here are not exhaustive, but a few that I chose to test:

  1. !$string
  2. $string == false
  3. empty($string)
  4. strlen($string) == 0
  5. $string == ” Continue reading PHP: Fastest way to check if a string is blank

How to install PHP Memcache on Windows WAMP, Linux for any operating system (without really installing)

I have a site that runs on Linux in production that uses Memcache. Installing Memcache on Linux is a cinch. I was setting this site up in my development environment however (Windows 7 64-bit, with WAMP, specifically Apache 2 and PHP 5.3) and I quickly discovered it’s not so easy. For the life of me, I could not find the correct php_memcache.dll file.

After spending a ton of time unsuccessfully install Memcache on my local machine, I realized that I don’t even need the memory caching functionality of Memcache, I just need the functions to work. Continue reading How to install PHP Memcache on Windows WAMP, Linux for any operating system (without really installing)

How to Install PHP APC on Fedora & CentOS

APC (or Alternate PHP Cache) is a popular PHP PECL extension that can be used for PHP op-code caching. It is very stable and can significantly reduce page rendering times. It works by caching the PHP binaries, so that PHP doesn’t have to compile them on every request.

Installation is simple:

1. Use yum to install necessary packages.

# yum install php-pear php-devel httpd-devel pcre-devel

Continue reading How to Install PHP APC on Fedora & CentOS

How to insert a tab character into Putty for Linux

If you’re like me, you’ve noticed that if you’re trying to grep for a tab character, the following won’t work:

grep "\t" file.txt

The solution is to use a literal tab character, but it’s not quite so simple. You can’t insert a tab character just by hitting the tab button or by pasting one in. You need to hit Ctrl+V first:

So to type a tab in the putty console:

How to loop through days (dates) in bash and force two digits (zerofill)

Often with bash, I need to run a script and pass in a date. It helps to be able to use a bash loop to do it all at once. Here’s how you do it, and make sure the day is two digits. Note the use of the println command.

for day in {1..31}; do php some_script.php 2011-05-`printf "%02d" $day`; done

How to have htop save configuration on exit

htop is awesome. I use it all the time to monitor all the servers I use. It was only until recently that I noticed it has some great configuration options, namely the "Tree View." This allows you to see a hierarchy of processes, which can be really helpful in finding out why certain processes are running.

I quickly realized it would be a pain to have to constantly hit F5 every time I opened the program, until I realized there was a way to make htop remember your last configuration.

What you want to do is make sure you close out of htop with F10 instead of Ctrl+C, which I normally use. You only need to use F10 when you want to save the settings, and can subsequently close out how you normally do!

How to Hide Digsby Ads

I use Digsby as my instant messenger client. A couple minutes ago, I received an update which set ads to display in the conversation windows by default. I immediately decided I'd try to figure out how to remove the ads, or switch back to Pidgin, the free open source client. Turns out it was simple to turn off the ads. When you're done, you'll need to reopen your conversation windows to see the changes.

From the Buddy List window:

  1. Tools -> Preferences
  2. Conversations
  3. Uncheck "Support Digsby development by showing an ad in the IM window"