
Spark - lrvick
https://github.com/holman/spark
======
Mgccl
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...](https://github.com/Mgccl/mgccl-
haskell/blob/master/random/spark.hs)

~~~
jcromartie
Same features. 4 SLoC of Ruby :)

<https://gist.github.com/1367091>

~~~
silvestrov
'floor' on last line should be changed to 'round'.

    
    
      ▁▁▁▁▁▁▂▂▂▂▂▂▃▃▃▃▃▃▅▅▅▅▅▅▆▆▆▆▆▆▇ = floor
      ▁▁▁▂▂▂▂▂▂▃▃▃▃▃▃▅▅▅▅▅▅▆▆▆▆▆▆▇▇▇▇ = round

~~~
jcromartie
Thanks! Much better.

------
DanielN
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.

~~~
gwern
In my defense, I _did_ try: <https://github.com/holman/spark/pull/34/files>

~~~
DanielN
Excellent. Does a great job of clarifying.

~~~
gwern
Unfortunately, the maintainer didn't like it as much as you.

------
etanol
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).

~~~
willvarfar
Fork and fix please!

~~~
imrehg
... and send a pull-request, so everyone can share the happy.

~~~
etanol
Already done, and someone even did a better fix:

<https://github.com/holman/spark/pull/8>

~~~
kelnos
NetBSD seriously doesn't put bash in /bin? That's just broken by design.

~~~
ketralnis
I can't speak to NetBSD, but FreeBSD doesn't put any user-installed programs
in /bin or /usr/bin, they all go into /usr/local. Since bash isn't distributed
as part of the base system, it goes into /usr/local/bin/bash

~~~
kelnos
So then how do you write cross-platform scripts? You can't even do
"#!/usr/bin/env bash" since I'm assuming what you're saying means 'env' is in
/usr/local/ as well, but on Linux systems it'll be in /usr/.

Broken! Can we please just pick one convention and stick with it? Oh,
standards... so many to choose from.

------
spektom
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\""'

~~~
reledi
The dick grows depending on how long the system has been running?

~~~
spektom
Exactly. Kinda measure of how strong is sysadmin.

------
premchai21
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
No idea. Here they are for everyone's use:

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

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

~~~
bodyfour
At least in my OS/X terminal using the "Monaco" font (which I think is the
default), the final one (U+2588) doesn't descend as far as the rest of the
characters. It really produces some ugly output with that one included.

Including the space character means that you lose a nice baseline if the input
is fairly sparse, so it looks less like a bar graph and more like just some
random blobs.

~~~
carterschonwald
Yes, on the mac it seems only menlo renders it correctly, (vs all the other
fixed with font families that bork the rendering in various ways)

------
jmah
Ah, as inspired by Edward ttyfte.

~~~
huhtenberg
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.

~~~
zyfo
I was about to upvote compensate you before I read your edit.

~~~
huhtenberg
Well. When I posted the above comment, its parent was lingering at the very
bottom of the page. Then it quickly floated to the top, and after that mine
got as quickly downvoted into oblivion. Interesting dynamic in itself.

Right now the karma counter keeps oscillating around 4600... which makes me
regret that I didn't say it was 4701 :)

------
zx2c4
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
        ▂▃▄▃▃▃▄▃▇▃▄▄▄▅▃▄▄▄▅▅▅▄▄▄▃▃▃▃▃▄▃▄█▅▄▄▄▄▃▇▄▄▄█▄▃▄▄▄▄▃▃▄▅▄▅▃▃▃▃▇▄▅▄▇▃▅▃▄▃▄▃▇▃▃▄▇▃▄▃▄▃▃▃▄▃▃▃▃▃▃▅▃▄▃▃

------
raphman
Nice: found a spark _line_ generator at
<http://sandbox.kidstrythisathome.com/louis/> :

⡠⠞⠉⠙⠦⣀⠴⠋⠉⠳⢄⡠⠞⠉⠙⠦⣀⠴⠋⠉⠳⢄

~~~
Groxx
Needs a lot more characters to handle height progressions and angles better,
but that's awesome.

------
scottyallen
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.

~~~
Chirono
Try changing line 120 to

    
    
      echo -e $"$(print_tick $number)\c"
    

And it should work fine.

~~~
rnadna
I found it necessary to escape the backslash

    
    
             echo -e $"$(print_tick $number)\\c"

------
bch
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.

~~~
IgorPartola
Sparklines Wikipedia page: <http://en.wikipedia.org/wiki/Sparkline>

spark, the linked project, is just an implementation of a sparkline generator
for the command line.

~~~
bch
Thanks! First time I've heard of "sparkline". Of course I've seen these items
for as long as I can remember, but I just call them "graphs". :P

~~~
teej
A sparkline is a specific type of graph used for certain types of data. The
wiki page is pretty clear with the uses and limitations.

Not all graphs are created equal, it's important to use the right tool for the
job. This tool isnt just a graph generator, it's a spark bar chart generator
that's compact enough to fit in the command line. Overall a cool idea.

~~~
bch
I feel like I'm being reprimanded. Forgive me if I'm mistaken.

> A sparkline is a specific type of graph

My point is this should be explained _somewhere_. Anybody else unfamiliar with
sparklines will now have the benefit of this thread. Previously, to me anyway,
it was a mystery.

> The wiki page is pretty clear with the uses and limitations.

It is. It was only presented upon my initial query, and am grateful to
@IgorPartola for providing!

> Not all graphs are created equal, it's important to use the right > tool for
> the job. This tool isnt just a graph generator, > it's a > spark bar chart
> generator that's compact enough to fit in > the > command line. Overall a
> cool idea.

It is, indeed. My initial note wasn't about the coolness of the project, just
"what _is_ the project"? Is clear now. Anybody else who is ignorant about
sparklines as I was, enjoy this thread!

------
kablamo
Cool. I also like that he set up a wiki where people can contribute
interesting spark one liners:

<https://github.com/holman/spark/wiki/Wicked-Cool-Usage>

~~~
kvermeer
All involve awk or sed. That cuts out a large portion of the potential
userbase...

Perhaps common uses could be wrapped in options to the script? For instance,
an option to graph numbers on separate lines, to graph all numbers in the
input in order, to graph a specific column of information (like passing
through cut first) or to graph commonly graphed sources?

~~~
Oompa
I feel like they're examples of really awesome use cases, so it shouldn't
matter if people can't use them. Not to mention, I feel like this tool is
targeted for terminal junkies who likely already have awk/sed.

~~~
gwern
Basically. Are there very many people who would generate sparklines, using a
sh program - somewhere that has sh but not awk or sed?

------
0xdeadc0de
<https://github.com/bitly/data_hacks>

------
adaml_623
Sparklines are cool. This is just a bar graph and not nearly as useful.

~~~
knowtheory
So, because you can't deviate below the x axis this is really that much less
useful?

~~~
abrowne
This also doesn't meet the high resolution part of Tufte's definition ("a
small intense, simple, word-sized graphic with typographic resolution"[1]).

[1]: [http://www.edwardtufte.com/bboard/q-and-a-fetch-
msg?msg_id=0...](http://www.edwardtufte.com/bboard/q-and-a-fetch-
msg?msg_id=0001OR&topic_id=1)

~~~
tel
They're _comparatively_ higher density...

~~~
abrowne
This gives you eight levels (plus blank)[1]. Most of the type I read is at
least twice that many pixels high.

[1]:<https://github.com/holman/spark/blob/master/spark#L46>

~~~
tel
Tufte honestly thinks pixelated type is pretty terrible, too. 16 pixel density
is embarrassing compared to printed or pressed text.

But in either case, it's obvious that's a silly argument. Trends posterized to
8 levels are far easier to read in "sparkbar" form than as a list of numbers.
It's suboptimal, but better than the plain list.

------
jvoorhis
I hooked this up to my homebrew cohort-analysis script and saw a gratifying
terminal hockeystick :D

------
yycom
a bit more efficient, and without the comma requirement

<https://gist.github.com/1366926>

------
ieure
Because I want my shell prompt to be a giant graph.

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

Ship it.

~~~
smackfu
Does HN really not have any protection against comments that are very long
single words that screw up the page width?

------
mfukar
What would be really interesting is finding out which decent programming fonts
can show block elements. I mean, beyond the DejaVu Sans Mono fiasco.

~~~
gurraman
<http://www.levien.com/type/myfonts/inconsolata.html>

~~~
icebraining
This is what I've been using (after more than a year with DejaVu Sans Mono)
and I sometimes still stop to admire my terminal ;)

Using #e8e8e8 instead of pure white for the text color helps too.

------
yycom
<https://gist.github.com/1366875> (python)

~~~
rogerallen
thanks. here's a couple bugfixes. fixed width calc & handles negative #s

<https://gist.github.com/1368454>

------
craigkerstiens
Here's a port of it to Python already live:

<https://github.com/kennethreitz/spark.py>

~~~
RyanMcGreal
Here's my effort: <https://gist.github.com/1368953>

------
philjackson
I would rather it took a number, one per line from stdin. Great idea though.

~~~
icebraining
Try this:

    
    
        alias spark='tr "\\n" "," | xargs spark'

------
jcfrei
had basically the same idea a while back - but would have used standard ascii
characters and written it in c... still cool though!

------
hasantayyar
this should be utf-8 supported.

------
jongraehl
cool, but:

$ spark 3,4,9 ▃▇▇

huh?

~~~
gwern
A fixed bug <https://github.com/holman/spark/issues/19> With HEAD:

    
    
        $ spark 3 4 9
        ▃▄▇

------
thechut
Holman never fails to impress

------
skeletonjelly
Blogs on swearing are so last week. This week is Holman week.

Just an observation.

------
sktrdie
This is sort of useless. Giving visual meaning to a bunch of numbers means
nothing. It's just a bunch of numbers.

