removing demo files

This commit is contained in:
Joshua Seigler 2016-06-30 23:41:10 -04:00
parent 9f955259fa
commit 04369adbb3
4 changed files with 0 additions and 283 deletions

View file

@ -1,74 +0,0 @@
<?php
// Adapted for The Art of Web: www.the-art-of-web.com
// Based on PHP code by Dennis Pallett: www.phpit.net
// Please acknowledge use of this code by including this header.
// Updated to include and use last-modified and etag headers
// location and prefix for cache files
define('CACHE_PATH', "/tmp/cache_");
// how long to keep the cache files (seconds)
define('CACHE_TIME', 5 * 60);
// return location and name for cache file
function cache_file()
{
return CACHE_PATH . md5('buffer'.$_SERVER['REQUEST_URI']);
}
// display cached file if present and not expired
function cache_display()
{
$file = cache_file();
// check that cache file exists and is not too old
if(!file_exists($file)) return;
$last_modified_time = filemtime($file);
if($last_modified_time < time() - CACHE_TIME) return;
$etag = md5_file($file);
// always send headers
header("Last-Modified: ".gmdate("D, d M Y H:i:s", $last_modified_time)." GMT");
header("Etag: $etag");
header("Expires: ".gmdate("D, d M Y H:i:s", $last_modified_time + CACHE_TIME)." GMT");
// tell any caches that I really mean it with these other headers
header("Cache-Control: max-age=".CACHE_TIME.", must-revalidate");
// exit if not modified
if (@strtotime($_SERVER['HTTP_IF_MODIFIED_SINCE']) == $last_modified_time ||
@trim($_SERVER['HTTP_IF_NONE_MATCH']) == $etag) {
header("HTTP/1.1 304 Not Modified");
exit;
}
// if so, display cache file and stop processing
readfile($file);
exit;
}
// write to cache file
function cache_page($content)
{
if(false !== ($f = @fopen(cache_file(), 'w'))) {
fwrite($f, $content);
fclose($f);
}
$last_modified_time = time();
$etag = md5_file('buffer'.$file);
// always send headers
header("Last-Modified: ".gmdate("D, d M Y H:i:s", $last_modified_time)." GMT");
header("Etag: $etag");
header("Expires: ".gmdate("D, d M Y H:i:s", $last_modified_time + CACHE_TIME)." GMT");
return $content;
}
// execution stops here if valid cache file found
cache_display();
// enable output buffering and create cache file
ob_start('cache_page');
?>

View file

@ -1,93 +0,0 @@
<!DOCTYPE html>
<html lang="en-US">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, minimum-scale=1.0, maximum-scale=1.0">
<title>NeatCharts demo</title>
<style>
main {
-webkit-columns: 800px 2;
-moz-columns: 800px 2;
columns: 800px 2;
}
section {
display: inline-block;
width: auto;
max-width: 800px;
padding: 10px;
vertical-align: top;
}
</style>
</head>
<body>
<header>
<h1>NeatCharts demo</h1>
</header>
<main>
<section>
<h2>Poloniex Dash/BTC Price</h2>
<img src="poloniex-dash-btc.php" alt="Poloniex Dash/BTC price">
</section>
<section>
<h2>Fake Stock Market Data</h2>
<?php
ini_set('display_errors', 1);
require '../src/NeatCharts/LineChart.php'; // just use composer instead of this
// fake up some stock market data
$chartData = [];
$offset = 100 * (rand()/getRandMax())**4;
$scale = 100 * (rand()/getRandMax())**2;
$volatility = 0.5 * (rand()/getRandMax())**3;
for ($n = 0, $current = $offset + 0.5 * $scale; $n < 96; $n++) {
$current -= $offset;
$current *= 1 + $volatility * (rand()/getRandMax() - 0.5);
$current += $offset;
$chartData[$n] = $current;
}
$stockChart = new NeatCharts\LineChart($chartData, [
"width"=>500,
"height"=>150,
"fontSize"=>10
]);
print $stockChart->render();
?>
</section>
<section>
<h2>Monotonically Smoothed Chart</h2>
<?php
$chartData = [];
$start = 100 * (rand()/getRandMax())**3;
$volatility = rand()/getRandMax() + 0.01;
$velocity = (rand()/getRandMax() - 0.5);
$acceleration = 0.1 * (rand()/getRandMax())**2;
for ($n = 0, $current = $start; $n < 12; $n++) {
$velocity *= 0.5;
$velocity += $acceleration * 2 * (rand()/getRandMax() - 0.5);
$current += $velocity;
$chartData[$n] = $current;
}
$tempChart = new NeatCharts\LineChart($chartData, [
"width"=>700,
"height"=>400,
"lineColor"=>"#D00",
"labelColor"=>"#777",
"smoothed"=>true
]);
print $tempChart->render();
?>
</section>
</main>
</body>
</html>

View file

@ -1,66 +0,0 @@
<?php
//ini_set('display_errors', 1);
/*
Display a 7 day Dash/BTC chart from Poloniex as a PNG (converted from SVG by imageMagick)
requires the imagick module be installed
*/
header("Content-Type: image/png");
header('Content-Disposition: inline; filename="Dash-24h-chart-' . date('Y-m-d\THisT') . '.png"');
require 'buffer.php';
require '../src/NeatCharts/LineChart.php'; // really just use composer instead
function getJson($url) {
if (empty($url)) {
trigger_error('Missing or empty JSON url');
}
$ch = curl_init($url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_HTTPHEADER, array('Accept: application/json'));
curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 5);
curl_setopt($ch, CURLOPT_TIMEOUT, 3);
// curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, true);
// curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 2);
// curl_setopt($ch, CURLOPT_CAINFO, getcwd() . "/VeriSignClass3PublicPrimaryCertificationAuthority-G5.pem");
$result = curl_exec($ch);
$result = json_decode($result) or trigger_error('Couldn\'t parse JSON');
return $result;
}
$yesterday = time() - (7 * 24 * 60 * 60);
$poloniex_url = 'https://poloniex.com/public?command=returnChartData&currencyPair=BTC_DASH&start=' . $yesterday . '&end=9999999999&period=' .
//300 //5 min
//900 //15 min
1800 //30 min
//7200 //3h
//14400 //6h
//86400 //1d
;
$last24h = getJson($poloniex_url);
$chartData = [];
foreach ($last24h as $item) {
$chartData[$item->date] = $item->weightedAverage;
}
$poloniexChart = new NeatCharts\LineChart($chartData, [
'width'=>800,
'height'=>200,
'lineColor'=>"#1C75BC", // Dash blue
'labelColor'=>"#777",
'smoothed'=>false,
'fontSize'=>10
]);
$svg = $poloniexChart->render();
$im = new Imagick();
$im->setBackgroundColor(new ImagickPixel("transparent"));
$im->readImageBlob($svg);
$im->setImageFormat("png32");
echo $im;
$im->clear();
$im->destroy();

View file

@ -1,50 +0,0 @@
<?php
//ini_set('display_errors', 1);
Header('Content-type: image/svg+xml; charset=utf-8');
Header('Content-Disposition: inline; filename="Dash-24h-chart-' . date('Y-m-d\THisT') . '.svg"');
require 'buffer.php';
require '../src/NeatCharts/LineChart.php'; // really just use composer instead
function getJson($url) {
if (empty($url)) {
trigger_error('Missing or empty JSON url');
}
$ch = curl_init($url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_HTTPHEADER, array('Accept: application/json'));
curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 5);
curl_setopt($ch, CURLOPT_TIMEOUT, 3);
// curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, true);
// curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 2);
// curl_setopt($ch, CURLOPT_CAINFO, getcwd() . "/VeriSignClass3PublicPrimaryCertificationAuthority-G5.pem");
$result = curl_exec($ch);
$result = json_decode($result) or trigger_error('Couldn\'t parse JSON');
return $result;
}
$yesterday = time() - (24 * 60 * 60);
$poloniex_url = 'https://poloniex.com/public?command=returnChartData&currencyPair=BTC_DASH&start=' . $yesterday . '&end=9999999999&period=' .
//300 //5 min
900 //15 min
//1800 //30 min
//7200 //3h
//14400 //6h
//86400 //1d
;
$last24h = getJson($poloniex_url);
$chartData = [];
foreach ($last24h as $item) {
$chartData[$item->date] = $item->weightedAverage;
}
$poloniexChart = new NeatCharts\LineChart($chartData, [
'width'=>800,
'height'=>250,
'lineColor'=>"#1C75BC", // Dash blue
'labelColor'=>"#777",
'smoothed'=>false
]);
print $poloniexChart->render();