Skip to content

Instantly share code, notes, and snippets.

@jfhbrook
Forked from 140bytes/LICENSE.txt
Created May 27, 2011 04:45
Show Gist options
  • Star 3 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save jfhbrook/994653 to your computer and use it in GitHub Desktop.
Save jfhbrook/994653 to your computer and use it in GitHub Desktop.
<140 byte sparktweet helper

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

The 140byt.es site hasn't launched yet, but for now 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. It was inspired by work from Thomas Fuchs and Dustin Diaz.

//This function generates sparktweets from array data.
//ex: > st([1,2,3,4,5])
// '▁▃▆▃▁'
st=function(a,b,c,d,e){
//a: The array in question.
//b: A copy of the array used to find the data's max and min.
//c: The resulting string.
//d: Used for incrementing in the for loop.
//e: Used to hold the length of the array.
b=a.slice().sort(); // Makes a sorted copy of a. This way, the first element
// is the minimum, and the last element is the max.
c=''; // Initializes c
for( d=0;
d<(e=b.length); //We use the array length twice, so we assign it here.
c+=['','▁','▃','▅','▆','█'][-~(4*(a[d++]-b[0])/(b[e-1]-b[0]))]);
//Grab the proper 'bar' based on an (x-a)/(b-a) type calculation.
//Tricks:
// * -~ is used for ceil()-ish purposes.
// '' is a sort of placeholder, since -~0 = 1.
// Note the d++ increment buried in the accessing of a[d].
return c //Return answer :)
}
function(a,b,c,d,e){b=a.slice().sort();c='';for(d=0;d<(e=b.length);c+=['','▁','▃','▅','▆','█'][-~(4*(a[d++]-b[0])/(b[e-1]-b[0]))]);return c}
DO WHAT THE FUCK YOU WANT TO PUBLIC LICENSE
Version 2, December 2004
Copyright (C) 2011 Joshua Holbrook <http://jesusabdullah.github.com>
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": "sparktweet",
"description": "Generates sparktweets from input arrays of data.",
"keywords": [
"140bytes",
"plotting",
"twitter"
]
}
@tsaniel
Copy link

tsaniel commented Nov 3, 2011

What about this?

function(a,b,c,d){for(d in b=a.slice(c='').sort())c+='0▁0▃0▅0▆0█'.split(0)[-~(4*(a[d++]-b[0])/(b[b.length-1]-b[0]))];return c}

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