Live data from Hacker News

A spreadsheet in fewer than 30 lines of JavaScript, no library used

jsfiddle.net

221–230 of 274 posts

Re: A spreadsheet in fewer than 30 lines of JavaScript, no library used

#222
post #93

It's not really comparable, but minimalistic spreadsheet applications always remind me of Dan Piponi's Haskell `loeb` function [0]---a "one-line" "spreadsheet" "implementation". The blog post is very interesting to read, but here's the meat. We're looking for a function with type loeb :: Functor f => f (f a -> a) -> f a and without thinking about the meaning of it, we can implement it as loeb x = fmap (\a -> a (loeb…

One more cool trick from the same article (slightly modified). It's a factorial function computed on an "infinite spreadsheet". But how?

    fact = loeb fact' where
      fact' 0 _ = 1
      fact' n f = n*f (n-1)
If we ask GHC for the type of `fact'` then we see that it is

    Int -> ((Int -> Int) -> Int)
which we can interpret via the `Reader Int` monad as being

    m (m Int -> Int)
    -- for 
    m a = (Int -> a)
Now, `f :: (Int -> a)` as a functor is isomorphic to an infinite stream

    map f [0, 1, ...]
if we ignore the negative numbers. So we can think of `fact'` as having the type

    Stream (Stream Int -> Int)
where each function in the stream takes its own index and multiplies it by the value at the previous index.

Then `loeb` completes the computation using spreadsheet recursion.

Re: A spreadsheet in fewer than 30 lines of JavaScript, no library used

#225
post #191

Earlier quoted context omitted.

Just goes to show how much the far left and the far right has influence over our society

Eh, it's pretty easy to get things not on the far side of the screen; it's just hard to get it precisely in the center.

Center something vertically :). Or even better, create three divs, arranged horizontally, with a different amount of text such that all the divs are the same width and height. Note that you cannot specify a height for the parent since the text may be of arbitrary length. Makes me sad every time.

Re: A spreadsheet in fewer than 30 lines of JavaScript, no library used

#226
post #213

I thought the spreadsheet was mad impressive and decided to take a shot at making it massively multiplayer. Here's the fiddle: http://jsfiddle.net/sy85U/

Warning: Don't click it. This fiddle spams infinite javascript alerts.

Re: A spreadsheet in fewer than 30 lines of JavaScript, no library used

#227
post #30

Are there any more full-featured libraries that people use for this? I've found SpreadJS[0], GelSheet[1], jQuery.Sheet[2], and ZK Spreadsheet, but none seem like thriving open-source projects as far as I can tell. [0] http://wijmo.com/demo/spreadjs/samples/index.html [1] http://www.gelsheet.org/demo [2] http://visop-dev.com/Project+jQuery.sheet [3] http://www.zkoss.org/product/zkspreadsheet

Styles and Graphs - Spreadsheet GNU GPLv2 : http://www.simple-groupware.de/cms/Spreadsheet/Home

Keep thinking I need to convert this to JS: Spreadsheet formulas that build web applications - http://www.youtube.com/watch?v=oogKKfbRyMQ (2 Min)

Re: A spreadsheet in fewer than 30 lines of JavaScript, no library used

#229
post #153
post #49

Awesome job! Very clever :) After seeing it working and the few clever lines of code I was really surprised. But then I though: oh, let me go back to HN and read the comments from people saying "BUT IT DOESN'T HAVE CHARTS!!!" and unfortunately comments like that are here. What is wrong with this poeple???

Apart from the fact that I think (as far as the comments that are on now) you are exaggerating quite a bit with "BUT IT DOESN'T HAVE CHARTS!!!", I also think there's no need to suggest that there's anything 'wrong' with those people. There's the downvote button if something is really not fruitful for discussion (remember though discussion is - to a respectful extent - often enriched when people differ in their views…

I still don't have the down vote option :(

And the reason why I point these critics out is that they are simply not reasonable if you know what is happening there. Perhaps having a top level comment like this may actually encourage them to think twice or try to learn before commenting?

But you know, maybe this is just a mirror to what happens almost daily in companies where there are non-technical people making decisions. Imagine this "excel-like app" being presented by the author to his boss, a non-technical person, as something extra that he built and is all excited about. There is a good chance that his boss will make the bad comments that it is lacking a lot of features. That is probably why these people make such comments: they don't have a clue of what is going on.

Post reply on HN