• 2 Posts
  • 10 Comments
Joined 1 year ago
cake
Cake day: July 9th, 2023

help-circle


  • it doesn’t unravel the underlying complexity of what it does… these alternative syntaxes tend to make some easy cases easy, but they have no idea what to do with more complicated cases

    This can be said of any higher-level language, or API. There is always a cost to abstraction. Binary -> Assembly -> C -> Python. As you go up that chain, many things get easier, but some things become impossible. You always have the option to drop down, though, and these regex tools are no different. Software development, sysops, devops, etc are full of compromises like this.






  • grep -r string .

    The flag should go before the pattern.

    -r to search recursively, . refers to the current directory.

    Why use . instead of *? Because on it’s own, * will (typically) not match hidden files. See the last paragraph of the ‘Origin’ section of: https://en.m.wikipedia.org/wiki/Glob_(programming). Technically your ls command (lacking the -a) flag would also skip hidden files, but since your comment mentions finding the string in ‘any files,’ I figured hidden files should also be covered (the find commands listed would also find the hidden files).

    EDIT: Should have mentioned that -R is also recursive, but will follow symlinks, where -r will ignore them.


  • Can you describe your use case more?

    I don’t think format matters - if you’ve got multiple processes writing simultaneously, you’ll have a potential for corruption. What you want is a lock file. Basically, you just create a separate file called something like my process.lock. When a process wants to write to the other file, you check if the lock file exists - if yes, wait until it doesn’t; if no, create it. In the lock file, store just the process id of the file that has the lock, so you can also add logic to check if the process exists (if it doesn’t, it probably died - you may have to check the file you’re writing to for corruption/recover). When done writing, delete the file to release the lock.

    See https://en.wikipedia.org/wiki/File_locking, and specifically the section on lock files.

    This is a common enough pattern there are probably libraries to handle a lot of the logic for you, though it’s also simple enough to handle yourself.


  • This is approximately what I do as well, and would highly recommend. The one caveat I would add is while you are researching things you might want to do, take note of the subset of things you most want to do, and make sure you know what days/times they are open, if you need to book in advance, etc. I am very against having a hard schedule, but I also don’t want to travel somewhere only to miss the one thing I was really looking forward to because I decided “I’ll do that tomorrow,” only to find out it was closed the next day.

    An additional pro-tip: Make your first list of things you might want to do ahead of time, and name it after the place you are going, e.g. “New York.” Then while you’re traveling, make a second list of “favorites”, e.g. “New York Favorites.” Keep track of all the restaurants, activities, view points, etc that you enjoyed using that second list. Then whenever someone asks for recommendations for a particular location, you can just send them your favorites list.