Skip to content

Instantly share code, notes, and snippets.

@georules
Created May 16, 2013 21:23
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save georules/5595214 to your computer and use it in GitHub Desktop.
Save georules/5595214 to your computer and use it in GitHub Desktop.
tribception2
{"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"}
// 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)
// original code with infinite loop
var x=0;
while(true) {
x = x + 1;
}
x;
// 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