Last active
June 13, 2018 12:18
-
-
Save pReya/f6282699e5d14848cd0e21520d41a31e to your computer and use it in GitHub Desktop.
Start your cloud computer from Paperspace (http://www.paperspace.com/) using a regular web browser (e.g. on a Fire TV stick). Just upload this to your server or webspace and then call it from your desired browser. You need to add the machine id and the api-key to the URL (e.g. startPaperspace.html?machine=ab1c2n345&key=1234567890). Save this to …
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<!DOCTYPE html> | |
<html> | |
<head> | |
<title>Start Paperspace machine</title> | |
<meta charset="UTF-8"> | |
<style> | |
body { | |
background-color: black; | |
} | |
#main { | |
color: white; | |
font-family: Arial, Helvetica, sans-serif; | |
font-weight: bold; | |
font-size: 3em; | |
text-align: center; | |
padding: 200px 0; | |
} | |
</style> | |
<script type="text/javascript"> | |
"use strict"; | |
// Source: https://css-tricks.com/snippets/javascript/get-url-variables/ | |
function getQueryVariable(variable) | |
{ | |
var query = window.location.search.substring(1); | |
var vars = query.split("&"); | |
for (var i=0;i<vars.length;i++) { | |
var pair = vars[i].split("="); | |
if(pair[0] == variable){return pair[1];} | |
} | |
return(false); | |
} | |
function sendPaperspaceStart(machineId, apiKey) | |
{ | |
var response = ""; | |
if (machineId && apiKey) | |
{ | |
var url = 'https://api.paperspace.io/machines/' + machineId + '/start'; | |
var xhr = new XMLHttpRequest(); | |
xhr.open("POST", url, true); | |
xhr.setRequestHeader("x-api-key", apiKey); | |
xhr.onreadystatechange = function() { | |
if(xhr.readyState == XMLHttpRequest.DONE && xhr.status == 204) { | |
response = '✅ - Machine ' + machineId + ' was successfully started.'; | |
} | |
else | |
{ | |
response = '❌ - Machine ' + machineId + ' could not be started.'; | |
} | |
document.getElementById('main').innerHTML = response; | |
} | |
xhr.send(); | |
} | |
else | |
{ | |
response = 'URL parameters not correct'; | |
document.getElementById('main').innerHTML = response; | |
} | |
} | |
function onLoadHandler() | |
{ | |
var machineId = getQueryVariable('machine'); | |
var apiKey = getQueryVariable('key'); | |
sendPaperspaceStart(machineId, apiKey); | |
} | |
</script> | |
</head> | |
<body onload="onLoadHandler()"> | |
<div id="main">Trying to start Paperspace machine...</div> | |
</body> | |
</html> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment