Javascript Code

Quicksort

function quick_sort(arry, col, cols, lo_par, hi_par)
{
  var lo = lo_par;
  var hi = hi_par;
  var mid = 0;
  var temp = 0;
  if (col>=cols) col=0;
  if (hi_par > lo_par)
  {
    mid = arry[Math.floor((lo_par+hi_par)/2)*cols+col];
    while (lo<=hi)
    {
      while (lo<hi_par && arry[lo*cols+col]<mid)
        lo++;
      while (hi>lo_par && arry[hi*cols+col]>mid)
        hi--;
      if (lo<=hi)
      {
        for (var i=0; i<cols; i++)
        {
          temp = arry[lo*cols+i];
          arry[lo*cols+i] = arry[hi*cols+i];
          arry[hi*cols+i] = temp;
        }
        lo++;
        hi--;
      }
    }
    if (lo_par<hi) quick_sort(arry, col, cols, lo_par, hi);
    if (lo<hi_par) quick_sort(arry, col, cols, lo, hi_par);
  }
  return arry;
}
 
// Array sort routine (col=column to sort on; cols=total number of columns)
function sort_array(arry, col, cols)
{
  sorted_arry = new Array(arry.length);
  sorted_arry = quick_sort(arry, col, cols, 0, arry.length/cols - 1);
  return sorted_arry;
}
 
// Serialize array into a single string
function serialize(arry)
{
  var str = "";
  for (var i=0; i<arry.length; i++)
  {
    str+=arry[i]; // add element
    if (i<arry.length-1) str+=","; // comma separated list of elements
  }
  return str;
}

Bookmarklets

  • Design:
javascript:function%20fnStartDesign(sUrl)%20{var%20nScript%20=%20document.createElement('script');nScript.setAttribute('language','JavaScript');nScript.setAttribute('src',sUrl);document.body.appendChild(nScript);}fnStartDesign('http://www.sprymedia.co.uk/design/design/media/js/design-loader.js');
  • Bookmarks - here: simple mediamatic
javascript:(function(){var%20a=window,b=document,c=encodeURIComponent,d=a.open(%22http://openci01.test.mediamatic.nl/module/PubSub/subscribe?httpurl=%22+c(b.location));a.setTimeout(function(){d.focus()},300)})();
 
wiki/javasniplets.txt · Last modified: 01.07.2008 12:51 by rgareus