Computer Notes: Shortcuts
- If your browser is using a lot of RAM, it may be that you have visited a lot of websites which have silently installed service workers (programs which make websites fully or partially usable offline.) You can see whether there are service workers installed in Firefox by visiting about:debugging#/runtime/this-firefox
[not sure if this is right] Make website backups more rsync-friendly by zipping up the files beforehand. It will take less time to sync one file than thousands because you have to stat() the file system for each file. And don't forget the "archive file ordering" trick, courtesy of Gwern.
youtube-dl -F $URL shows the choices for video quality when downloading a video from $URL. youtube--dl -f $CHOICE $URL downloads the video at that quality. To automatically get the best quality, use youtube--dl -f best $URL.
macOS / OS X: open a minimized window: (1) Command + Tab until you get the app's icon. (2) Release Tab; keep holding Command. (3) Hold Option. (4) Release Command and Option. From here.
macOS / OS X: F1 and F2 increase and decrease the brightness of your screen -- but there's a hidden shortcut, Option-Shift-F1/F2, which lets you fine-tune the brightness in increments 1/10 as large as the normal shortcut.
Gimp: "Shift-q" is Quick Mask. While selecting, use quick mask to paint areas into or out of the selection, by painting in black or white. I would like to learn more about masking features...
HTML <code> tags are for code of any kind, including HTML tags. To mark up a keyboard command, use the <kbd> tag. (:h/t HTML Hell; that link also shows the proper way to mark up a "hamburger" menu icon.)
LaTeX text sizes, from biggest to smallest: \Huge, \huge, \LARGE, \Large, \large, \normalsize (default), \small, \footnotesize, \scriptsize, \tiny
To clear a suggestion from a Firefox text-entry area, highlight the suggestion, and type SHIFT-Del.
Python:
When working with nested loops in list comprehensions remember that the for clauses remain in the same order as in our original for loops. Trey Hunner
While == and != are equality operators, is and is not are identity operators.Python’s is operator asks about the identity of an object: are the two objects on either side of the is operator actually the same exact object.
We’re not just asking are they equal, but are they stored in the same place in memory and in fact refer to the same exact object.
[...]
By default, Python’s == operator delegates to is. Meaning unless two variables point to the exact some object in memory, == will return False [...] This is true by default… but many objects in Python overload the == operator to do much more useful things when we ask about equality.
Derived classes may override methods of their base classes. Because methods have no special privileges when calling other methods of the same object, a method of a base class that calls another method defined in the same base class may end up calling a method of a derived class that overrides it. (For C++ programmers: all methods in Python are effectively virtual.) https://docs.python.org/3/tutorial/classes.html#inheritance
Behind the scenes, the for statement calls iter() on the container object. The function returns an iterator object that defines the method __next__() which accesses elements in the container one at a time. When there are no more elements, __next__() raises a StopIteration exception which tells the for loop to terminate. You can call the __next__() method using the next() built-in function; this example shows how it all works[...]
Having seen the mechanics behind the iterator protocol, it is easy to add iterator behavior to your classes. Define an iter() method which returns an object with a next() method. If the class defines next(), then iter() can just return self.
https://docs.python.org/3/tutorial/classes.html#iterators
Adapted from Martin Heinz's blog:
In Python [...] everything is exported from a module, unless it defines __all__:
# my_module.py
def foo():
pass
def bar():
pass
__all__ = ["bar"]
If the above is written in my_module.py, then my_module import * will only import bar, and not foo. Alternatively, if __all__ is defined as an empty list, that same import statement will raise an AttributeError.