JasonWyatt

This blog is full of stuff, and things.

Find my resume.

permalink

Generate Hashed Passwords and Salts With Python

Here’s a code snippet you can use to generate hashed passwords and salts for those passwords, as well as verify an input password against a hashed password and salt:

Usage

>>> hashed, salt = hash_password('password123')
>>> print hashed
7845386cd6e73893d12ded643b3bbffe9dc367daa7e52....
>>> print salt
812d47da9c41400e8f07495020a17f92
>>> verify_password('password123', hashed, salt)
True

permalink

Easy Backup of MongoLab Databases for Heroku

For WODWatcher, I needed an easy-to-use script for backing up my MongoLab database. I wrote this script to be used from within my project directory, it should work for your app directory easily as well.

In addition to defaulting to Heroku+MongoLab, you can also pass it any valid MongoDB URI.

For Heroku+MongoLab:

home/my_heroku_project$ ./mongobackup.py [-o output directory]

For general MongoDB URLs:

home$ ./mongobackup.py -u mongodb://username:password@hostname:port/db [-o output directory]

permalink UI Faux Pas: Youtube.
Looks like there’s a bug in the embedded player’s timeline. When I chose to play another video from the end-screen of a previous one, the timeline registered the start-time of the next video as the end-time of the previous one.  It did this until the advertisement was finished.

UI Faux Pas: Youtube.

Looks like there’s a bug in the embedded player’s timeline. When I chose to play another video from the end-screen of a previous one, the timeline registered the start-time of the next video as the end-time of the previous one. It did this until the advertisement was finished.

permalink UI Faux Pas: Hipmunk + Amtrak

UI Faux Pas: Hipmunk + Amtrak

permalink

An Update to jQSlickWrap

Earlier today, @AlmogBaku submitted the first ever pull request to the github project for jQSlickWrap. He added the ability to have the image rendered as the background-image of the parent div by its src parameter, as opposed to using a data-URI. I think this approach may be better than the data-URI mechanism I was using before, so maybe it’ll become the default in the future.

Additionally, while testing the pull request I realized that there was a bug with how the height of parent divs was being set (to make sure the entire image showed.) If you were to resize the window after jQSlickWrap did its business a couple of things could happen: the image could get chopped-off, or the text could overflow the containing div. This behavior has been corrected.

Thanks to these changes, I’ve upped the version number of jQSlickWrap to 0.2. You can read more about the project and download it from the jQSlickWrap home page. These are the first substantial changes to the code since it was released in 2009!

It really is something special to receive a pull request from a total stranger on a project you created.

permalink

I’m Joining Republic Wireless! (Bandwidth.com)

Working at TransLōc for nearly two and a half years has been a fantastic experience:

  • I’ve learned a lot about working at a web company, especially one which deals with huge amounts of data and interesting user interface / interaction design and development challenges.
  • I’ve been able to interact directly with clients in many capacities: support, usability testing, and even a bit of technical sales support.
  • I count the development team amongst my closest friends, and I get along really well with the entire company (all 20 of us.)

TransLōc has been great, but it’s time for me to move on to something new. If you’re a front-end developer and you’re looking for a cool place to work, TransLōc will be back-filling my position. Check out the job description and apply!

Joining Bandwidth.com

I’m super excited to announce I’ll be joining Bandwidth.com as a UX Developer for their exciting new product: Republic Wireless.

I’ll be working on various things with the team: one of which is an advanced customer service portal used by tens (to hundreds) of thousands of users to find answers to questions about the service and collaborate with other users when an answer can’t be easily found. I will blog about the other projects when I know more, and am able.

My start date is Halloween! (October 31st)

permalink

Algorithms in JavaScript: Binary Search

I’m going to start a new blog series: Algorithms in JavaScript. This first article will discuss the implementation of “Binary Search”.

The Problem

You’ve got a huge array of sorted values and you need to find the location in that array of a particular value (or whether that value exists within the list at all.)

Brute Force (And Why It Sucks)

The simplest approach to finding the location of your target value within a sorted list of values is to iterate through the list one-by-one until you:

  1. find the target value (returning the location when found), or
  2. find a value greater-than the target value (returning null because this means the target can’t possibly exist in the array.)

Why does it suck? Consider the case when you’re given an array containing a million elements and your target is nowhere to be found: you’ll have to look at every element in the array! In computer science parlance, this worst-case situation of having to look at every element in the array means that the algorithm is O(n) (read “Big-Oh of n”) and its run-time will increase linearly with the size of the search array.

“Binary” Searching

Instead of looking at every element in the array from lowest to highest: let’s look at the middle of the array first and if it’s greater than our target we’ll search in the first half of the array, if it’s lesser than the target we can search in the second half of the array, and if it’s equal to the target - our answer is the middle index. You keep repeating this pattern of cutting the array in half until you either find the target or run out of array (and hence: didn’t find the target).

If you’re still confused, think of it like the days before the internet when you would have to “let your fingers do the walking” to search a phone book for your friend’s number. You’d crack the book open somewhere in the middle and look at one of the names on the page. If your friend’s name comes before that name you’ll look in the chunk of pages to the left of the current page, if it comes after that name you will look in the other chunk of pages, and if it’s pretty close to the name you found at first - you’re in luck and just have to scan the current page for your friend (using binary search again!)

Because we’re repeatedly cutting our search space in half with each iteration, and we’re only evaluating the endpoints and median of the space each time we can say that Binary Search performs in O(log n) time (this series won’t deal with proving this type of thing, but you can find plenty of proofs online with a quick visit to google.) What this means is that even when searching within a million-item array, we’ll only end up iterating about twenty times at the worst case. That’s 50,000 times faster than the worst case of the brute-force situation!

Pseudocode

function search(array, target, start, end):
    if start > end:
        return NOT_FOUND
    if array[start] is target:
        return start
    if array[end] is target:
        return end
    middle = ( start + end ) / 2
    if array[middle] > target:
        return search(array, target, start+1, middle)
    if array[middle] < target:
        return search(array, target, middle, end-1)
    return middle

You would call the above function with start = 0 and end = array.length-1.

Binary Search in JavaScript

The following code is also available with a demo application on jsbin.

function binarySearch( sortedValues, target ){
  // summary:
  //    Performs a binary search on an array of sorted 
  //    values for a specified target. 
  // sortedValues: Array
  //    Array of values to search within.
  // target: String|Number
  //    Item to search for, within the sortedValues array.
  // returns:
  //    Number or null. The location of the target within
  //    the sortedValues array, if found. Otherwise returns 
  //    null.
  
  // define the recursive function.
  function search( low, high ) {
    // If the low index is greater than the high index, 
    //  return null for not-found. 
    if ( low > high ) {
      return null;
    }
    
    // If the value at the low index is our target, return 
    //  the low index.
    if ( sortedValues[low] === target ){
      return low;
    }
    
    // If the value at the high index is our target, return
    //  the high index.
    if ( sortedValues[high] === target ){
      return high;
    }
    
    // Find the middle index and median element.
    var middle = Math.floor( ( low + high ) / 2 );
    var middleElement = sortedValues[middle];
    
    // Recursive calls, depending on whether or not the 
    //  middleElement is less-than or greater-than the 
    //  target.
    // Note: We can use high-1 and low+1 because we've 
    //  already checked for equality at the high and low 
    //  indexes above.
    if ( middleElement > target ) {
      return search(low+1, middle);
    } else if ( middleElement < target ) {
      return search(middle, high-1);
    }
    
    // If middleElement === target, we can return that value.
    return middle;
  }
  
  // Start our search between the first and last elements of 
  //  the array.
  return search(0, sortedValues.length-1);
}

What other algorithms would you like to see discussed and implemented with JavaScript?

permalink

CrossFit Invoke Paleo Challenge - Day 29

I finally got Mike Wooten into the gym to try it out, he may actually consider joining! Yesterday was a killer WOD:

5 Rounds

  • 5 Thrusters @ 95lbs
  • 200m run with 20lb medicine ball
  • 12 box jumps @ 24”

Paleo Challenge Points So Far

Date Strict WOD Sleep Mobility Alcohol Cheat Veggies Water Coffee
7/2/12 3 2 2 7
7/3/12 3 2 2 7
7/4/12 3 2 2 7
7/5/12 3 2 2 7
7/6/12 3 2 2 7
7/7/12 3 2 1 6
7/8/12 3 2 1 6
7/9/12 3 2 2 -2 5
7/10/12 3 2 2 7
7/11/12 3 2 1 6
7/12/12 3 2 2 7
7/13/12 3 2 2 7
7/14/12 3 2 2 7
7/15/12 3 2 5
7/16/12 3 2 2 7
7/17/12 3 2 2 7
7/18/12 3 2 2 7
7/19/12 3 2 2 7
7/20/12 3 2 2 7
7/21/12 3 2 -2 3
7/22/12 3 2 1 6
7/23/12 3 2 1 6
7/24/12 3 2 2 7
7/25/12 3 2 2 7
7/26/12 3 2 2 7
7/27/12 3 2 2 7
7/28/12 3 2 1 6
7/29/12 3 2 1 6
7/30/12 3 2 2 7
Bonus Points (Bring a Friend to Invoke x 5) 15
Total Challenge Points 204
permalink

CrossFit Invoke Paleo Challenge - Days 26, 27 & 28

Though I didn’t get to go to the send-off for Christmas on Saturday, this weekend was all kinds of fun. Nathan and I finished our check-out dives for SCUBA certification! I’m looking forward to being able to finally dive with Paula - she’s been trying to get me to certify ever since we started dating.

Paleo Challenge Points So Far

Date Strict WOD Sleep Mobility Alcohol Cheat Veggies Water Coffee
7/2/12 3 2 2 7
7/3/12 3 2 2 7
7/4/12 3 2 2 7
7/5/12 3 2 2 7
7/6/12 3 2 2 7
7/7/12 3 2 1 6
7/8/12 3 2 1 6
7/9/12 3 2 2 -2 5
7/10/12 3 2 2 7
7/11/12 3 2 1 6
7/12/12 3 2 2 7
7/13/12 3 2 2 7
7/14/12 3 2 2 7
7/15/12 3 2 5
7/16/12 3 2 2 7
7/17/12 3 2 2 7
7/18/12 3 2 2 7
7/19/12 3 2 2 7
7/20/12 3 2 2 7
7/21/12 3 2 -2 3
7/22/12 3 2 1 6
7/23/12 3 2 1 6
7/24/12 3 2 2 7
7/25/12 3 2 2 7
7/26/12 3 2 2 7
7/27/12 3 2 2 7
7/28/12 3 2 1 6
7/29/12 3 2 1 6
Bonus Points (Bring a Friend to Invoke x 5) 10
Total Challenge Points 192