Splitting a string in Google Spreadsheet

Here is how to split a string into tokens, then grab each token for each column in Google Spreadsheet.

So we start with the string.

Then we do =index(split(A2, ” “), 1, 1). Basically, split will give us an array (or range). Then we select the first row (there is just one resulting row), and we select the first column (there are 3 resulting columns in our example).

Similarly we do =index(split(A2, ” “), 1, 2) to pick the second token.

Lastly do =index(split(A2, ” “), 1, 3) to pick the 3rd token.

This is similar to explode in PHP, and string split in Python. =)

Get url parameters with javascript

There are times you will need to grab url parameters, then update some of your form components accordingly. In my case, it was a search form that passes search terms using GET.

I largely got the javascript function from here, but I added a few lines to decode/unescape values.

Here it is.

function getUrlParameter(sParam) {
  var sPageURL = window.location.search.substring(1);
  var sURLVariables = sPageURL.split('&');
  for (var i = 0; i < sURLVariables.length; i++) {
    var sParameterName = sURLVariables[i].split('=');
    if (sParameterName[0] == sParam) {
      var val = sParameterName[1];
      //console.log("before: " + val)
      val = decodeURIComponent(val);
      val = val.replace(/\+/g, " ");
      //console.log("after: " + val)
      return val;
    }
  }
};

$(function() {
  // pre-set our search control components based on the URL params
  $("#search_text").val(getUrlParameter("search_text"));
  // more fields...
});

Install MySQLdb on osx

Here is the error message I got.

ImportError: No module named MySQLdb

Below is how you install such module for your python script.

brew install mysql
brew install python
sudo easy_install pip
sudo pip install MySQL-python

Depending on your file permissions at various directories, you can determine the use of sudo.

vis.js

Here is a fun graphing library to play with! =)

Vis.js is a dynamic, browser based visualization library. The library is designed to be easy to use, to handle large amounts of dynamic data, and to enable manipulation of and interaction with the data. The library consists of the components DataSet, Timeline, and Graph.