Live data from Hacker News

Show HN: Scratch.js – Interactive JavaScript Scratchpad

hole.dev

41–50 of 69 posts

Re: Show HN: Scratch.js – Interactive JavaScript Scratchpad

#41

Do you, or the broader community, have any ideas about solving infinite loops? I'm on mobile so I can't test this at the moment, but I imagine that while(1) crashes the tab. What would an MVP operating system like ctrl-C functionality look like for execution environments in the browser?

Codepen uses a system that measures loop duration, and it's a giant pain. Having done some pens that do ray tracing and image transforms which can have long running loops. Given the variable execution time of JS it can be quite random. It just exits the loop without warning, causing weird failures in your code. 2 theoretical solutions ( with significant overhead ) are: Run the code in a VM ( maybe quick.js compiled t…

I've done this and it works surprisingly well. I made a timesliced js scripting system this way.. it looked imperative with tight loops but it was all asynchronous. It felt like a threaded app.

Re: Show HN: Scratch.js – Interactive JavaScript Scratchpad

#42
post #7
post #2

Cool stuff! What was the reason for you to make this?

I find myself opening and using the web console to do simple tasks like string manipulation, maths, sorting often. I wanted a dedicated and persistent way to do this. And also just a place to keep notes, urls and stuff. So I made this "literate programming" notepad. I'm also former Emacs user, and I like the lisp scratch buffer there, which is similar.

I've been using this extension for a while...

https://chrome.google.com/webstore/detail/markdown-new-tab/d...

Would be neat to see this integrated in somehow.

Re: Show HN: Scratch.js – Interactive JavaScript Scratchpad

#43
post #35

Earlier quoted context omitted.

Yes, as the other comments get at the "hack" I'm referring to is a loop transform that adds a timer check to the condition.

Oh, right, I was not there at all. Wow, that seems hard to do. One would need to take a lot of things in account, including recursive calls, asynchronous functions / calls and, indeed, even long strings of instructions that are not necessarily part of a loop or recursive calls. Would a transform that adds the check between every JS instructions where it is possible theoretically solve the problem? is there a solution…

Yeah! The general case of this is the halting problem... The best solution I know of is stopify, which the other comments have talked about. I just wonder if there's another take on the situation, something akin to OS task management.

Re: Show HN: Scratch.js – Interactive JavaScript Scratchpad

#44
post #40
post #30

Earlier quoted context omitted.

We started with a blacklist to match against while(1), while(true), for(;;), etc, but we eventually found an eslint plugin (goedel.js) that nicely tells you if the code contains an infinite loop or recursion.

That plug-in certainly won’t cover all cases of infinite loops, or they just solved the halting problem :)

Hmmmm maybe you're thinking of entscheidungsproblem.js? This is a fork of that.

Re: Show HN: Scratch.js – Interactive JavaScript Scratchpad

#47
post #7

Earlier quoted context omitted.

I find myself opening and using the web console to do simple tasks like string manipulation, maths, sorting often. I wanted a dedicated and persistent way to do this. And also just a place to keep notes, urls and stuff. So I made this "literate programming" notepad. I'm also former Emacs user, and I like the lisp scratch buffer there, which is similar.

I've been using this extension for a while... https://chrome.google.com/webstore/detail/markdown-new-tab/d... Would be neat to see this integrated in somehow.

That would be awesome!

Re: Show HN: Scratch.js – Interactive JavaScript Scratchpad

#48
Very cool.

Small issue: I find that the cursor can be hard to use sometimes. For example, if I clear and then execute the single line

    "body {background-color: #fdf6e3;}"
I can no longer get an empty line at the bottom of the document. My cursor can only ever be within the outputted "" tags, and hitting return from there creates a new pair of "" tags.

To temper this bug-report with a cool feature, I like that the output is (usually, with the exception of the above) plain text, which can itself be executed. I haven't found a use-case for this, but I'm sure there's some interesting meta-programming that could be done.

Re: Show HN: Scratch.js – Interactive JavaScript Scratchpad

#49
post #48

Very cool. Small issue: I find that the cursor can be hard to use sometimes. For example, if I clear and then execute the single line " body {background-color: #fdf6e3;} " I can no longer get an empty line at the bottom of the document. My cursor can only ever be within the outputted " " tags, and hitting return from there creates a new pair of " " tags. To temper this bug-report with a cool feature, I like that the…

(Now fixed) Thanks for letting me know, there is indeed a small issue with the clear() function.

I considered supporting only plain-text, but I found the editable visible style tag very interesting. And I like the fact all the power of the browser is available, e.g canvas, 3d rendering, and simple stuff like headers and images. Of course, you can use only plaintext if you'd like.

Re: Show HN: Scratch.js – Interactive JavaScript Scratchpad

#50
post #48

Very cool. Small issue: I find that the cursor can be hard to use sometimes. For example, if I clear and then execute the single line " body {background-color: #fdf6e3;} " I can no longer get an empty line at the bottom of the document. My cursor can only ever be within the outputted " " tags, and hitting return from there creates a new pair of " " tags. To temper this bug-report with a cool feature, I like that the…

This should now be fixed!
Post reply on HN