2009 Mac Pro video card upgrade

After upgrading to Yosemite, I noticed that graphics performance was starting to lag a bit on my 2009 Mac Pro while driving two monitors at fairly low resolutions. At one point I had two GT 120s running separate monitors, but after one replacement and two failures, I was back down to one.

GT 120
GT 120

I decided to look into upgrade options and was happy to see that OS X now supports non-EFI video cards. The only catch: You won’t see anything displayed until OS X loads your drivers. Who cares?

I settled on an EVGA GeForce GTX 660 2GB, which Best Buy happened to sell. I can feel the judgement from the hardcore nerds for buying something at Best Buy. Nevertheless, this was much cheaper than trying to buy another GT 120 to replace my second one and offers WAY more power. I don’t game on my Mac – I just want the OS to feel snappy and fluid.

GeForce GTX 660
GeForce GTX 660

Like many powerful cards, the GTX 660 requires the PCIe 6 pin power connector from the power supply or motherboard. I’ve ordered this, but until it gets here, I’ve rigged up an external power source.

Steps to install:

  1. Attach one of these cables to your Mac Pro motherboard OR rig up an external PSU like I did
  2. Insert the new card and attach the other end of the 6 pin PCIe power cable
  3. Put the card retainer back in place, fasten everything down and reassemble
  4. If running an external PSU, make sure it is powered up before powering up the Mac Pro

Thoughts after installation:

  • Why didn’t I do this sooner
  • OS X is silky smooth
  • The fans will ramp up audibly if doing anything intensive in apps that utilize the GPU, but that’s OK
  • Everything just works – no drivers to install
  • My biggest bottleneck is now my disk – an SSD is nextMac About

Heaven Benchmark results:

Mode: 1680×1050 fullscreen on one monitor

Before:

  • FPS: 5.9
  • Score: 148
  • Min FPS: 3.3
  • Max FPS: 11.8

After:

  • FPS: 52.8
  • Score: 1330
  • Min FPS: 8.3
  • Max FPS: 103.3

New GTX 660
New GTX 660
IMG_0801
External PSU 6 pin power cable running through an open slot.
IMG_0802
External PSU

 

Adjusting a blank to provide room for the external power
Adjusting a blank to provide room for the external power cable

IMG_0805 IMG_0809 IMG_0810

Temporary setup
Temporary setup with external power supply. A PSU tester is connected to keep the supply running without being attached to a motherboard.

House analytics

My Dad and I built the alarm system for their house in late 2009. He handled hardware, I did software. From time to time I export the data it collects just for the heck of it, since it’s been running non-stop for years.

The back door at their house has been opened 41,267 since the end of November 2009. That’s kind of surprising to me.

It’s interesting to see some patterns in the graph – it’s how many times the door has been opened per month. You can definitely tell what year I bought my house. :)

Back Door Graph

Mounting partitions contained in a disk image in Linux

Say you have a disk image created using ‘dd’. You want to mount a partition contained on it but you realize it’s not as simple as just mounting the image and exploring the path.

The kpartx utility can help with that:

sudo kpartx -av disk.img

This should have created some partition mappings to /dev/mapper. Now, just mount the correct mapping the same way you would mount anything else. For instance:

sudo mount -t ntfs -o ro,noexec /dev/mapper/loop0p1 mounted

Drawing and connecting nodes with SVG

This is something I created over a year ago and I’ve decided to share the code in case someone finds it useful.

nodes

It’s nothing more than an example of using JavaScript to dynamically add connectable SVG objects.

Usage: 

  • Click a node and drag
  • Double-click to generate a node
  • Click a node, hold down shift, then release over another node to connect

Demo (Should be supported by most modern browsers)

Download ZIP

Detecting Smith numbers

After learning about Smith numbers today I cooked up this script fairly quickly. There are many places where it could be optimized and cleaned up but that wasn’t really the point – I just needed something that was accurate, and I’m pretty sure this is.

It also helped me to learn about the ulimit command after running it with a HUGE number that had taken up about 7GB of swap before I had to kill the process remotely via SSH…


#!/usr/bin/python
# smith number detector - TWS 1-12-13

def detectSmith(num):
  if(sumFactors(num) == sumDigits(num)):
    return True
  else:
    return False

# calculate the sum of the factors
def sumFactors(num):
  factorList = factors(num)
  sum = 0

  for factor in factorList:
    if factor > 9:
      # if a number (base ten) has multiple digits it has to be broken down
      sum = sum + sumDigits(factor)
    else:
      sum = sum + factor

  return sum

# sum the digits in a number with two or more
def sumDigits(num):
  sum = 0  

  if num > 9:
    while num > 9:
      sum = sum + num % 10
      num = num / 10
    sum = sum + num
    return sum
  else:
    # should never reach this
    return num

def factors(num):
  primeFactorList = []

  factor = lowestPrimeFactor(num)
  currentNum = num

  while factor != -1:
    primeFactorList.append(factor)
    currentNum = currentNum / factor
    factor = lowestPrimeFactor(currentNum)

  if(currentNum != num):
    # preventing returning the number passed in
    primeFactorList.append(currentNum)

  return primeFactorList

def lowestPrimeFactor(num):
  for x in range(2, (num / 2) + 1):
    if(num % x == 0):
      return x
  return -1

for number in range(1, 1000):
  if(detectSmith(number)):
    print "The number", number, "is a Smith number."

Ubuntu, PHP, S3, and AWS SDK2 Example

A super quick, super simple little example of how to get started with the AWS SDK2 for PHP. It connects to the S3 service with your credentials and checks to see if a file exists.

  1. Assuming you already have a LAMP setup, you may need to install php-pear:
    sudo apt-get install php-pear
  2. Add the AWS channel and auto discover dependencies:
    pear channel-discover pear.amazonwebservices.com
    pear -D auto_discover=1 install pear.amazonwebservices.com/sdk
  3. Download the .phar file here and throw it on your server in this script’s directory (for this example).
  4. Replace the items in brackets and run the script. The [OBJECT KEY] is just the name of the file, so ‘mypicture.jpg’ in the root of the bucket would have the key ‘mypicture.jpg’.
 <?php

require 'aws.phar';

use Aws\Common\Aws;

$aws = Aws::factory(array(
   'key' => '[KEY HERE]',
   'secret' => '[SECRET HERE]'
));

$client = $aws->get('s3');

echo $client->doesObjectExist('[BUCKET NAME]', '[OBJECT KEY]');

?>

You’ll get back the boolean response of that call (assuming it makes it that far without error). Refer to the API documentation for the other methods and their responses.

A simple Linux content search script

A simple script I use for work to search the contents of files. It just wraps up ‘find’ and ‘grep’ to recursively search and display the location of the file.

#!/bin/bash
# Tanner Stokes - 8-23-12
# Search contents of files

if [ -z "$1" ] || [ -z "$2" ]
then
echo "Usage: csearch \"filetype\" \"content\""
echo "ex: csearch \"*.php\" \"my_function()\""
exit 1
fi

find . -name "$1" -exec grep -Hn "$2" {} \;