Páginas

2011/05/28

How to create a compatibility list with google spreadsheet?

http://dpspemu.blogspot.com/p/compatibility.html

HOW THIS WORKS?


This is a google spreadsheet with a form vinculated to a sheet

The other sheet gets the information of the form results and locates the max version per gameId showing only the results for the lastests version of the emulator per each game. After that it order the list with the date added descending so it will show first the lastest updates. Also it generates a chart with the Status column.

It should be updated automatically every 5 minutes.

HOW DID YOU DO THAT?


I have made the following function for google spreadsheets. Maybe it is too simple, but it is enough for creating a compatibility list successfully.

function groupByAndMaxSorted(list, uniqueColumn, maxColumn, sortColumn) {
  var list2 = [];
  for (var n = 0; n < list.length; n++) {
    var row = list[n];
    var prevRow = list2[row[uniqueColumn]];
    var prevMax = (prevRow !== undefined) ? prevRow[maxColumn] : undefined;
    var currentMax = row[maxColumn];
    if (prevMax === undefined || currentMax > prevMax) {
      list2[row[uniqueColumn]] = row;
    }
  }
  var list3 = [];
  for (var k in list2) {
    list3.push(list2[k]);
  }
  list3.sort(function(a, b) {
    return b[sortColumn] - a[sortColumn];
  });
  return list3;
}

2011/05/09

PHP: WHICH with PHP on Windows

Which is a very useful linux command that allows you to determine the absolute path of an executable that is contained in path. Futhermore if the executable to launch is inside several folders on the path, it will show which one of those has priority and would be executed.

In order to be able to execute insde a console, you only have to create the which.bat file with the contents I included here and put it on the PHP interpreter's folder. Of course, you will need to add that folder to the PATH enviorement variable.

which.bat
@"%~dp0\php.exe" -r"$cmd_to_check = $argv[1]; $exts = array('exe', 'bat', 'cmd'); foreach (explode(';', getenv('PATH')) as $path) { foreach ($exts as $ext) { $file = $path . '\\' . $cmd_to_check . '.' . $ext; if (is_file($file)) { echo $file; exit; } } } echo $test . ' not found';" %*

Expanded code:
<?php
$cmd_to_check = $argv[1];
$exts = array('exe', 'bat', 'cmd');
foreach (explode(';', getenv('PATH')) as $path) {
    foreach ($exts as $ext) {
        $file = $path . '\\' . $cmd_to_check . '.' . $ext;
        if (is_file($file)) {
            echo $file;
            exit;
        }
    }
}

Usage:
C:\>which php
c:\php\php.exe