💾 Archived View for gemini.circumlunar.space › users › adiabatic › words › computing › snippets captured on 2024-08-18 at 17:32:48. Gemini links have been rewritten to link to archived content
⬅️ Previous capture (2024-05-10)
➡️ Next capture (2024-08-31)
-=-=-=-=-=-=-
The elites don’t want you to know this, but the snippets on the Web are free. You can take them home. I have 231 snippets.
— Alex Jones, in a different universe where he’s an automations enthusiast
I use TextExpander to turn easily-typed text into time-consuming-to-generate text.
All the shell-script ones are written in zsh since that’s the default shell on my system of choice, but they probably run identically in bash, and maybe even sh.
Fair warning: A bunch of these snippets use common UNIX programs. One of the problems with stringing together common UNIX programs like date(1), tr(1), and sed(1) is that they’re often implemented slightly differently depending on what UNIX(alike) you’re on.
These are, by far, my most important snippets. They save me the most time because I use them fantastically often and they save me from having to translate the current date and time into one format or another. Sure, I can read “18” off the date in the menu bar, but translating month names like “June” into their numeric counterparts like “6” is, worst case, an O(n) operation. The snippet I use most often is probably ;date:
%Y-%m-%d
It evaluates to the current date in YYYY-MM-DD format. It's especially handy for filenames where you want to ensure some kind of chronological ordering no matter what happens to modified or creation times.
Sometimes I want to write dates out longhand. Enter ;americadate, for dates like “July 18, 2022”:
#!/bin/zsh date "+%B %e, %Y" | tr -d '\n' | sed -E 's/ / /'
The first part spits out the date, the second part (after the |) removes the trailing newline, and the third part turns two consecutive spaces into one. This last twiddle is necessary because %e will write a space for single-digit days of the month, as in “ 9”, and we don’t want that.
Since I do weird things like write feeds by hand, I also get a fair bit of use out of being able to get an ISO 8601 date and time in UTC, so I have ;dtz, which gives me output like “2022-07-18T16:40:49Z”:
#!/bin/zsh TZ=UTC date "+%FT%TZ" | tr -d '\n'
I also get some use out of ;americadt, which gives times like “Monday, July 18, 2022 at 3:40:08 PM”:
#!/bin/zsh date "+%A, %B %e, %Y at %l:%M:%S %p" | tr -d '\n' | sed -E 's/ / /'
Finally, there’s ;isoweek, which generates strings like 2022-W29-1, but I’m not really a by-week person:
#!/bin/zsh date "+%Y-W%V-%u" | tr -d '\n'
I was using %W instead of %V up until just now, but a Stack Overflow page helped set me straight.
Stack Overflow: “Get date from ISO week number in Python [duplicate]”
More to come later. Probably. One day.
If you want a program to check this page on your behalf, have a look at the feeds on the site colophon:
⏚