Skip to content

Instantly share code, notes, and snippets.

@monkee52
Forked from 140bytes/LICENSE.txt
Created September 30, 2012 15:06
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 monkee52/3807059 to your computer and use it in GitHub Desktop.
Save monkee52/3807059 to your computer and use it in GitHub Desktop.
140byt.es -- Click ↑↑ fork ↑↑ to play!

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(n) {
return "rgb(" + [ // Start with the string "rgb(" and declare an array.
(n >> 16) & 0xFF, // Get the red value, shift it right by 8 then get only 8-bits of it
(n >> 8) & 0xFF, // Get the green value, shift it right by 8 then get only 8-bits of it
n & 0xFF // Get the blue value, and get only 8-bits of it.
] + ")" // Close the array and add a ")" on to the end.
}
function(n){return"rgb("+[(n>>16)&0xFF,(n>>8)&0xFF,n&0xFF]+")"}
DO WHAT THE FUCK YOU WANT TO PUBLIC LICENSE
Version 2, December 2004
Copyright (C) 2011 YOUR_NAME_HERE <YOUR_URL_HERE>
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": "Number2RGB",
"description": "Turn a colour into a string that can be used in CSS",
"keywords": [
"color",
"css",
"array",
"rgb",
"colour"
]
}
<!DOCTYPE html>
<title>Foo</title>
<div>Expected value: <b style="color: rgb(255,0,255);">The quick brown fox jumps over the lazy dog.</b></div>
<div>Actual value: <b id="ret">The quick brown fox jumps over the lazy dog.</b></div>
<script>
var myFunction = function(n){return"rgb("+[(n>>16)&0xFF,(n>>8)&0xFF,n&0xFF].join(",")+")"}
document.getElementById( "ret" ).style['color'] = myFunction(0xFF00FF);
</script>
@xpansive
Copy link

xpansive commented Oct 1, 2012

You can actually leave off the .join(',') because when you add an array to a string it does that automatically for you.

function(n){return"rgb("+[(n>>16)&0xFF,(n>>8)&0xFF,n&0xFF]+")"}

@atk
Copy link

atk commented Oct 1, 2012

You can save the bytes for join, because if you coerce an array by concatenating it to strings, it will be formatted with commas, anyway.

@atk
Copy link

atk commented Oct 1, 2012

In adition, #RRGGBB colors work, too, you can use function(n){return'#'+(1<<16+n).toString(16).slice(1)} to do that.

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