Skip to content

Instantly share code, notes, and snippets.

@heyLu
Forked from 140bytes/LICENSE.txt
Created November 27, 2012 14:40
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 heyLu/4154556 to your computer and use it in GitHub Desktop.
Save heyLu/4154556 to your computer and use it in GitHub Desktop.
140byt.es -- Fun with bidirectionality and Unicode (inspired by xkcd #1137)

140byt.es

A tweet-sized, fork-to-play, community-curated collection of JavaScript.

How to play

  1. Click the Fork button above to fork this gist.
  2. Modify all the files to according to the rules below.
  3. Save your entry and tweet it up!

Keep in mind that thanks to the awesome sensibilities of the GitHub team, gists are just repos. So feel free to clone yours and work locally for a more comfortable environment, and to allow commit messages.

Rules

All entries must exist in an index.js file, whose contents are

  1. an assignable, valid Javascript expression that
  2. contains no more than 140 bytes, and
  3. does not leak to the global scope.

All entries must also be licensed under the WTFPL or equally permissive license.

For more information

See the 140byt.es site for a showcase of entries (built itself using 140-byte entries!), and follow @140bytes on Twitter.

To learn about byte-saving hacks for your own code, or to contribute what you've learned, head to the wiki.

140byt.es is brought to you by Jed Schmidt, with help from Alex Kloss. It was inspired by work from Thomas Fuchs and Dustin Diaz.

function(){
d = document; // Abbreviate document because that name is not 140byt.es friendly.
e = d.querySelectorAll("body *"); // Find all elements under body,
for(i = 0; i < e.length; i++) { // iterate over those elements and
e[i].insertBefore( // insert
d.createTextNode("\u202e"), // the change-the-bidirectionality-to-right-to-left unicode character
e[i].firstChild // before each of them.
);
}
}
function(){d=document;e=d.querySelectorAll("body *");for(i=0;i<e.length;i++){e[i].insertBefore(d.createTextNode("\u202e"),e[i].firstChild);}}
DO WHAT THE FUCK YOU WANT TO PUBLIC LICENSE
Version 2, December 2004
Copyright (C) 2011 Lucas Stadler <http://papill0n.org>
Everyone is permitted to copy and distribute verbatim or modified
copies of this license document, and changing it is allowed as long
as the name is changed.
DO WHAT THE FUCK YOU WANT TO PUBLIC LICENSE
TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION
0. You just DO WHAT THE FUCK YOU WANT TO.
{
"name": "reverseALLTHETHINGS",
"description": "Make all the text in an HTML document run from right to left. (Inspired by xkcd #1137.)",
"keywords": [
"xkcd",
"unicode",
"delbrag"
]
}
<!DOCTYPE html>
<html>
<head>
<title>Fun with bidirectionality and Unicode (inspired by xkcd #1137)</title>
<meta charset="utf-8" />
</head>
<body>
<h1>Breaking news: HTML actually contains magic!</h1>
<h3>Sadly, it doesn't have unicorns by default.<h3>
<p>If you take a look at <a href="http://xkcd.com/1137">one of the recent xkcds</a>
in Firefox on certain platforms, you might notice that the window title and the
source view is a little bit funny (if you don't, here's <a href="https://bugzilla.mozilla.org/show_bug.cgi?id=814030">a bug</a>
that has the relevant details.</p>
<p>Anyway, it brought a very curious Unicode character to my attention: U+202e. This
character switches the text direction to right-to-left, which makes western texts
rather interesting to read. (I encourage you to try this little function on a few
of your favourite sites, it's quite entertaining.)</p>
<p>Well, this should be enough text to be interesting...</p>
<p>But before we go, a few notes:<br /><!-- (sorry) -->
This text is not funny, &#x202e; but from here it is!
<ul>
<li>But shockingly, this is <em>not!</em></li>
<li>This isn't so funny, right.</li>
<li>And so I set out to remedy it. (Quite conveniently it fits in less than 140
characters, all of which can be encoded as bytes)</li>
</ul>
</p>
<p>
Ok, I have a few more things...
<ul>
<li>I like <a href="https://gist.github.com/1707371">this article</a> about some things Unicode and Javascript.</li>
<li>And this script could be made shorter by shaving of at least one semicolon,
encoding the mischievous character as a real unicode character and whatnot...
</li>
</ul>
</p>
<p>Thanks for reading and bye! :)</p>
<p>Now, go and <a href="javascript:function(){d=document;e=d.querySelectorAll('body *');for(i=0;i<e.length;i++){e[i].insertBefore(d.createTextNode('\u202e'),e[i].firstChild);}}">reverse ALL THE THINGS</a>.</p>
</body>
</html>

Breaking news: HTML actually contains magic!

Sadly, it doesn't have unicorns by default.

If you take a look at one of the recent xkcds in Firefox on certain platforms, you might notice that the window title and the source view is a little bit funny (if you don't, here's a bug that has the relevant details.

Anyway, it brought a very curious Unicode character to my attention: U+202e. This character switches the text direction to right-to-left, which makes western texts rather interesting to read. (I encourage you to try this little function on a few of your favourite sites, it's quite entertaining.)

Well, this should be enough text to be interesting...

But before we go, a few notes:

This text is not funny, ‮ but from here it is!

  • But shockingly, this is not!
  • This isn't so funny, right.
  • And so I set out to remedy it. (Quite conveniently it fits in less than 140 characters, all of which can be encoded as bytes)

Ok, I have a few more things...

  • I like this article about some things Unicode and Javascript.
  • And this script could be made shorter by shaving of at least one semicolon, encoding the mischievous character as a real unicode character and whatnot...

Thanks for reading and bye! :)

Now, go and reverse ALL THE THINGS

@atk
Copy link

atk commented Nov 28, 2012

This leaks d, e and i into the global scope, alas.

@atk
Copy link

atk commented Nov 28, 2012

function(){for(var d=document,e=d.querySelectorAll('body *'),i=e.length;i--;e[i].insertBefore(d.createTextNode("\u202e"),e[i].firstChild));}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment