viernes, 21 de diciembre de 2018

TIL: search-whitespace-regexp

Here's another little dwim emacs' feature that I didn't know it existed and I just noticed today when it didn't dwim'ed.

When searching for a string "foo     bar", multiple whitespaces are ignored, and strings with one whitespace between the 2 words is detected as a match anyway.

Here are some ways to fix it, or bypass it in a particular occasion.

miércoles, 19 de diciembre de 2018

A strange case of quoting shell vars

cat << ${FOO:-"{}"}
EOF


You got that? evaluate it in your shell. Now Put it into a file and try to "sh file.sh".  You're going to see the funny {"}.   Go figure...

  1. sh doesn't understand about nested {} inside {}
  2. Take into account that bash or zsh do, so none of this applies there, you have to test it on pure sh.
  3. ${FOO:-"{} is what gets interpreted as part of the variable
  4. as $FOO is not defined, '"{' should be outputted,
  5. leaving the final "{"}
  6. But nope. Because quotes inside a variable expansion do not pass through
  7. So the final {"}
  8. Bonus points for this not happening in bash
  9. More bonus points for this being inside a makefile that calls the file as $(SHELL) file.sh. And different platforms use different $(SHELL) by default.
  10. Mine (ubuntu) uses /bin/sh (which is linked to /bin/dash), others might use busybox, and MacOS uses something that does not do any of the above (zsh?)

martes, 18 de diciembre de 2018

Linux extended file attributes

I just discovered a couple of nice linux commands that seem to be quite orthogonal and suckless, and that probably allow for all sorts of nice tricks.

Extended attributes are like the -rwxrwxrwx but allow for more subtle meanings.

On the one hand we have chattr, which allows to add about 10 different attributes to files and directories with a very specific meaning:
  • a - append only
  • c - compressed
  • d - no dump
  • e - extent format
  • i - immutable
  • j - data journaling
  • s - secure deletion
  • t - no tail-merging
  • u - undeletable
  • A - no atime updates
  • D - synchronous directory updates
  • S - synchronous updates
  • T - top of directory hierarchy

On the other hand, we have the command 'attr' (not nstalled by default in ubuntu, but it's just one apt-get away).

This one serves as a kind of general tag:value system for files and directories.  It feels like it's a feature that can be overused to extremes to create not only tagging systems but acls (there's already getfacl), complex permissions or just hide info in this kind of "plists" scoped by file.

miércoles, 12 de diciembre de 2018

3 basic org agenda tips for the fundamentally forgetful

I've been trying to use org mode for the last 5 years, and the system always fails in one way or another.

  • When I have too many types of templates, I doubt which template should I use.
  • When I set for too many tags, I forget about them (and I dont' know how to search for them anyway), so I don't use them.
  • When I use datetree for org-capture definitions, I never know where to find the things and end up using c-s. Multiple reasons here:
    • There's some missbehaving on the change of a month. Not sure how to fix it but it messes up my trees.
    • If  entries are supposed to be refiled anyway to their "final" topic, no need to keep a structural context when capturing.
  • Having 2 different capture one beginning with TODO and the other not.

Any of these mean total failure unless you're already a very well organized person and can hold the system.  And they lead to not using org consistently, which leads to not using it efficiently, which means it's useless.

But lately I seem to have found something that kinda works.


#1. Use 1 template


So, only 1 capture template.


   ("t" "Todo" entry (file+headline "~/org/tasks.org" "Tasks")
    "* %^{title} \n  SCHEDULED:%t\n  %?\n %i\n  %a\nAdded: %U")

This creates a plain entry sequentially under "* Tasks".  You know that "up" means before, and "down" means after. If you ever start using refile or tags properly, then I guess you'll add them to the mesh, but for now, leave it like this.

#2. Schedule everything to not miss it


Schedule everything. Get used to use scheduling.  Although being incapable of using org mode in a decent way, I've read its whole manual (more than once). And I know there's a bunch of different timestamps that mean different things. DEADLINE, SCHEDULED, <active timestamps> and [inactive timestamps].  

Usual advice is to use active timestamps for things that will happen anyway, no matter what (birthdays?, new years,..). Inactive is for "meta" logging of when you created the entry, or a date you want to be clickable, but not visible in the agenda.  DEADLINE and SCHEDULE also have their own subtle meanings.

I just want something that appears in front of me when I press 'c-c a a' (for a given date), and if I think it's not relevant anymore, I'd have to have a way to say "ok, do not bother me anymore with that".

So with SCHEDULED, it works, and if the day passes and you haven't done anything about it, it carries over to next day, so you will end up doing something about it (or having a huge overdue list).

So yeah. 'c-c c-s' all (most) of your entries.

#3. ] == reflog


So I created a couple of items in a trance, and after 10 minutes I'm like: "ok, let's review those items"....  And I realize I forgot to add a schedule date (usually I schedule for the same day if I want to review later).

Old me would blame himself for not being organized enough, and go through the huge tasks.org, trying to grep for the year-month (if we had the datetree), or was it month-year? who knows.  Going over many different datetrees for supposed different topics. most of them half forgotten.

The trick here is a magic unknown keybinding on your agenda view: ']'.  What it does is it displays the inactive timestamps in your agenda, as if they were active.

And as we added the '%U' pattern in the single org-capture template, we know all our items will have an inactive timestamp of its creation. So you can see it as a reflog you can use to see your activity in "diary mode".

lunes, 10 de diciembre de 2018

bash and python pills

So you know bash sucks, but it's the best we have to do process orchestration and pipes and all that kind of stuff.

Here are a few lists of knowledge pills that are kind of related.

  • You are writing bash, and there's clearly a list of things (patterns) you do over and over. Here's a list of some common things
  • You have some shellscripts but some depend on linux/bsd programs and you'd like to make them pure bash. Or you're just the curious type that wants to know "what would this look in pure bash".
  •  Until you realize you should start moving all your bash crap to something different. What about python?
  • Python is great, but it's not without wtfs.

sábado, 8 de diciembre de 2018

Dark themes for the browser

If you're spending many hours a day at your computer, chances are the white background of the average web site causes some visual stress to you (that's why we use low contrast themes in our editors and terminals.)

Changing css styles of websites you visit can be done with userstyles (custom css's loaded by your browser), but until now, all plugins I've found to manage them sucked in one way or another. Here's my experience:

The most successful strategy I had until 2 days ago was using stylus with one of its "Global dark style", but the problem with those generic themes is that some pages go very wrong with them, and then you have to manually disable them for those sites, and maybe find an ad-hoc dark style for them.

That was the case with Slack, HackerNews, Reddit, Github (which are 80% of my browsing anyway).

But this week I discovered Dark Reader, and I'm so happy with it I can't believe it.

Just give it a try. It just works.

EDIT: I'm noticing added load and lag when loading some pages, but for now it's nothing that outweights the benefits, so for now, it stays