Live data from Hacker News

You can read my blog posts using curl

mahdi.blog

41–50 of 73 posts

Re: You can read my blog posts using curl

#42

Earlier quoted context omitted.

I'm guessing you're on BSD (or maybe Apple)? Their version requires you to tell less there's a raw data at the input.

No, Debian 11. Fresh install too.

Very strange, I could have sworn I've tested in without -R with Debian 11 (I can't check, that laptop broke and my other machines are still at 10). Maybe it's terminal definition or something changed.

Terminal emulation is a spooking place full of ancient magic. One of the reasons why I assumed "modern defaults". It would turn "a weekend hack" into a session of misery. ;)

Re: You can read my blog posts using curl

#44
post #32
post #27

Earlier quoted context omitted.

Browsers send "Accept: text/html" explicitly. For my pastebin[1], I send an HTML document when "text/html" is in the list of accepted formats, and I just send the plain data otherwise. This seems to work in practice, doesn't hard-code knowledge about curl, and doesn't require curl users to add custom headers. [1]: https://sr.ht/~mort/coffeepaste/

I feel that neatly meets the kind of thing these params are for - if you ask a server for content and say "Accept: */*" the server should be free to return that content in whatever format it likes.

That format should probably be the original file then, the one that was uploaded/pasted.

Re: You can read my blog posts using curl

#45
post #30
post #17

If you know basic vim movements (j/k for down/up kind of basic stuff), you can pipe the output into less to read it in a more convenient way. Nothing major, just found it nicer to not have to scroll back up when the article loads Example: curl https://mahdi.blog/raw/self-hosted/ | less

The “less” program understands the standard cursor keys just fine; there is no need to use vi-style keys.

You can even use the scroll wheel (so can vim, accursedly)

Re: You can read my blog posts using curl

#46
post #20

A cool add-on to this would be a plugin that automatically redirected /latest to the latest blog post. That way, if the blogger were to publish say once a week every Tuesday, the user could alias the curl for maximum ease of use.

I once suggested this kind of strategy at a previous job...and internally, everyone liked it. But what ended up happening was: our fans of the content kept complaining that they were sharing the /latest url but "the website kept breaking" (in their mind) because last week it pointed to the blog post they wanted to share, and this week, its pointing to a different blog post, and please fix the website, etc. Clearly, o…

This is not a problem if you use proper redirects.

Re: You can read my blog posts using curl

#47

Two months ago I hacked something like that for my blog: curl https://fuse.pl/beton/10print.html # with code highlighting curl https://fuse.pl/beton/cegla.html # just prose

Damn that looks really polished. How does the server know what characters to send so that my specific command line interprets it in a nice way? Sorry if I'm not being very articulate. EDIT: doesn't work when piping to less.

> EDIT: doesn't work when piping to less.

What if you pass '-r' to less? (I can't verify myself because it worked without -r for me)

Re: You can read my blog posts using curl

#48

> To make this easily readable on small screens and terminals, I used vim’s text-width setting to make sure my lines do not exceed 80 characters: I never understand comments like these. Now if my terminal is 78 characters it is a mess or if it is 100 characters it is wasting space. If you just don't wrap the lines my terminal does it at the right width. Hard wrapping doesn't work well. You need to know the target wid…

I will never understand this obsession with 80 characters as if we still use MS-DOS.

Re: You can read my blog posts using curl

#49
post #27
post #10

In these comments people have suggested to check for the User-Agent, but wouldn't it make more sense to check if the Accept header mentions text/html? I realize that curl sends "Accept: / ", but if you wanted to see a page in plain text, you would have to pass -H "Accept: text/plain". I think that uses HTTP much more like it was intended.

Browsers send "Accept: text/html" explicitly. For my pastebin[1], I send an HTML document when "text/html" is in the list of accepted formats, and I just send the plain data otherwise. This seems to work in practice, doesn't hard-code knowledge about curl, and doesn't require curl users to add custom headers. [1]: https://sr.ht/~mort/coffeepaste/

Yup, I do the same with dotfilehub.com

E.G,

curl https://dotfilehub.com/knoebber/emacs

results in plain text

Re: You can read my blog posts using curl

#50

Two months ago I hacked something like that for my blog: curl https://fuse.pl/beton/10print.html # with code highlighting curl https://fuse.pl/beton/cegla.html # just prose

Looks fantastic! I can't read the post, but I think you can simplify the 10 print Python code to

  while True: print(choice("\\/"), end="")
(the `format` call doesn't seem needed and `choice` works on any iterable, including strings of characters).

Al Sweigart has a repository of "scroll art" similar to 10 print that might interest you: https://github.com/asweigart/scrollart

Post reply on HN