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.


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


  • 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…

# smith number detector - TWS 1-12-13

def detectSmith(num):
  if(sumFactors(num) == sumDigits(num)):
    return True
    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)
      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
    # should never reach this
    return num

def factors(num):
  primeFactorList = []

  factor = lowestPrimeFactor(num)
  currentNum = num

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

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

  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):
    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’.

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.

# Tanner Stokes - 8-23-12
# Search contents of files

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

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

Some derpy numbers

Now that this site has basically turned into ‘herp derp‘ central, I thought I’d post some numbers up regarding downloads. Running this command on my Apache access logs provided me with the download numbers for each browser version (in this case Firefox):

cat access.log | grep xpi | colrm 16 | sort | uniq | wc -l


Note: This method isn’t exactly super precise, it would only count once per IP, but it does the job. It also doesn’t account for other sites like download.com.

As of this post:

Chrome: 4722
Firefox: 2564
Safari: 531
Opera: 278

Update: 7-12-12

Shortly after creating this post I got picked up by Boing Boing, Gizmodo, and Reddit. New numbers:

Chrome: 8026
Firefox: 4025
Safari: 919
Opera: 415

Go Herp Derp! 

Herp Derp updated

I got around to fixing some annoying bugs in Herp Derp tonight:

  • When loaded via HTTP Secure (HTTPS) Herp Derp now works (thanks for reminding me @Funshine__Bear)
  • Firefox no longer freaks out when there is only one comment
  • YouTube Feather Mode is now supported (thanks @_sjs)

The latest version is available for all browsers and can be downloaded here.