Hacker News new | past | comments | ask | show | jobs | submit login
Sedtris: Tetris in sed (doslash.org)
82 points by waterhouse on April 10, 2011 | hide | past | favorite | 15 comments



For learning about sed, this is the best resource that I've seen so far:

http://www.grymoire.com/Unix/Sed.html



Weird, I posted this exact same link with the same title a month ago: http://news.ycombinator.com/item?id=2303109

Does HN use the URL as a primary key or something else?


IIRC* , posts get rejected if the same URL is in the part of the history in memory. HN loads its data off disk on-demand, and it gets restarted every once in a while. Dupes can get submitted more easily after a recent restart, if nobody else has caused that comment thread to load. This means there isn't an explicit time-out for reposts, just a non-deterministic cut-off. I'd guess it's roughly 6-9 months.

* Please correct me if I'm wrong!

Also, it's all too easy for a good post to get buried by a bunch of lame submissions, then fall off the new page before getting enough upvotes. It'd probably be worth making submissions cost a few points karma; the current system blindly rewards submitting anything others are likely to post.


If you want to learn sed, I once wrote a multi-part article explaining various sed one-liners:

http://www.catonmat.net/blog/sed-one-liners-explained-part-o...

Personally one of my favorite article series that I have written.




Uh oh, you threw the stone in the proverbial argument well again:

http://news.ycombinator.com/item?id=2420509


You should be piping that into bash instead of sh.

With sh, it infinitely prints out

    [: 48: unexpected operator
    read: 48: Illegal option -s


Haha, I take it you're on Ubuntu? Ubuntu uses dash[0] as its default shell to speed things up. Funny thing is I've run into this same issue before in another context with sh vs bash on Ubuntu. In any case, updated.

0: https://secure.wikimedia.org/wikipedia/en/wiki/Debian_Almqui...


Ubuntu uses dash as its default shell to speed things up.

Actually it is (sadly) the major reason, but not the only one:

The Debian policy manual has long mandated that "shell scripts specifying '/bin/sh' as interpreter must only use POSIX features"; in fact, this requirement has been in place since well before the inception of the Ubuntu project. Furthermore, any shell scripts that expected to be portable to other Unix systems, such as the BSDs or Solaris, already honoured this requirement. Thus, we felt that the compatibility impact of this change would be minimal. [1]

Personally I think that assuming nothing but POSIX is a more compelling reason than efficiency.

[1] https://wiki.ubuntu.com/DashAsBinSh


You know I almost specified my distribution but thought 'surely that wouldn't make a difference'. lol


I downloaded and played it. It didn't disappoint!

I was left wondering whether the game speeds up, though, and if so, how it works. Anyone know?


It doesn't speed up. The sed program will wait forever for input, so it has no set speed.

The helper bash script gives it input once a second.

It uses the "read" command to check for input from you, and it will wait 1 second. If it gets no input it sends the sed program an enter.

Unfortunately "read" can not have timeouts less than a second (it doesn't support fractions of a second).

If you want, you could replace "read" with a different program that accepts shorter timeouts. And presumably you could have the bash script slowly decrease the timeout.





Consider applying for YC's Spring batch! Applications are open till Feb 11.

Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: