[ Launch: tribception ] 5595214 by georules
[ Launch: tribception ] 5594755 by georules
-
-
Save georules/5595214 to your computer and use it in GitHub Desktop.
tribception2
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
{"description":"tribception2","endpoint":"","display":"svg","public":true,"require":[],"fileconfigs":{"inlet.js":{"default":true,"vim":false,"emacs":false,"fontSize":12},"_.md":{"default":true,"vim":false,"emacs":false,"fontSize":12},"config.json":{"default":true,"vim":false,"emacs":false,"fontSize":12},"original_code":{"default":true,"vim":false,"emacs":false,"fontSize":12},"original_code.txt":{"default":true,"vim":false,"emacs":false,"fontSize":12}},"fullscreen":false,"play":true,"loop":false,"restart":false,"autoinit":true,"pause":true,"loop_type":"period","bv":false,"nclones":15,"clone_opacity":0.4,"duration":3000,"ease":"linear","dt":0.01,"thumbnail":"http://i.imgur.com/m0Zsd1v.png"} |
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
// code in my code live updating code with code | |
original_code = tributary.original_code || "-1"; | |
console.log(original_code); | |
// the depth counter code, currently stopping at 1000. probably would be a lot more than this. | |
var depth_inject_string = "var depth=0;var maxdepth=1000;"; | |
var loop_inject_string = "if(depth++ > maxdepth) {break;}"; | |
// need a real parser here | |
function inject(code) { | |
lines = code.split("\n"); | |
console.log(lines); | |
for (line in lines) { | |
datline = lines[line]; | |
if (datline.indexOf("while") != -1) { // "parsing" lol | |
lines[line] = depth_inject_string + lines[line]; | |
lines[line] = lines[line] + loop_inject_string; // assumes that while() { is by itself on a line | |
} | |
} | |
console.log(lines); | |
newcode = lines.join(''); | |
return newcode; | |
} | |
function evil(code) { | |
ret = eval(code); // evil? whatever, I do what I want. | |
return ret; | |
} | |
var svg = d3.select("svg"); | |
var screen = svg.append("text") | |
.attr("x", 54) | |
.attr("y", 124) | |
.attr("fill","#0C87AD") | |
.attr("font-size",147) | |
.attr("font-family","Courier"); | |
// inject the depth counter | |
new_code = inject(original_code); | |
// run the 'safe' code | |
screen.text(evil(new_code)); | |
var codewindow = svg.append("foreignObject").attr("x",54).attr("y",165) | |
.attr("width", 500) | |
.attr("height", 500) | |
.append("xhtml:body") | |
.style("font", "25px 'Courier'") | |
.style("color", "#0C87AD") | |
.html(newcode) |
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
// original code with infinite loop | |
var x=0; | |
while(true) { | |
x = x + 1; | |
} | |
x; |
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
// original code with infinite loop | |
var x=0; | |
while(true) { | |
x = x + 1; | |
} | |
x; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment