Blog

eXorithm – Execute Algorithm: View / Run Algorithm calendar_month

function calendar_month ($month$year
{
  $start = getdatemktime(0,0,0,$month,1,$year));
  $end = getdatemktime(0,0,0,$month+1,0,$year));
  
  $end_date = $end'mday'];
  $start_day = $start'wday'];
  
  $html = "<table border=1><tr>
  <th width=100>Sunday</th>
  <th width=100>Monday</th>
  <th width=100>Tuesday</th>
  <th width=100>Wednesday</th>
  <th width=100 >Thursday</th>
  <th width=100>Friday</th>
  <th width=100>Saturday</th>
  </tr>n"
  
  $date = 0;
  $week_day = 0;
  while ($date$end_date) {
    if ($week_day==0)
      $html .= "<tr>n"
    
    if ($date==0)
      if ($week_day==$start_day
        $date++;
    else
      $date++;
  
    if ($date==0)
      $html .= "<td></td>"
    else
      $html .= "<td height=85 valign=top>$date</td>"
    
    $week_day = ($week_day+1) % 7;
    
    if ($week_day==0)
      $html .= "</tr>n"
  }
  
  if ($week_day!=0) {
    $html .= str_repeat"<td></td>", 7-$week_day);
    $html .= "</tr>n"
  }
  
  $html .= "</table>"
  return $html

Show Address

<?php

/**
 * show_address
 *
 * Given an address, show the location on a map.
 *
 * @version 0.6
 * @author Contributors at eXorithm
 * @link /algorithm/view/show_address Listing at eXorithm
 * @link /algorithm/history/show_address History at eXorithm
 * @license /home/show/license
 *
 * @param mixed $address The address to find.
 * @return array latitude/longitude
 */
function show_address($address='The White House
1600 Pennsylvania Ave NW
Washington, DC
20500')
{
	$data = file_get_contents("http://maps.googleapis.com/maps/api/geocode/json?address=".urlencode($address)."&sensor=false");
	$obj = json_decode($data);
	if ($obj) {
		if (isset($obj->results[0]->geometry->location)) {
			$loc = $obj->results[0]->geometry->location;
			return array('latitude'=>$loc->lat, 'longitude'=>$loc->lng);
		} else {
			throw new Exception('Lookup failed and/or address does not exist!');
		}
	} else {
		throw new Exception('Lookup failed and/or address does not exist!');
	}
}

?>

eXorithm – Execute Algorithm: View / Run Algorithm sort_multi_array

function sort_multi_array ($array$key
{
  $keys = array();
  for ($i=1;$ifunc_num_args();$i++) {
    $keys$i-1] = func_get_arg$i);
  }
  
  // create a custom search function to pass to usort
  $func = function ($a$buse ($keys) {
    for ($i=0;$icount$keys);$i++) {
      if ($a$keys$i]] != $b$keys$i]]) {
        return ($a$keys$i]] < $b$keys$i]]) ? -1 : 1;
      }
    }
    return 0;
  };
  
  usort$array$func);
  
  return $array

Overlay Image

<?php

/**
 * overlay_image
 *
 * Overlay a transparent image on top of another image.
 *
 * @version 0.2
 * @author Contributors at eXorithm
 * @link /algorithm/view/overlay_image Listing at eXorithm
 * @link /algorithm/history/overlay_image History at eXorithm
 * @license /home/show/license
 *
 * @param resource $base (GD image) 
 * @param resource $image (GD image) 
 * @return mixed
 */
function overlay_image($base=null,$image=null)
{
	$h = imagesy($image);
	$w = imagesx($image);
	
	imagealphablending($base, true);
	imagesavealpha($base, true);
	imagecopy($base, $image, 0, 0, 0, 0, $w, $h);
	return $base;
}

?>

eXorithm – Execute Algorithm: View / Run Algorithm equilateral_shape

function equilateral_shape ($radius$sides$color
{
  // blank image
  $image = image_create_alpha$radius*2+4, $radius*2+4);
  
  // create the color
  $r  = hexdecsubstr$color, 0, 2));
  $g  = hexdecsubstr$color, 2, 2));
  $b  = hexdecsubstr$color, 4, 2));
  $color = imagecolorallocate$image$r$g$b);
  
  // The fudge factor is only used to rotate the shape so a flat
  // line is at the bottom.
  if (($sides%2)==0) {
    if (($sides/2%2)==0) {
      $fudge = pi()*1/$sides
    } else {
      $fudge = 0;
    }
  } else {
    if ((($sides-1)/2%2)==0) {
      $fudge = pi()*1.5/$sides
    } else {
      $fudge = pi()*0.5/$sides
    }
  }
  
  $x0 = 0;
  $y0 = 0;
  
  // for the number of sides...
  for ($i=0; $i$sides$i++) {
    // compute a point on the perimeter $i/$sides from the beginning
    $x1 = round$radiuscos(2*pi()*$i$sides$fudge)+$radius+2);
    $y1 = round$radiussin(2*pi()*$i$sides$fudge)+$radius+2);
    if ($i==0) {
      // If this is the first point then we can't draw a line yet
      // because we don't have a second set of points to connect to.
      // However, we need we need these points to connect the last
      // set of points to.
      $x0 = $x1
      $y0 = $y1
    } else {
      // draw a line
      imageline$image$x1$y1$x2$y2$color);
    }
    // remember these points
    $x2 = $x1
    $y2 = $y1
  }
  // draw the final line
  imageline$image$x2$y2$x0$y0$color);
  
  return $image

eXorithm – Execute Algorithm: Embed Algorithm stock_ticker


Embed This Algorithm

This page will help you embed the algorithm stock_ticker 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.

symbols
Argument info
background color Argument info
stock color Argument info
price color Argument info
up color Argument info
down color Argument info
speed Argument info
Embed the form Embed only the output