Dwitter – A social network for short JavaScript demos

9 years ago (dwitter.net)

Oh fun, didn't expect to see my side-project here :)

A few of my personal favorites:

https://www.dwitter.net/d/90

https://www.dwitter.net/d/406

https://www.dwitter.net/d/433

https://www.dwitter.net/d/617

So I whipped up a standalone HTML page to use to develop Dwitter scripts without having to use their interface (which seems prone to crashing). Here's the source: https://gist.github.com/russellbeattie/ef27709f7c916ea54454c... and you can see it live on my site: http://www.russellbeattie.com/dwitterish.html

Interestingly, I found that some scripts really don't like using eval(), so I modified the page to dynamically swap in new <script> elements with the code instead, and a flag to go back and forth.

Here's an example of a script which doesn't like eval() - it runs noticeably faster when embedded in a script: https://www.dwitter.net/d/697

Edit: Added the ability to just embed the code in the URL: http://www.russellbeattie.com/dwitterish.html#c.width%7C%3D0...

(Note that I only tested this on Chrome, so feel free to modify if there's issues.)

This is the coolest website I've seen in a long time. Awesome idea.

EDIT: one issue I'm running into is it's easy to accidentally write half-finished code that freezes my browser. It would be nice to have an option to only refresh the preview upon clicking some kind of button.

  • One trick you learn as a dweeter is to write all for-loops as "fr" instead of "for", and then only adding the last "o" when you feel confident that the loop won't accidentally go on forever!

    • or the source box could replace 'for' with a loop thats designed to run a few seconds.

  • Sorry about your lost dweet :( Accidental infinite loops while editing can be a pain. A "reload" button isn't a bad idea, or a "recover dweet draft" functionality.

This is really cool, but executing other people's javascript in a page makes me nervous. What sort of restrictions are in place to prevent malicious exploits?

  • Makes me quite nervous too. So far each dweet is run in a sandboxed iframe loaded from a separate subdomain.

    There are definitely things you can do, and I'm aware of some annoying ones. I'll just manually delete them at this point. Any security conscious person would view it with noscript and just read the javascript ;)

    • While you're deleting stuff, I noticed someone on the new page has posted pornographic images. Alas, I'm not terribly surprised since this is the internet after all, but I'll +1 a feature to report dweets as being inappropriate.

      A system to automatically hide dweets (for later manual review) after receiving a certain number of reports would likely solve the problem in the short term.

    • While you're manually deleting things... there are currently way too many that are just exact reposts of the default swaying black bars. Probably accidents rather than people being deliberately lame, but low-hanging fruit for any kind of automatic cleanup.

    • Why not make their javascript run in WebWorkers and provide a DOM-like interface for all the things? That way you can kill infinite loops etc.

      1 reply →

This is awesome! During one of the last hackathons I participated while at Tumblr, I made a Processing post type, that allowed people to have interactive posts using Processing code, and could be reblogged with edits - very much like this. Love seeing something similar to this idea!

Opened page: this is kinda lam....oooh that's neat.

* scroll scroll scroll *

Nice work.

This is definitely fun... It'd be nice if it used Github to login and save to Gists. Also, I think it'd be better if the developer called u(t){}, rather than it being the content of the entire post, so it could set up variables, etc., and since it already has a few shortcuts like c,x,C,S,T,R, might as well add in a more complete API.

How do I link to a specific post?

This one by mxfh looks very cool:

    d=x.getImageData(0,0,w=c.width=256,h=144);for(i=0;i<h;i++)for(j=0;j<w;j++)d.data[(i*w+j)*4+3]=(i-j&j+i)*t%w;x.putImageData(d,0,0)

Does anyone know how it works?

  • I don't know either, was more of an accident and I ran for it. But I'll try:

    Manipulating the canvas Imagedata TypedArray is usually faster than draw calls like fillRect; yet the getImagadata-setImagedata and 2D-Y-X-iteration (here ij) fluff doesn't leave much bytes for actual per pixel operations.

        (i*w+j)*4+3 // is the alpha channel (offset of 3) index of the pixel in the Imagedata
    

    The actual payload:

        (i-j&j+i)*t%w
    

    Translates to

        (y - x & x + y) * time % 256
    

    With 255 resulting in Black rgba(0,0,0,1) to transparent black rgba(0,0,0,0), which is then effectively viewed as background color, in this case white.

    see https://www.dwitter.net/d/661 for an earlier full RGBA example

    Before WebGL this was the fastest way to get stuff done in the canvas: https://hacks.mozilla.org/2011/12/faster-canvas-pixel-manipu...

What resources to people recommend for learning about animating in canvas tags like on Dwitter? I'm already familiar with Javascript, but seeing what people are able to do here with 140 characters amazes me.

Just tried to register with username @H2O. Sent post request, after that got 500 error.

  • Oh, got the 500 error dump. It's the @ in your username, that'll teach me. For now avoid special characters in your username ;)

    Edit: In case you were stuck in a 500-loop I quickly changed your username to H2O, hopefully it works now

I'm not understanding this. How is animation happening? What is S(t)? Can somebody please explain this project?

  • Scroll down:

      u(t) is called 60 times per second.
      t: elapsed time in seconds.
      c: A 1920x1080 canvas.
      x: A 2D context for that canvas.
      S: Math.sin
      C: Math.cos
      T: Math.tan
      R: Generates rgba-strings, ex.: R(255, 255, 255, 0.5)

within a half hour of playing around on this site, someone posted goatse. and there is no way to report, hide, downvote, etc.