Address Elevation

<?php

/**
 * address_elevation
 *
 * Returns the elevation (in meters) above sea level for an address.
 *
 * @version 0.2
 * @author Contributors at eXorithm
 * @link /algorithm/view/address_elevation Listing at eXorithm
 * @link /algorithm/history/address_elevation History at eXorithm
 * @license /home/show/license
 *
 * @param mixed $address The address to get the elevation for.
 * @return mixed
 */
function address_elevation($address='Denver, Colorado')
{
	// get the lat/long for this address
	$data = file_get_contents("http://maps.google.com/maps/geo?output=csv&q=".urlencode($address));
	$arr = explode(",", $data);
	if (count($arr)>=4) {
		if ($arr[0]==200) {
			// get the elevation for this lat/long
			$data = file_get_contents("http://maps.googleapis.com/maps/api/elevation/xml?sensor=false&locations=".$arr[2].','.$arr[3]);
			$obj = simplexml_load_string($data);
			if ($obj instanceof SimpleXMLElement) {
				$obj = (array) $obj;
				$obj = $obj['result'];
				if ($obj instanceof SimpleXMLElement) {
					$obj = (array) $obj;
					return $obj['elevation'];
				} else {
					throw new Exception('Elevation lookup failed');
				}
			} else {
				throw new Exception('Elevation lookup failed');
			}
		} else {
			throw new Exception('Address lookup failed');
		}
	} else {
		throw new Exception('Address lookup failed');
	}
}

?>

eXorithm – Execute Algorithm: View / Run Algorithm check_domain

function check_domain ($url$white_list$black_list
{
  foreach ($white_list as $re) {
    $re = preg_quote$re);
    $re = str_replace'*''.*'$re);
    
    if (preg_match'|^'$re'$|'$url)) {
      return true;
    }
  }
  
  foreach ($black_list as $re) {
    $re = preg_quote$re);
    $re = str_replace'*''.*'$re);
    
    if (preg_match'|^'$re'$|'$url)) {
      return false;
    }
  }
  
  return true;

eXorithm – Execute Algorithm: View / Run Algorithm constrain_image

function constrain_image ($image, $width, $height, $mode, $border_color, $transparent_border, $never_scale_up
{
  if (!$image
    throw new Exception'Invalid image');
  
  $iwidth = imagesx$image);
  $iheight = imagesy$image);
  
  if ($never_scale_up) {
    if ($width$iwidth && $height$iheight) {
      $mode = 'crop'
    }
    if ($width$iwidth || $height$iheight) {
      if (($mode=='scale') || ($mode=='scale_crop'))
        $mode = 'crop'
    }
  }
  
  // scaling phase
  switch ($mode) {
  
    case 'scale_crop': // scale and crop
      if ($width$iwidth > $height$iheight) {
        $iheight = round$iheight$width$iwidth);
        $iwidth =  $width
      } else {
        $iwidth =  round$iwidth$height$iheight);
        $iheight = $height
      }
      $image2 = image_create_alpha$iwidth, $iheight);
      imagecopyresampled$image2, $image, 0, 0, 0, 0, $iwidth, $iheight, imagesx$image), imagesy$image));
      break
     
    case 'scale_border': // scale and add borders
      if ($width$iwidth < $height$iheight) {
        $iheight = round$iheight$width$iwidth);
        $iwidth =  $width
      } else {
        $iwidth =  round$iwidth$height$iheight);
        $iheight = $height
      }
      $image2 = image_create_alpha$iwidth, $iheight);
      imagecopyresampled$image2, $image, 0, 0, 0, 0, $iwidth, $iheight, imagesx$image), imagesy$image));
      break
      
    case 'scale': // scale
      $image2 = image_create_alpha$width, $height);
      imagecopyresampled$image2, $image, 0, 0, 0, 0, $width, $height, imagesx$image), imagesy$image));
      break
  
    default
      $image2 = $image
  }
  
  // crop / borders phase
  switch ($mode) {
    case 'crop': 
    case 'scale_crop': 
    case 'scale_border': 
      
      $image3 = image_create_alpha$width, $height);
      
      $r  = hexdecsubstr$border_color, 0, 2));
      $g  = hexdecsubstr$border_color, 2, 2));
      $b  = hexdecsubstr$border_color, 4, 2));
      if ($transparent_border
        $border_color = imagecolorallocatealpha$image3, $r, $g, $b, 127);
      else
        $border_color = imagecolorallocatealpha$image3, $r, $g, $b, 0);
      imagefilledrectangle$image3, 0, 0, $width, $height, $border_color);
      
      // x,y to paste to
      $px = ($iwidth$width)   ? round(($width - $iwidth)/2) : 0;
      $py = ($iheight$height) ? round(($height - $iheight)/2) : 0;
      // x,y to start cut from
      $sx = ($iwidth$width)   ? 0 : round(($iwidth - $width)/2);
      $sy = ($iheight$height) ? 0 : round(($iheight - $height)/2);
      // x,y to end cut at
      $ex = ($iwidth$width)   ? $iwidth : $sx$width
      $ey = ($iheight$height) ? $iheight : $sy$height
      imagecopy$image3, $image2, $px, $py, $sx, $sy, $ex, $ey);
      break
      
    default
      $image3 = $image2
  }
  
  return $image3
} 

eXorithm – Execute Algorithm: View / Run Algorithm bubble_sort

function bubble_sort ($array
{
  do {
    $again = false;
    for$ii=0; $ii<(count$array)-1); $ii++) {
      if$array$ii] > $array$ii+1]) {
        $temp = $array$ii];
        $array$ii] = $array$ii+1];
        $array$ii+1] = $temp
        $again = true;
      }
    }
  } while ($again==true);
   
  return $array

eXorithm – Execute Algorithm: View / Run Algorithm primes

function primes ($number_of_primes
{
  $n = $number_of_primes
  $primes = array();
  for$i = 2; ; $i++)
  {
    $is_prime = true;
    for$j = 2; $j < $i$j++)
    {
      if(($i % $j) == 0)
      {
        $is_prime = false;
        break
      }
      if$j > floor$i/2)) break
    }
    if ($is_prime
    {
      $primes[] = $i
      $n--;
    }
    if ($n == 0) break
  }
  return $primes

eXorithm – Execute Algorithm: Embed Algorithm pi_digits


Embed This Algorithm

This page will help you embed the algorithm pi_digits on a page on your own website. Just configure the inputs, then click the generate button to get a snippet of code you can paste onto your site. You have two options.

  1. You can embed the entire form. Users will be able to enter their own arguments, and will need to press the run button to execute the algorithm.
  2. You can add only the output of the algorithm to your website. There will be no argument inputs or run button.
digits
Embed the form Embed only the output