[HN Gopher] Sed challenge: join cal -y months into a single column
       ___________________________________________________________________
        
       Sed challenge: join cal -y months into a single column
        
       Author : jolmg
       Score  : 26 points
       Date   : 2021-11-17 16:26 UTC (6 hours ago)
        
 (HTM) web link (jol.dev)
 (TXT) w3m dump (jol.dev)
        
       | clon wrote:
       | At what point should you give up writing a sed "program" and just
       | write a few lines of Python to arrive at an answer? Seems he went
       | way past that point.
        
         | fragmede wrote:
         | _> Of course, I just looked at the calendar and counted_
        
         | azalemeth wrote:
         | Is answering the challenge he answered with python actually
         | easier? I know _counting the weeks_ is easier, but is parsing
         | text like a ninja far less verbose in posix-like tools?
         | Learning awk made me much more productive, at the very least...
        
         | jolmg wrote:
         | It was even easier to just count with my finger. :)
         | 
         | The point was a sed challenge. Challenges are fun sometimes.
         | 
         | It was also a good exercise for doing things with sed. There
         | are times when sed is the most terse way to shape text to how
         | you want it. It's also very portable.
        
       | raspyberr wrote:
       | I really like the start of your blog. Please do consider adding
       | RSS/Atom support. I'll add you to my feed if you do.
        
       | tlackemann wrote:
       | org-mode blog! How do you like it? Been considering this for
       | myself recently but haven't looked into RSS much. I like the
       | theme you built.
        
         | jolmg wrote:
         | > org-mode blog! How do you like it?
         | 
         | I've just gotten started! I think it's comfortable in the sense
         | that I won't need to copy and paste stuff to and from the
         | terminal and can just code from the same file and see how the
         | result changes. That's really neat!
         | 
         | I imagine I'll be feeling restricted at some point, since I'm
         | not doing custom HTML for each post, and I want to keep the org
         | file readable on its own, so no excessive markup.
         | 
         | > I like the theme you built.
         | 
         | Thanks, though it's really almost no styling. The syntax
         | highlighting is done by the ruby library `rouge`. The colors
         | were just black on white, but the Dark Reader Firefox extension
         | I have installed would change that to these off-black and off-
         | white colors, and I liked it, so I set them in the CSS.
        
       | jez wrote:
       | This is super cool--I've wanted something notebook-like for blog
       | posts in the past, and I had no clue it was possible in org-mode!
       | 
       | I can also empathize with the desire for a single-column calendar
       | output, but my first instinct wasn't to implement it with sed:
       | 
       | https://github.com/jez/calz
       | 
       | Substantially more lines than the sed implementation, but also
       | more feature rich, because I can do things like
       | calz from last month to next month         calz from now to feb
       | 
       | etc. Also: pretty colors.
        
         | jolmg wrote:
         | > This is super cool--I've wanted something notebook-like for
         | blog posts in the past, and I had no clue it was possible in
         | org-mode!
         | 
         | Thanks! You can access the org file by changing the URL
         | extension from .html to .org. Maybe I should make that a link.
        
       | raziel2p wrote:
       | Wow. I've only ever used sed for simple regex operations, reading
       | this has opened up a whole new world for me.
       | 
       | ... I will force myself not to make use of it because you're a
       | bad influence and I already have to stop myself from using too
       | much grep/sed/awk magic, but this is seriously impressive, and an
       | entertaining read. Well done!
        
         | jolmg wrote:
         | Thank you for the kind words! :)
        
         | mananaysiempre wrote:
         | I can't bring myself to write blog posts, but here's a
         | precedence parser in sed as part of a solution for last year's
         | Advent of Code #18 (https://adventofcode.com/2020/day/18):
         | #!/bin/sh -eu       set -o pipefail            sed -E \
         | -e 's/([+*])\s*([0-9]+)/ \2 \1 /g' \       -e ':parens' \
         | -e 's/([+*])\s*(\([^()]+\))/ \2 \1 /g' \       -e
         | 's/\(([^()]+)\)/ \1 /g' \       -e '/\(/bparens' \       -e
         | 's/\s+/ /g' -e 's/^ //' -e 's/ $//' \       -e '$a\' -e '[+
         | z1<r]sr z1<r p' | \       dc
         | 
         | (I'm very, very sorry for fuelling your addiction.)
        
         | nvartolomei wrote:
         | How about a chess engine written in sed?
         | https://github.com/moldabekov/chess-
         | sed/blob/master/chess.se....
         | 
         | And accompanying blog post in Russian
         | https://habr.com/ru/post/191006/.
        
       | otherflavors wrote:
       | I'd have suggested to make this more challenging and only use
       | POSIX sed, but -y is not part of POSIX cal anyway
        
         | jolmg wrote:
         | Another way to make it more challenging would be to do
         | everything in a single `sed` call. Maybe it's for that kind of
         | script that features like `D`'s and `P`'s "up to the first
         | newline" detail become useful.
        
       ___________________________________________________________________
       (page generated 2021-11-17 23:00 UTC)