Skip to content

Instantly share code, notes, and snippets.

@uu59
Last active December 14, 2015 20:19
Show Gist options
  • Save uu59/5143074 to your computer and use it in GitHub Desktop.
Save uu59/5143074 to your computer and use it in GitHub Desktop.
$ phantomjs ./ec2.js ./config.json
{
"t1.micro": 0.5, // 0.5 * 24 hours * 365 days / 12 month
"m1.small": 1
}
/*jshint evil: true */
/*global require,phantom,jQuery*/
var page = require('webpage').create(),
system = require('system'),
fs = require("fs")
;
var file = system.args[1];
if(!file){
console.log("Usage: " + system.args[0] + " <config.json>");
phantom.exit(1);
}
var conf = fs.read(file)
page.open("http://mikekhristo.com/ec2-ondemand-vs-reserved-instance-savings-calculator/#" + encodeURIComponent(conf), function(){
var result = page.evaluate(function(){
// use eval for commented JSON
eval("var conf = "+decodeURIComponent(location.hash.substring(1)));
var targets = [];
Object.keys(conf).forEach(function(key){
jQuery('input[name="num_' + (key.replace(".","_")) + '"]').val(conf[key]).trigger('keyup');
targets.push(key);
});
var result = "";
targets.forEach(function(key){
result += key + " : $";
result += jQuery('input[name="num_' + (key.replace(".","_")) + '"]').closest('tr').find('td:nth-child(3)').text() + "\n";
});
result += document.querySelector('#current-amount').textContent;
return result;
});
console.log(result);
phantom.exit(0);
});
$ phantomjs ./ec2.js ./config.json
t1.micro : $7.30
m1.small : $47.45
With on-demand, you currently pay:
$0.00 upfront
$54.75 monthly
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment