Calculating Inflation in Excel

Future value of 100 dollars at 3% inflation in 10 years = $74.41:


Formula to copy in cells to calculate inflated value:
Col A        Col B
Year     Inflated Value
0        =100*(1+.03)^A1
=A1+1    =100*(1+.03)^A2
=A2+1    =100*(1+.03)^A3
=A3+1    =100*(1+.03)^A4
=A4+1    =100*(1+.03)^A5
=A5+1    =100*(1+.03)^A6
=A6+1    =100*(1+.03)^A7
=A7+1    =100*(1+.03)^A8
=A8+1    =100*(1+.03)^A9
=A9+1    =100*(1+.03)^A10
=A10+1   =100*(1+.03)^A11

Microsoft VBA Get Existing Outlook Instance

Sub Get_Existing_Outlook_Instance()
  Dim objOutlook As Outlook.Application
  ' Gets the existing instance (if Outlook is already open) regardless of early or late binding
  On Error Resume Next
  Set objOutlook = GetObject(, "Outlook.Application")
  If objOutlook Is Nothing Then
      Debug.Print "Outlook is not open, getting a new instance"
      Set objOutlook = New Outlook.Application
  End If
  Set objOutlook = Nothing
End Sub

Microsift VBA Early vs. Late Binding Example

Private Sub Early_vs_Late_Binding_Example()
#Const LATEBINDING = False

    Dim objOutlook As Object
    Set objOutlook = CreateObject("Outlook.Application")
    ' NOTE! Early binding requires a typelib reference.  In the VBE click Tools -> References
    ' and make sure that "Microsoft Outlook xx.x Object Library" is selected
    Dim objOutlook As Outlook.Application
    Set objOutlook = New Outlook.Application
#End If
    Set objOutlook = Nothing
End Sub

Move Ubuntu Unity Launcher to the Bottom of the Screen

gsettings set com.canonical.Unity.Launcher launcher-position Bottom

To reset to the left side:
gsettings set com.canonical.Unity.Launcher launcher-position Left

Changing the window placement in Ubuntu

To see the current setting:
dconf read /org/compiz/profiles/unity/plugins/place/mode

To update the setting:
dconf write /org/compiz/profiles/unity/plugins/place/mode 1

(Try different values to understand the behavior.)

Restoring the default login screen background in Ubuntu Xenial

Changing the desktop wallpaper also changed the login screen. Follow these steps to override that behavior and reset the login screen back to the default.
cd /usr/share/glib-2.0/schemas/
sudo vi com.canonical.unity-greeter.gschema.xml
Look for this key node:
<key name="draw-user-backgrounds" type="b">
<summary>Whether to draw user backgrounds</summary>
Change the value true to false.

You can also remove the white dots by changing this key node:
<key name="draw-grid" type="b">
<summary>Whether to draw an overlay grid</summary>
Now recompile the schema with this command:
sudo glib-compile-schemas /usr/share/glib-2.0/schemas/
Log out and back in to see the change.

Biweekly vs. semi-weekly

  • Biweekly means once every two weeks.
  • Semi-weekly means twice per week.

Ubuntu Unity Configurations

To position the launcher at the bottom of the screen:
gsettings set com.canonical.Unity.Launcher launcher-position Bottom

To return to the default position on the left:
gsettings set com.canonical.Unity.Launcher launcher-position Left

To open new windows centered on the screen without installing compiz-conf:
dconf write /org/compiz/profiles/unity/plugins/place/mode 1

Calculating Percentage Change

  • Method 1: (new - old) / old
  • Method 2: (new / old) - 1

Old value 100
New value 50
Method 1 =(B2-B1)/B1 -50.00%
Method 2 B2/B1-1 -50.00%

Getting a list of stock symbols

Lists of stock symbols can be found at either of these links:

You can download a list of symbols from the site for the Nasdaq, NYSE, and AMEX exchanges.

The FTP directory at gets updated every night at 3:00AM (symbols can change). Here is a quick Python script to download the nasdaqlisted.txt and otherlisted.txt files from the ftp site:


# typical use: python > symbols.txt

import urllib

def get_data( url ):
    data = urllib.urlopen( url )
    lines = []
    for line in data:
        lines.append( line.rstrip().split('|') )
    return lines

url = ''
files = ['nasdaqlisted.txt', 'otherlisted.txt']

for f in files:
    print get_data( url + f )

List Comprehensions in Python

# create a new list
>>> a = [1,2,3,4,5]
>>> a [1, 2, 3, 4, 5]

# sample list comprehension expression; equivalent to b = a
>>> b = [a[i] for i in range(len(a))]
>>> b [1, 2, 3, 4, 5]

# only even indices
>>> b = [a[i] for i in range(len(a)) if i % 2 == 0]
>>> b [1, 3, 5]

# only even indices and conditionally modifies the value of a[i] 
>>> b = [a[i]*2 if i > 1 else a[i] for i in range(len(a)) if i % 2 == 0]
>>> b [1, 6, 10]

Deck of Cards Exercises

The Deck of Cards exercises.

For each suit, perform a certain exercise:
  • Clubs = burpees
  • Hearts = pushups
  • Spades = jumping jacks
  • Diamonds = sit ups

Use the value of the card as the number of repetitions:
  • 2-10 = number of reps on the card
  • Jack = 11 reps
  • Queen = 12 reps
  • King = 13 reps
  • Ace = 15 reps
  • Joker = 30/60/90 second rest -OR- 10/15/20 reps of all exercises

Implementing ATAN2

An implementation of ATAN2 in PHP. PHP implements ATAN2 but I needed to figure out the algorithm for a microcontroller that didn't, so I prototyped it in PHP.

Here is the code:

class Math {
  public static function atan2( $dy, $dx ) {
    if( $dy > 0 ) {
      if( $dx > 0  ) $tcl = atan($dy/$dx);
      if( $dx < 0  ) $tcl = M_PI - atan(-$dy/$dx);
      if( $dx == 0 ) $tcl = M_PI/2;

    if( $dy < 0 ) {
      if( $dx > 0  ) $tcl = -atan(-$dy/$dx);
      if( $dx < 0  ) $tcl = atan($dy/$dx) - M_PI;
      if( $dx == 0 ) $tcl = -M_PI/2;

    if( $dy == 0 ) {
      if( $dx > 0  ) $tcl = 0.0;
      if( $dx < 0  ) $tcl = M_PI;
      if( $dx == 0 ) $tcl = 0.0; // the 2 points are the same, default to zero

    return $tcl;
And here is an example of how to use it:
$heading = 270.0;  // degrees
$Ax =  0.00;
$Ay =  0.00;
$Bx = -7.89;
$By = -0.86;

// get target distance and bearing in degrees
$dx = $Bx-$Ax;
$dy = $By-$Ay;
$dist = sqrt( pow($dx,2) + pow($dy,2) );
$dir = Math::atan2( $dy, $dx ) * 180 / M_PI;
printf( "Target spotted at %0.3f degrees, distance %0.3f !!\n", $dir, $dist );

// get new heading
$diff = $heading - $dir;
if( $diff < -180 ) $diff += 360;
if( $diff > 180 ) $diff -= 360;
printf( "Turn %s %0.3f degrees\n", ($diff < 0 ? 'left' : 'right'), $diff );

Implementing Logic Gates in a Spreadsheet

Here are some of the basic logic gates, implemented as spreadsheet formulas.

GateSpreadsheet Formula

It is possible to implement any gate using only NOT and OR (NOR), or with NOT and AND (NAND) gates. For example, here is an AND gate implemented using only NOT and OR gates:

AND using only NOR gatesNOT(OR(NOT(OR(A,A)),NOT(OR(B,B)))

With AND, OR and NOT, we can implement a half adder, like this:

Column AColumn B
Carry (AND)=AND(B1,B2)
Sum (XOR)=OR(AND(B1,NOT(B2)),AND(NOT(B1),B2))

By string together two half adders and OR-ing the carry bit, we can create a full adder:

BitSpreadsheet Formula

Implementing a 4-bit adder is just a matter of simply replicating the full adder logic four times:

Input A0000
Input B0000

Radians made easy

If you are in danger of losing your Geek cred because you don't understand radians, fear not! Radians aren't bad, they're just drawn that way.

What is a radian?

Diagram A
You already know some things about degrees, like there are 360 degrees in a circle and that you can measure an angle with two points on the circle's edge (see Diagram A).

Radians are just another way to measure angles. Here's how:

Start with a circle. The radius of the circle is a line from the center of the circle to a point on the edge. In Diagram A, that's the line CA. Start point A moving counterclockwise around the circle. It will trace out an arc as it travels. When the arc is as long as the radius of the circle, stop. Call that point B. You now have an arc AB, and an angle ACB. That angle at C is equivalent to one radian. So, the length of arc AB is the same as the length of the radius of the circle, which is line CA. Here's the rule:
  • The lengths of the arc and the radius are equal.
Next, you already know that the ratio of the circumference of a circle to its diameter is pi, or π, which is 3.14. The formula is C = πd. Since the radius of a circle is half the diameter, then d = 2r, so C = πd = π2r, more commonly written C = 2πr.

Since C = 2πr, and since we already said the radius of the circle equals one radian, setting r = 1 means that C = 2π radians. In other words, there are 2π radians in the circumference of the circle, which is 360 degrees. So, 360 degrees = 2π radians. Knowing that, we can now convert between radians and degrees.

Since there are 2π radians in 360 degrees, we get: 2π rad = 360 deg. Diving both sides by 2π, rad = 360/2π = 180/π. And, because 360 deg = 2π rad: dividing both sides by 360, deg = 2π/360 = π/180. To summarize:
  • Given degrees, you get radians with rad = deg × 180/π.
  • Given radians, you get degrees = rad × π/180.
Radians for common degrees

You'll see charts that tell you 90 degrees equals π/2 radians, or 315 degrees equals 7π/4 radians. How did they get that?

Remember that C = 2π, meaning that there are 2π radians in 360 degrees. To find out how many radians are in, for example, 90 degrees, we just multiply 2π by the ratio 90/360, like this:

radians = 90/360 × 2π.

Reducing the fraction, we get ¼ × 2π, which simplifies to 2π/4, or π/2. So 90 degrees = π/2 radians.

Let's do a few more:

180 degrees = 180/360 × 2π = ½ × 2π = 2π/2 = π radians.
270 degrees = 270/360 × 2π = ¾ × 2π = 6π/4 = 3π/2 radians.
360 degrees = 360/360 × 2π = 2π radians.

Try the calculations for yourself! 45, 135, 225, and 315 degrees are all common angles.

Cheaper Gas Calculator (spreadsheet)

Is is worth driving to a more distant gas station to buy gas that's slightly cheaper? Here's a spreadsheet to find out. Just copy and paste into cell A1 in your favorite spreadsheet program, then enter your own data in cells A1 through A6. Your savings in cells A14 and A15 should be a positive number to make the trip worth while.

In cells A5 and A6 just put the one-way distance to the away station. The spreadsheet automatically calculates the round-trip cost.

Tested in Excel, OpenOffice Calc and Gnumeric.

15tank size (gallons)
29.55miles per gallon
3.619local price per gallon
3.599away price per gallon
2.00miles to local station (one way)
5.00miles to away station (one way)
=A1*A3cost to fill up at local station
=A1*A4cost to fill up at away station
=A8-A9savings from cheaper gas
=(A6-A5)*2extra round trip distance to away station
=A12/A2extra gallons to drive to cheaper station and back
=A13/A3extra travel cost to away station (based on local gas price)
=A10-A14savings (loss)
=A16/A1savings (loss) per gallon

Highlighting rows in Excel having specific text

We have an Excel spreadsheet and we'd like to somehow highlight cells containing specific text.  For example, we have the following data in cells A1 through A10 and we want to highlight any row containing the letter 'F', in this case cells A3, A5 and A8.


First we need a formula that allows us to identify whether a cell contains the target text.  We can use the Search() function, like this: =SEARCH("F",A1).  Search returns the position of the first letter in the search string if it is found, otherwise it returns a #Value error.  This works well, but we are not interested in the position of the text, just whether or not it is found.  We also need to deal with the #Value error when the text is not found.  Here's how:


This formula will return TRUE if the text is found, or FALSE if it is not.  Now all we need is a way to highlight the cells containing the search text.  Enter conditional formatting!

Move the cursor to cell A1 and hit Formatting --> Contitional formatting in the menu.  Change the dropdown from "Cell value is" to "Formula is".  Then paste your formula in the formula box and set the background to red.  This will have the effect of setting the cell background to red if the cell contains the text we are looking for.  Hit OK to save.

Now hit the paintbrush button in the toolbar to copy this format to all the other cells.  You should see the cells with the letter F highlighted in red.

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:

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

$str = "hello world!";

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

/* 2. use create_function instead */
$str = preg_replace_callback(
  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, 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.

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

    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: 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:


    var t='YourAssociateID',

    d.writeln('The link is:'+h+'

    d.writeln('Your short affiliate link is:'+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
      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!