viebel / klipse

Klipse is a JavaScript plugin for embedding interactive code snippets in tech blogs.
http://blog.klipse.tech/
GNU General Public License v3.0
3.1k stars 145 forks source link

klipse freezes far too easily #162

Open rdebath opened 7 years ago

rdebath commented 7 years ago

When you're editing code it's good practice to keep it syntactically correct as much as possible. Certain editors make it difficult; for example "Intellisense" is really dumb about this grabbing various keys and generally behaving like a headless chicken.

OTOH, various editors try to be helpful, inserting the closing structure automatically when you enter the start of a loop or condition. This doesn't always work very well either.

Currently, klipse is probably one of the least helpful I've come across. You basically have to force a syntax error at the top of the code to keep it from crashing and if you (for example) decrement the wrong variable within a loop you lose what you've typed.

The solution is simple in concept; the code should only run until the next keypress ... no more.

viebel commented 7 years ago

Can you give a detailed example? What language are you editing?

Maybe you could share an animated gif?

On Mon, Dec 19, 2016, 11:24 rdebath notifications@github.com wrote:

When you're editing code it's good practice to keep it syntactically correct as much as possible. Certain editors make it difficult; for example "Intellisense" is really dumb about this grabbing various keys and generally behaving like a headless chicken.

OTOH, various editors try to be helpful, inserting the closing structure automatically when you enter the start of a loop or condition. This doesn't always work very well either.

Currently, klipse is probably one of the least helpful I've come across. You basically have to force a syntax error at the top of the code to keep it from crashing and if you (for example) decrement the wrong variable within a loop you lose what you've typed.

The solution is simple in concept; the code should only run until the next keypress ... no more.

— You are receiving this because you are subscribed to this thread. Reply to this email directly, view it on GitHub https://github.com/viebel/klipse/issues/162, or mute the thread https://github.com/notifications/unsubscribe-auth/AA6VPpbeOYh1xva_OutZhejpYgxP4Sscks5rJk1MgaJpZM4LQhSv .

rdebath commented 7 years ago

The one I tried was ruby, you're typing this in.

$i = 0
$num = 5

while $i < $num  do
   puts("Inside the loop i = #$i" )
   $i +=1
end

First type this:

$i = 0
$num = 5

Then add the loop;

while $i < $num  do
end

Lastly fill in the loop ...

while $i < $num  do
   puts("Inside the loop i = #$i" )
   $i +=1
end

You won't get to lastly.

viebel commented 7 years ago

I see.

The browser is stuck in an infinite loop. I've solved this issue in clojure and brainfuck by detecting infinite loops and stopping the execution.

But it's not yet implemented in ruby.

A possible workaround is to set the data-eval-idle-msec attribute to a bigger value - see https://github.com/viebel/klipse#snippet-level-configuration. Maybe, eventually as you suggest I will have a button.

A PR is more than welcome!!!

rdebath commented 7 years ago

detecting infinite loops

Heh, I think Dr. Turing might have something to say about that. But I expect you're just limiting the number of instructions that can be run; the problem with that is that sometimes I'm a lot more patient than others. Eg: This shouldn't be too long...

++  [>++++<-]>[>+++<-]< +[>>>[>>]<[[->>+<<]>>-[<<]]>+<<[-<<]<]

OTOH: This is a lot longer, but I might want to wait for it once in a while.

+++ [>++++<-]>[>+++<-]< +[>>>[>>]<[[->>+<<]>>-[<<]]>+<<[-<<]<]

But I'm not going to wait for this one.

++++[>++++<-]>[>+++<-]< +[>>>[>>]<[[->>+<<]>>-[<<]]>+<<[-<<]<]

Actually, I was thinking more of threading or background processes. Something that can be started on a different core and 'killed' if the user doesn't wait for it. A bit like the spelling checker in a web browser... I understand something called "Web Workers" can do that.

viebel commented 7 years ago

Indeed it can be done with web worker. I have forked a gist that does eval in a web worker https://gist.github.com/viebel/707cc19e288aa9f40510333187f06f53

But I didn't integrated into klipse - yet Again, a PR is welcome :)

On Mon, 19 Dec 2016 at 14:00 rdebath notifications@github.com wrote:

detecting infinite loops

Heh, I think Dr. Turing might have something to say about that. But I expect you're just limiting the number of instructions that can be run; the problem with that is that sometimes I'm a lot more patient than others. Eg: This shouldn't be too long...

++ [>++++<-]>[>+++<-]< +[>>>[>>]<[[->>+<<]>>-[<<]]>+<<[-<<]<]

OTOH: This is a lot longer, but I might want to wait for it once in a while.

+++ [>++++<-]>[>+++<-]< +[>>>[>>]<[[->>+<<]>>-[<<]]>+<<[-<<]<]

But I'm not going to wait for this one.

++++[>++++<-]>[>+++<-]< +[>>>[>>]<[[->>+<<]>>-[<<]]>+<<[-<<]<]

Actually, I was thinking more of threading or background processes. Something that can be started on a different core and 'killed' if the user doesn't wait for it. A bit like the spelling checker in a web browser... I understand something called "Web Workers" can do that.

— You are receiving this because you commented.

Reply to this email directly, view it on GitHub https://github.com/viebel/klipse/issues/162#issuecomment-267947960, or mute the thread https://github.com/notifications/unsubscribe-auth/AA6VPuRzo2xkTbXMgRgH21LqRZOU_V6mks5rJnHkgaJpZM4LQhSv .

viebel commented 7 years ago

BTW, all the brainfuck programs that you mentioned are the same.

On Mon, 19 Dec 2016 at 14:40 Yehonathan Sharvit viebel@gmail.com wrote:

Indeed it can be done with web worker. I have forked a gist that does eval in a web worker https://gist.github.com/viebel/707cc19e288aa9f40510333187f06f53

But I didn't integrated into klipse - yet Again, a PR is welcome :)

On Mon, 19 Dec 2016 at 14:00 rdebath notifications@github.com wrote:

detecting infinite loops

Heh, I think Dr. Turing might have something to say about that. But I expect you're just limiting the number of instructions that can be run; the problem with that is that sometimes I'm a lot more patient than others. Eg: This shouldn't be too long...

++ [>++++<-]>[>+++<-]< +[>>>[>>]<[[->>+<<]>>-[<<]]>+<<[-<<]<]

OTOH: This is a lot longer, but I might want to wait for it once in a while.

+++ [>++++<-]>[>+++<-]< +[>>>[>>]<[[->>+<<]>>-[<<]]>+<<[-<<]<]

But I'm not going to wait for this one.

++++[>++++<-]>[>+++<-]< +[>>>[>>]<[[->>+<<]>>-[<<]]>+<<[-<<]<]

Actually, I was thinking more of threading or background processes. Something that can be started on a different core and 'killed' if the user doesn't wait for it. A bit like the spelling checker in a web browser... I understand something called "Web Workers" can do that.

— You are receiving this because you commented.

Reply to this email directly, view it on GitHub https://github.com/viebel/klipse/issues/162#issuecomment-267947960, or mute the thread https://github.com/notifications/unsubscribe-auth/AA6VPuRzo2xkTbXMgRgH21LqRZOU_V6mks5rJnHkgaJpZM4LQhSv .

rdebath commented 7 years ago

Um: They begin with two, three or four pluses. That means the first one runs about 167772160 BF instructions, the second one runs about 687194767360 instructions and the third one runs around 2814749767106560 instructions.

That third one will take several days to complete on the fastest BF 'interpreter' around. If you add another plus it'll probably take about 100 years...

viebel commented 7 years ago

Thx for the clarifications.

On Mon, 19 Dec 2016 at 15:38 rdebath notifications@github.com wrote:

Um: They begin with two, three or four pluses. That means the first one runs about 167772160 BF instructions, the second one runs about 687194767360 instructions and the third one runs around 2814749767106560 instructions.

That third one will take several days to complete on the fastest BF 'interpreter' around. If you add another plus it'll probably take about 100 years...

— You are receiving this because you commented.

Reply to this email directly, view it on GitHub https://github.com/viebel/klipse/issues/162#issuecomment-267965644, or mute the thread https://github.com/notifications/unsubscribe-auth/AA6VPhJtKaoZyYz2clgwn6_GrSIJf7edks5rJoi4gaJpZM4LQhSv .

rachitnigam commented 6 years ago

Hey, we have something that will help with the problem: http://www.stopify.org/ We built a source to source compiler for JS that can instrument programs to prevent them from freezing the browser. You can check out our demo to see this in action (link above).

If you'd be interested in getting Klipse to use this, let me know. I'd be happy to help. The API is straightforward and does not require you to modify your compiler.

viebel commented 6 years ago

@rachitnigam I'd be happy to use stopify inside Klipse.

  1. What compiler option should I use?
  2. Is there a way to prevent from the code to do any malicious actions like stealing cookies etc...?
workshub[bot] commented 4 years ago

If you successfully complete this Issue via WorskHub there's a $250 reward available. Start work via WorksHub Issue Details page.

workshub[bot] commented 4 years ago

@darknightm started working on this issue via WorksHub.