.
This commit is contained in:
@@ -1,13 +0,0 @@
|
||||
function bfgen(text) {
|
||||
let out = "+".repeat(10) + "[";
|
||||
let repeat = 0;
|
||||
for (let i = 0; i < text.length; i++)
|
||||
repeat = text.charCodeAt(i) - text.charCodeAt(i) % 10;
|
||||
out += repeat > 10 ? '>' + "+".repeat(repeat / 10) : null;
|
||||
out += "<".repeat(out.split(">").length - 1) + "-]";
|
||||
for (let i = 0; i < text.length; i++)
|
||||
out += ">" + "+".repeat(text.charCodeAt(i) % 10) + ".";
|
||||
return out;
|
||||
}
|
||||
|
||||
export default { bfgen };
|
93
src/inc/trigger/lib/sandbox.js
Normal file
93
src/inc/trigger/lib/sandbox.js
Normal file
@@ -0,0 +1,93 @@
|
||||
const request = require("request");
|
||||
|
||||
const maxoutput = 400;
|
||||
|
||||
const hsimports = [
|
||||
"Control.Applicative", "Control.Arrow", "Control.Monad",
|
||||
"Control.Monad.Zip", "Data.Bits", "Data.Bool", "Data.Char",
|
||||
"Data.Complex", "Data.Data", "Data.Eq", "Data.Fixed",
|
||||
"Data.Foldable", "Data.Function", "Data.Functor",
|
||||
"Data.Int", "Data.List", "Data.Maybe", "Data.Monoid", "Data.Map",
|
||||
"Data.Ord", "Data.Set", "Data.String", "Data.Tuple", "Data.Word"
|
||||
].map(imp => { return `import qualified ${imp}`; }).join("\r\n");
|
||||
|
||||
function sandbox(lang, code) {
|
||||
const langs = {
|
||||
cpp: {
|
||||
"LanguageChoice": "7",
|
||||
"Program": "#include <iostream>\r\nint main() { " + code + "}",
|
||||
"Input": "",
|
||||
"CompilerArgs": "-Wall -std=c++14 -O2 -o a.out source_file.cpp"
|
||||
},
|
||||
hs: {
|
||||
"LanguageChoice": "11",
|
||||
"Program": `${hsimports}\r\nmain = print(${code})`,
|
||||
"Input": "",
|
||||
"CompilerArgs": "-XUnicodeSyntax -XPartialTypeSignatures -o a.out source_file.hs"
|
||||
},
|
||||
py: {
|
||||
"LanguageChoice": "24",
|
||||
"Program": "print(" + code + ")",
|
||||
"Input": "",
|
||||
"CompilerArgs": "-o a.out source_file.hs"
|
||||
},
|
||||
bf: {
|
||||
"LanguageChoice": "44",
|
||||
"Program": code,
|
||||
"Input": "",
|
||||
"CompilerArgs": ""
|
||||
},
|
||||
php: {
|
||||
"LanguageChoice": "8",
|
||||
"Program": "<?php\r\n" + code + "\r\n?>",
|
||||
"Input": "",
|
||||
"CompilerArgs": ""
|
||||
},
|
||||
lua: {
|
||||
"LanguageChoice": "14",
|
||||
"Program": code,
|
||||
"Input": "",
|
||||
"CompilerArgs": ""
|
||||
}
|
||||
};
|
||||
|
||||
return new Promise((resolve, reject) => {
|
||||
const options = {
|
||||
url: "http://rextester.com/rundotnet/api",
|
||||
method: "POST",
|
||||
body: langs[lang],
|
||||
json: true
|
||||
};
|
||||
|
||||
request(options, (err, res, body) => {
|
||||
if (err)
|
||||
return reject("Error!");
|
||||
if (body.Errors) {
|
||||
if (body.Errors.length > maxoutput)
|
||||
return reject(`holy fuck, Error wäre viel zu lang! (${body.Errors.length} Zeichen :DDDDDD)`)
|
||||
return reject(body.Errors);
|
||||
}
|
||||
if (body.Result === null)
|
||||
return reject("Keine Ausgabe :(");
|
||||
if (body.Result.length > maxoutput)
|
||||
return reject(`holy fuck, Ausgabe wäre viel zu lang! (${body.Result.length} Zeichen :DDDDDD)`);
|
||||
if (body.Result.length === 0)
|
||||
return reject("lol keine Ausgabe");
|
||||
resolve(body.Result);
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
function bfgen(text) {
|
||||
let out = "+".repeat(10) + "[";
|
||||
let repeat = 0;
|
||||
for (let i = 0; i < text.length; i++)
|
||||
repeat = text.charCodeAt(i) - text.charCodeAt(i) % 10;
|
||||
out += repeat > 10 ? '>' + "+".repeat(repeat / 10) : null;
|
||||
out += "<".repeat(out.split(">").length - 1) + "-]";
|
||||
for (let i = 0; i < text.length; i++)
|
||||
out += ">" + "+".repeat(text.charCodeAt(i) % 10) + ".";
|
||||
return out;
|
||||
}
|
||||
|
||||
export { maxoutput, sandbox, bfgen };
|
Reference in New Issue
Block a user