top | item 3237478

Spark

568 points| lrvick | 14 years ago |github.com | reply

95 comments

order
[+] Mgccl|14 years ago|reply
Just did a Haskell version of spark. It supports in 9 lines of code (exclude comment + empty line) Double instead of just Int. Negative numbers.

https://github.com/Mgccl/mgccl-haskell/blob/master/random/sp...

[+] jodrellblank|14 years ago|reply
And here's a PowerShell version. (Use PowerShell ISE as PowerShell normal prompt doesn't support unicode).

http://pastie.org/2867807

[edit: updated, careless variable rename, thanks jcromartie]

[+] tome|14 years ago|reply
I really like your version. Very neat!
[+] ocharles|14 years ago|reply
Here's a Haskell version that uses a single loop to do the normalizing, and has a main that doesn't use do syntax. This was mostly a nice little brainteaser:

https://gist.github.com/1367709

mapNormalize takes a function, and produces a function that runs that function with the normalized input. It runs in a single iteration, rather than 2 maps. Credit to `dylex` for much hand holding on a single iteration normalizer :)

[+] Mgccl|14 years ago|reply
Updated. thx to gwern. Now I know the existence of hlint.

Now, without the type declaration, white space, comments, it's only 6 lines, and looks even better. :)

[+] DanielN|14 years ago|reply
This is pretty cool. Unfortunately it's coupled with some of the more obnoxious documentation I have seen recently. While the docs aren't very long, I had to read through a third of it to figure out simply what Spark is.

I'm all for being cute, but it shouldn't come at the cost of a basic understanding of what the program actually does and is useful for.

[+] antics|14 years ago|reply
This is a totally fair complaint. Sometimes it is a mystery to me why HN-ers downvote things.
[+] etanol|14 years ago|reply
The script is not a proper POSIX bourne shell script, as it uses arrays.

For starters, it won't work in dash (Debian and Ubuntu /bin/sh implementation). So the shebang line should be changed to #!/bin/bash (not sure if it would work in Zsh either).

[+] VMG|14 years ago|reply
Maybe this shouldn't be a shell script. A C implementation would be quite portable and also pretty fast.
[+] willvarfar|14 years ago|reply
Fork and fix please!
[+] spektom|14 years ago|reply
This reminds me of another useful utility from the childhood:

alias updick='/usr/bin/uptime | perl -ne "/(\d+) d/;print 8,q(=)x\$1,\"D\n\""'

[+] derwiki|14 years ago|reply
You cracked my office up. Deploying to production immediately.
[+] reledi|14 years ago|reply
The dick grows depending on how long the system has been running?
[+] premchai21|14 years ago|reply
I'm curious: is there a reason U+2584 LOWER HALF BLOCK is missing from the character set, which otherwise contains the progression from U+2581 to U+2587?

Edit: U+2588 seems like an obvious candidate as well.

[+] tome|14 years ago|reply
No idea. Here they are for everyone's use:

ticks = " ▁▂▃▄▅▆▇█"

I've included SPACE as well. That's an obvious missing one.

[+] jmah|14 years ago|reply
Ah, as inspired by Edward ttyfte.
[+] huhtenberg|14 years ago|reply
That ^ is why HN needs a LOL button :)

http://img819.imageshack.us/img819/264/hnlol.png

(edit) Ah, the downvoting frenzy! 4601 karma points to go. Bring it on, fellow HNers. Don't forget to quote the guidelines and to lecture me too as no bashing is complete without showing some smug superiority with a hint of righteousness.

[+] zx2c4|14 years ago|reply
I rewrote it in C, so it's faster and can work more efficiently on different data sets. It also uses a prettier algorithm for determining heights. Have fun:

http://git.zx2c4.com/spark/tree/spark.c

    $ git clone http://git.zx2c4.com/spark
    $ cd spark
    $ make
    $ ./spark 1 4 2 8 14
    ▂▃▂▅█
    $ curl -s http://earthquake.usgs.gov/earthquakes/catalogs/eqs1day-M1.txt | cut -d, -f9 | ./spark
    ▂▃▄▃▃▃▄▃▇▃▄▄▄▅▃▄▄▄▅▅▅▄▄▄▃▃▃▃▃▄▃▄█▅▄▄▄▄▃▇▄▄▄█▄▃▄▄▄▄▃▃▄▅▄▅▃▃▃▃▇▄▅▄▇▃▅▃▄▃▄▃▇▃▃▄▇▃▄▃▄▃▃▃▄▃▃▃▃▃▃▅▃▄▃▃
[+] scottyallen|14 years ago|reply
Hmm, I get the following:

  [scotty@Scotty-Allens-MacBook-Air ~/bin]$ spark 1,2,3,4,5
  ▇\c
  ▇\c
  ▇\c
  ▇\c
  ▇\c
I suspect this has something to do with my terminal settings, but I'm not sure quite what...

Nifty idea, regardless.

[+] enduser|14 years ago|reply
add a '-e' after 'echo' on line 120
[+] Chirono|14 years ago|reply
Try changing line 120 to

  echo -e $"$(print_tick $number)\c"
And it should work fine.
[+] bch|14 years ago|reply
I've quickly looked at the link, read the reviews here, and there's actually no description of what spark _is_. I gather is an UTF-8 graph generator.
[+] adaml_623|14 years ago|reply
Sparklines are cool. This is just a bar graph and not nearly as useful.
[+] knowtheory|14 years ago|reply
So, because you can't deviate below the x axis this is really that much less useful?
[+] jvoorhis|14 years ago|reply
I hooked this up to my homebrew cohort-analysis script and saw a gratifying terminal hockeystick :D
[+] ieure|14 years ago|reply
Because I want my shell prompt to be a giant graph.

▁▁▁▁▅▁▇▁▁▅▁▁▁▁▁▂▂▁▃▃▁▁▃▁▃▁▂▁▁▂▂▅▂▃▂▃▃▁▆▃▃▃▁▇▁▁▂▂▂▇▅▁▂▂▁▇▁▃▁▇▁▂▁▇▁▁▆▂▁▇▁▂▁▁▂▅▁▂▁▆▇▇▂▁▂▁▁▁▂▂▁▅▁▂▁▁▃▁▃▁▁▁▃▂▂▂▁▁▅▂▁▁▁▁▂▂▁▁▁▂▂$

Ship it.

[+] smackfu|14 years ago|reply
Does HN really not have any protection against comments that are very long single words that screw up the page width?
[+] mfukar|14 years ago|reply
What would be really interesting is finding out which decent programming fonts can show block elements. I mean, beyond the DejaVu Sans Mono fiasco.
[+] seabee|14 years ago|reply
You'll have difficulty on Windows if you use PuTTY, since it doesn't do font substitution.
[+] andrewcooke|14 years ago|reply
schumacher clean works (i can cut + paste the title of this post to my shell) - it's a bitmap font that's been in X forever.

and has anyone worked out how to get recent cpu load into their bash prompt yet?

[+] jablan|14 years ago|reply
Liberation Mono and Terminus both work.
[+] philjackson|14 years ago|reply
I would rather it took a number, one per line from stdin. Great idea though.