Detecting Dates in Microsoft Excel Spreadsheets

Microsoft Excel does not have an "isdate()" function, making it hard to determine whether a cell contains a date.

Excel VBA provides a function, but a formulaic solution also exists.  The trick is to realize that:
  1. Dates are stored as numbers in Excel, and
  2. You can use the Cell() function to return the format of a cell.
Armed with these two pieces of information, we can write a formula that returns TRUE (or one) if:
  1. The cell contains a number, and
  2. Is formatted as a date.
Here's how.

Use the IsNumber() function to determine whether or not the value contained in a cell is a number, like this: =ISNUMBER(A1).

Use the Cell() function to get the format of a cell, like this: =CELL("format",A1).

If Cell() returns a result in the range "D1" to "D5", the target cell -- in this case A1 --  is formatted as a date.  Therefore, we can write: =OR(CELL("format",A6)={"D1","D2","D3","D4","D5"}).

Or, more compactly: =LEFT(CELL("format",A6),1)="D".

Now we just need to combine the two formulas with an And(), like this:
=IF(AND(ISNUMBER(A5),LEFT(CELL("format",A5),1)="D"),1,0).

This formula returns one if the cell is a number and it is formatted as a date, otherwise it returns a zero.

Anonymous Inner (Lambda) Functions with PHP

<?php
$str = "hello world!";


/* 1. won't work with with anonymous inner (lambda) function before PHP 5.3
  $str = preg_replace_callback(
    '/world/',
    function( '$match', 'return "michael";' ),
    $str ); */
 

/* 2. use create_function instead */
$str = preg_replace_callback(
  '/world/',
  create_function( '$match', 'return "michael";' ),
  $str );
 

echo $str ; // output: hello michael!
?>


Reinstalling a LAMP stack on Ubuntu

This is to reinstall a LAMP stack on Ubuntu Jaunty, but it should work for pretty much any version.

Shut down Apache:
sudo /etc/init.d/apache2 stop
Shut down MySQL:
sudo /etc/init.d/mysql stop
Remove the entire LAMP stack:
sudo apt-get purge apache2 php5-mysql libapache2-mod-php5 mysql-server php5 phpmyadmin
  • Note the use of purge instead of remove -- this gets rid of configuration files as well.
  • You will need to download everything from the archives during the reinstall.
  • Stuff in /var/www will not be removed.
Now perform a new installation:
sudo apt-get install apache2 php5-mysql libapache2-mod-php5 mysql-server php5 phpmyadmin

How to find the last used row in a spreadsheet without using VB

I frequently copy spreadsheets between Microsoft Excel and Open Office Calc and I sometimes have a need to find the last row being used in a spreadsheet.  But since Open Office does not support Visual Basic for Applications (VBA), I needed a formulaic approach.

Here is the formula: {=MAX(NOT(ISBLANK($A$1:$A$65536))*ROW($A$1:$A$65536))}

This is an array formula, meaning, it will iterate over a range automatically and evaluate the formula for each cell in the range.  (NOTE: Don't forget to press CTRL-SHIFT-ENTER to save it after you are done editing the cell, otherwise it won't be saved as an array formula!)

How does it work?
  1. The array formula starts at cell A1 and works its way down to cell A65536.  Along the way it performs ISBLANK() on each cell it encounters.  ISBLANK() evaluates to true for each blank (empty) cell.
  2. Surrounding that, we have a NOT() function, which reverses the result from ISBLANK giving us false for blank cells and true for non-blank cells.  We now have a list of which cells are blank and which are non-blank.
  3. We then multiply that result by the ROW() number of each cell in the range, which is the same row number you see down the left side of the spreadsheet.  Since false is equivalent to zero and true is equivalent to one, this has the effect of multiplying the row number for each blank cell by zero and each non-blank cell by one.  We now have a value of zero for each blank cell, and the value of the row number for each non-blank cell.
  4. Finally, we take the MAX() of the list, which gives us the largest number in the list.  The largest number will be the last row used in the sheet.

    Protect your email address with javascript

    Spam is the bane of mankind's existence. Although modern spam filters do a good job of keeping your inbox clean, you can take some additional steps to protect yourself. One is to prevent your email address from being harvested from your web site. Spammers have crawlers that troll through web pages looking for the pattern name@site.com, or something similar.

    If you want to put an email contact on your web site, but also want to avoid spammers, you can use JavaScript. Here's the code. Copy it into the body of your contact web page, then change the name and site.

    <html>
    <head>
    <title>How to protect your email address</title>
    </head>
    <body>
    <script type='text/javascript'>
    e = 'name' + '@' + 'site.com';
    document.write( "<a href='mailto:" + e + "'>" + e + '</a>' );
    </script>
    <noscript>Please turn on JavaScript!</noscript>
    </body>
    </html>

    IE tip - use the Explorer view to organize your bookmarks

    To show all your favorites in an Explorer view:
    1. Go to Favorites --> Organize Favorites in the menu.
    2. Hold the shift key down when clicking on Organize Favorites.
    The Explorer view allows you to select multiple bookmarks at once, making it much easier to move things around.

    Bookmarklet for Creating an Amazon Affiliate Link

    Bloggers who run Amazon affiliate sites know how difficult it can be to add Amazon product links to your site. A key problem is the sheer length of the link url.

    Fortunately, Amazon supports a considerably shorter format url, having the form: http://www.amazon.com/dp/ProductID/?tag=YourAssociateID. This is helpful, but you still need to construct the link, then copy/paste it into your page.

    I have created a bookmarklet to help. Drag Make Amazon Link to your bookmarks toolbar to install it, then right-click, select "properties" and change the 'YourAssociateID' text to your actual associate id. That's it!

    You can check the link with Amazon's link checker to be sure everything will work correctly.

    Here is the bookmarklet code in a more readable format for those who might be interested:

    javascript:

    var t='YourAssociateID',
    h=document.location.href,
    p=h.split('/')[5];

    (function(){
    w=window.open('','','width=600,height=400');
    d=w.document;
    d.writeln('The Amazon.com link is:'+h+'

    ');
    d.writeln('Your short affiliate link is:
    http://www.amazon.com/dp/'+p+'/?tag='+t);
    })();

    30 Tips for Winning Unreal Tournament 2004

    I play a lot of Onslaught Torlan in Unreal Tournament 2004. These are tips on tactics to help you win the game with this map, but many of the tips will work with other maps or other game types. Either way, you must practice!
    1. Get out of your base fast. The faster you build nodes, the better chance you have beating the other team.
    2. Don't defend your base. I see this all the time. Teams that are losing start to hang around the base attempting to fend off attackers. Don't. The only sure way to avoid attacks on your base is to make sure your team controls the nodes.
    3. Playing "Instant Action" on your own? Prevent the bots from taking the best vehicles by repairing the vehicles (alt-click when using the link gun). Bots will veer away, leaving the ride for you.
    4. Another Instant action tip: Bots only go to the top of the central tower in Onslaught Torlan when the Redeemer is up there. If you start to see bots head up there, try to kill them and get there first.
    5. Give rides in vehicles leaving the base or any other node. A little teamwork goes a long way.
    6. Don't flak the Manta at the start of the game. If you get to the manta first, get in, but make it go lower so others can jump on. You can get three or four people on it besides the pilot. Drop everyone off at the first node so they can link and power it up fast.
    7. Set your keyboard up. The default setups are not intuitive. You don't want to think, just react. That means a good keyboard setup. Here's mine (I'm a lefty):
      • right hand for the keyboard, left hand for the mouse.
      • up, down, left, right arrows: movement.
      • ctrl = up, shift = down. This works for both vehicles and personal movement (shift to crouch, ctrl to jump). This keeps my right hand on the arrow keys, with the ctrl and shift buttons in easy reach of my thumb.
      • space = drop item or exit a vehicle (useful for the manta trick, described below).
      • mouse wheel to scroll thru weapons.
    8. Trade graphics for speed. you don't need your system slowing you down during a mano-a-mano fight. Reduce graphics detail as much as you can stand while still keeping the game looking as good as possible.
    9. Shock gun tip: A lot of guys like to use the shock gun in one on one fights. The secret to surviving a shock gun attack is to run toward the attacker. He needs to be a certain distance from you for the weapon to be effective.
    10. Avoid one on one fights if you can. It's far more effective to fire the Goliath tank from a distance than to engage in personal battles.
    11. Kill the Gnome screensaver. If you are running in Linux (I'm using Jaunty), kill the screensaver before starting play. Otherwise, you get unpredictable behavior when it kicks in, which can be a problem during battles. I use a launcher bash script that looks like this:
    12. #!/bin/sh
      killall gnome-screensaver 2>/dev/null
      /usr/local/bin/ut2004 2>/dev/null
      gnome-screensaver
      exit 0
    13. Ditch the assault rifle. It's useless, and I don't want to scroll through it with the mouse wheel. Toss it away with the ThrowWeapon key (usually the backslash).
    14. Turn off ambient sounds and music. You want to hear people coming up behind you!
    15. Manta trick: Fly at top speed directly toward someone. They will try to aim their Avril at you. Before they can lock on, jump out, which will prevent them from locking on, but the manta will continue forward and run over them!
    16. Turn off voice chat. Most teams don't use it effectively, and it is usually very annoying. Same with text to speech.
    17. If you get the Raptor coming out of the base at the start of the Torlan game, start the first node, then head to the central tower right away to get the Redeemer.
    18. Just after the game starts, head to the enemy base. There is usually no one there, and you can steal their shield and Big Keg o Health. It helps you and denies it to the enemy, always a good thing.
    19. If you are falling from a high place, activate your shield gun. Program your middle mouse button to activate the shield gun so you don't have to fumble with the keyboard.
    20. Turn on "always run". There is absolutely no point in walking anywhere.
    21. From the Hellbender side turret (the one that shoots out the energy balls that you can then shoot and cause a chain reaction), shoot the most distant ball first. This gives you an element of surprise.
    22. When in the hellbender rear turret, remember that many vehicles do not need a full charge to be destroyed. For example, destroying a Raptor takes one full charge on the first shot, then only a slight charge on the second shot. You do not need to wait for the weapon to fully charge again.
    23. Scorpion tip: Do not charge the weapon fully before firing. Just a short charge up to three energy balls, then let go. You get a much faster rate of fire than way. Keep doing it, and you can cause destruction to a node or enemy vehicle much more quickly than waiting for a full charge each time.
    24. The flack cannon is very effective against the Goliath (tank).
    25. You can shoot effectively from the bridge that goes over the central canyon in Torlan. But it is very hard to hit you unless the enemy comes up there.
    26. When powering up a node, pay attention to the energy level indicator (your maps must be on to see it!). When it turns from yellow to green, head to the next node. You do not need to power it up fully. It will continue powering up on its own. In Onslaught Torlan, the timing works out so the next node will be active exactly as you arrive there with the Manta.
    27. Don't try to guide the Redeemer toward a target. It is too easy to shoot down, expecially in Instant Action mode. Instead, sacrifice yourself in a suicide attack. For example, while above your target, say a node, jump out of the Raptor from a good height. While falling, select the Redeemer, then just before hitting the ground, fire it into the target. Try to land behind the turret so it protects you from the blast, and you might survive.
    28. If you are building nodes well, you will be able to tell the next enemy node to attack. Try to get there early to take out the turret, before the node is enabled for your attack. That way, the enemy has a much less effective defense, and you don't have to fight off the turret while trying to destroy the node.
    29. You don't have to be right up against a vehicle to get into it. Hit the "Use" key from a few steps away. This lets you get into a vehicle more quickly when you are racing a teammate for the Manta.
    30. Transporting to the center node takes you into the canyon when the double damage is about to appear.
    31. When fighting in the Goliath (tank), turn the tank body in the same direction as the turret to swing the gun around faster.
    Maps on Gentlemen!

    amzn.to link shortener

    Amazon links can be very long indeed. You want to be able to turn this:

    http://www.amazon.com/gp/product/B000CSWCQA?ie=UTF8&tag=goodforgeek-20&linkCode=as2&camp=1789&creative=390957&creativeASIN=B000CSWCQA

    into this:

    http://amzn.to/cRH47b

    How to use amzn.to? Amazon has signed up with bit.ly and reserved the amzn.to domain, so that if you use the bit.ly service, your shortened link will reference amzn.to, which redirects to bit.ly, is translated back to the long url form, and then redirects to Amazon.com.

    Disclosure: Goodies for Geeks is an Amazon affiliate site.

    Blogger custom domain displays blank white page

    You changed to a custom domain and now Blogger is displaying a blank white page? My experience: something is wrong with the Blogger template. Here's how to fix it:
    1. Change back to Blogger hosting from Settings tab --> Publishing.
    2. Go to Blogger Template Designer and change your template to something new. You may want to back up your current template first!
    3. Check the preview to make sure the changes look ok.
    4. Save.
    5. Do not change back to custom domain hosting yet! Wait a bit.
    6. Check that your blog is displayed properly by Blogger.
    7. Now change back to your custom domain. Wait a bit more. Maybe an hour.
    8. Your custom domain should be displaying your new template.

    How to remove the left side navigation bar from Sharepoint

    1. Site Actions --> Edit Page
    2. Click Add a Web Part (left or right side, it doesn't matter)
    3. Scroll down and check the Content Editor checkbox

    4. You will see a message: "To add content, open the tool pane and then click Rich Text Editor";
    5. Click the "open the tool pane" link
    6. Click the source editor button, paste in the following code and click the save button:
      <style>
      .ms-navframe {
      display: none;
      }
      .ms-quickLaunch {
      display: none;
      </style>
    7. Expand the layout category and click the hidden checkbox to prevent the Content Editor Web Part from appearing on the page
    8. Click Exit Edit Mode

    To change the Content Editor Web Part later:
    1. Site Actions --> Edit Page
    2. You will see a (Hidden) Content Editor Web Part
    3. Click the Edit dropdown button to Modify Shared Web Part or Delete
    4. If necessary, click Add a Web Part, then the "Advanced Web Part gallery and options" link
    5. Click "Hidden Web Parts under the "Browse" section
    6. Select your Web Part under the Web Part List section
    7. Click the Add button at the bottom

    Where is the Ubuntu Jaunty login screen background image?

    If you want to use this image for your wallpaper, the default welcome screen background image is here: /usr/share/gdm/themes/Human.

    How to set up a Tremulous server on Ubuntu Linux

    I did this on Feisty, but it should work for other versions:

    1. Download the .run file from sourceforge:

    sudo wget http://prdownloads.sourceforge.net/tremulous/tremulous-q3-1.0.2-installer.x86.run?download


    2. Run the install:

    sudo sh ./tremulous-1.1.0-installer.x86.run

    Take all the defaults, except also install the dedicated server option. I installed to /usr/local/games/tremulous.


    3. Modify the server name in the config file:

    cd /usr/local/games/tremulous
    sudo vi base/server.cfg


    4. Copy the patched version of tremded from tjw's site (contains important admin improvements). Assuming that you are still in /usr/local/games/tremulous, type:

    sudo wget http://tjw.org/tremulous/linux/tremded.x86
    chmod 755 tremded.x86


    5. Copy the game.qvm file from tjw's site:

    sudo wget -O ~/.tremulous/base/vm/game.qvm http://tjw.org/tremulous/game.qvm

    NOTE: The instructions for these two steps can be found at tjw's site here:

    NOTE: The qvm file (Quake Virtual Machine) and tremded files must match or the server will not run!


    6. Run the server in test mode with:

    sudo ./tremded.x86 +set dedicated 1 +exec server.cfg

    NOTE: "dedicated 1" does not send a heartbeat to the master server.
    You will see the game console. Type "status" to ensure the game is running.

    Use the 'dedicated 2' option if you want your server to appear in the master server list. Otherwise the server will only appear in your local network list what you run the client.

    To make a public server, make sure to assign a static IP address to your server, and set up your router to forward port 30720 traffic to that address.

    See this discussion for the details.

    8. Get a list of console commands with:

    cmdlist

    For example, change the map by issuing the command: map ; example: map atcs


    9. To shutdown the game, type:

    killserver

    10. To exit the game console, type:

    quit

    GMail hack: How to identify messages without an attachment

    I send email to my own GMail account all the time, both to back up files, and as a to-do list of things I need to take care of later. As a general rule, if the message has an attachment, I'm probably trying to back up a file. If there is no attachment, the message should go to my to do list for later action.

    I wanted to set up a filter to be able to distinguish between the two types of messages. The filter should apply a label based on whether or not the message has an attachment. For messages with an attachment, the filter should apply a "backup" label, and for those without an attachment, it should apply a "to do" label.

    It turns out that GMail search cannot find just messages that do not have an attachment. It does a good job at finding messages with attachments, but otherwise returns a mixed set of messages with and without attachments. For example, negating the "has" operator with "-has:attachment", does not return the expected result.

    The solution is to apply a label to messages having an attachment, then search and filter with the "-label" operator. Here's how:

    STEP 1: LABEL MESSAGES THAT HAVE ATTACHMENTS

    Search for messages having an attachment by using the "has:attachment" operator, then apply the "backup" label to the result set.
    You can also create a filter for messages having an attachment, then apply the "backup" label in the next step.

    STEP 2: SEARCH FOR MESSAGES WITHOUT THE LABEL

    Now you can search for messages without attachments by using the "-label:hasAttachment" operator. GMail will return only the messages that do not have an attachment.

    MAKING IT AUTOMATIC.

    You can set up a filter to apply the the "backup" label automatically. Enter (from:me to:me has:attachment) as the filter criteria in the "Has the words" field. Then in the next step, apply the "backup" label.

    All incoming messages having an attachment will receive the "backup" label, and you can now search your messages for your backed up files with "(from:me to:me label:backup)".

    However, this only solves part of the problem. What if you want a filter to apply your "to do" label to messages that do not have attachments? In that case, you set up a second filter to with "(from:me to:me -label:backup)". Negating the label operator will give you only the messages without attachments.

    Notice that it's important that the previous filter run first, so that the "backup" label is applied. Otherwise the "-label:backup" operator will not work.

    MySQL server has gone away

    Handling error 2006: MySQL server has gone away on a windows xampp installation.

    Summary: xampp installation on Windows XP, error encountered by a PHP script while uploading large files to a mysql database server.

    This is caused by a mysql max_allowed_packet setting, which by default is set to 1M.

    You can confirm the setting by
    • checking the value in sql by issuing a show variables command, or
    • by checking the system variables in phpmyadmin.
    To change the setting, you need to edit the my.cnf file in your c:\...\xampp\sql\bin directory and change the default value of 1M to something larger, for example 16M. NOTE: Change the directory path to its actual value.

    You may see the file named simply as "my", and it may also look like a shortcut. In this case, you cannot click on the file icon to open it. Instead, go start --> run and issue the command: notepad.exe c:\...\xampp\mysql\bin\my.cnf. Again, change the directory path to its actual value.