Add Scroogle to your search area in Firefox 2.0 Install the 'Scroogle Scraper' search plugin.

code


In my other blog I just wrote about my GPS + Google Maps Mashup.

Here are some details I left out of that entry:

Here is my PHP file for querying the Garmin GPS unit:

class GPSblob
{
	var $lat;
	var $long;
	var $timeStamp;
 
	function GPSblob($lat,$long,$timeStamp)
	{
	$this->lat=$lat;
	$this->long=$long;
	$this->timeStamp=$timeStamp;
	}
	function deltalat($lat)
	{
		return (abs($lat-$this->lat));
	}
	function deltalong($long)
	{
		return (abs($long-$this->long));
	}
}
session_start();
include_once("xmlparser.php");
$threshold=.005;
 
$cmd="c:\gpsrun.bat.lnk";
//this is the command I’m running: 
//"gpsbabel.exe -i garmin,get_posn -f usb: -o kml -F myposition.kml"
$cmdline = "cmd /C $cmd";
$WshShell = new COM("WScript.Shell");
$oExec = $WshShell->Run($cmdline, 0, true);
sleep(1);
$data=file_get_contents("myposition.kml");
 
$xml = new XML_Array($data);
$xmlarray = $xml->_data;
$parsed = split(‘Created ‘,$xmlarray[0][kml][Document][Snippet]);
$timeStamp=$parsed[1];
list($long,$lat,$delete)=
split(",",$xmlarray[0][kml][Document][Folder][Placemark][Point][coordinates]);
 
$blob=new GPSblob($lat,$long,$timeStamp);
 
if (empty($_SESSION[‘blob’]))
{
   $_SESSION[‘blob’] = $blob;
}
else
{
   $previousBlob=$_SESSION[‘blob’];
   $deltalat = $blob->deltalat($previousBlob->lat);
   $deltalong = $blob->deltalong($previousBlob->long);
   $moved=0;
   if (($deltalat>=$threshold)||($deltalong>=$threshold))
   {
   	$moved=1;
   }
   $_SESSION[‘blob’] = $blob;
}
require_once(‘json.php’);
$json = new Services_JSON();
 
$value = array($lat,$long,$timeStamp,$moved);
$output = $json->encode($value);
print($output);

Over on my other site I just posted a blog entry about a Dominos pizza ad campaign where each day they release a word puzzle and if you solve the puzzle you get a link to an eBay auction where the first ten people that day (for only $9.99) can buy pretty cool stuff, like an iPod or a year’s worth of pizza.

The puzzles are one of three forms: Word Jumbles, CryptoQuips or Domino’s Trivia. The Word Jumble is just as it sounds; they scramble the letters of some Domino’s themed sentence around and you get to unscramble it. For example: MOIODSN HITNNYGA SOGE ALED

Here’s the link to my Word Jumble solver Domino’s Pizza Anything Goes Deal Helper Script

And here is the code:

if (isset($_REQUEST["word_jumble"])&&$_REQUEST["word_jumble"]!=‘’)
{
 
$vocabArray=array(‘2-liter’,‘a’,…,‘Vine-Ripened’,‘wings’);
 
$lookuptable=array();
foreach($vocabArray as $vocab)
{
  $str=strtoupper($vocab);
  $tempArray= array();
  for($i=0; $<strlen($str); $i++)
    {
      $tempArray[]=$str[$i];
    }
  sort($tempArray);
  $tempStr=implode(‘’,$tempArray);
  $lookuptable[$tempStr]=$vocab;
}
$wordArray=explode(‘ ‘,$word_jumble);
foreach ($wordArray as $word)
{
  $str=strtoupper($word);
  $tempArray= array();
  for($i=0; $<strlen($str); $i++)
    {
      $tempArray[]=$str[$i];
    }
  sort($tempArray);
  $tempStr=implode(‘’,$tempArray);
  $unscrambled = ($lookuptable[$tempStr]==‘’)?‘?????’:$lookuptable[$tempStr];
  echo($word." = ".$unscrambled."n ");
}

In my other blog (the coolest site in Utah), I just wrote about the Mozy Programming Contest. On the Mozy Contest Site, they list a sample problem:

We are looking for sequences of n > 0 integers where the absolute values of the differences of successive elements are included in the set of numbers 1 through n - 1. For instance,

4 1 2 3

is a match, because the absolute differences are 3, 1, and 1, respectively where n is 4.

8 6 2

is not a match, because the absolute differences are 2 and 4 respectively where n is 3.

The definition implies that any sequence of a single integer is a match. Write a program to determine whether each of a number of sequences is a match.

Input

Each line of input contains a sequence of n integers where n < 1024.

Output

For each line of input generate a line of output printing ‘match’ or ‘not a match’.

Here’s my php solution:

$fp = fopen ($argv[1],"r");
while($line=fgets($fp,4092))
{
$numbersArray = split(" ",$line);
$output="match";
$size=count($numbersArray);
for ($i=0;$i<($size-1);$i++)
{
$difference = abs($numbersArray[$i]-$numbersArray[$i+1]);
if ($difference>($size-1)||!$difference)
{
$output = "not a match";
break;
}
}
echo $output."n";
}
fclose($fp);

« Previous Page

Send to a friend * Print this page * Join the club * Talk with my robot * Advertise here * Search this Site * Donate * Link to me


Web hosting by Utah Hub *  Powered by CreativeTap *  In association with Segomo
Unless otherwise noted, Copyright 2004-2006, Ryan Byrd. All Rights Reserved.
Ryan Byrd dot net -- probably the coolest site in Utah