In the middle of the desert you can say anything you want
Providing a __main__.py
along with __init__.py
makes the package itself executable:
$ python -m module_name
__main__.py
would have an usual if __name__ == "__main__" block
and run stuff imported from other files of that package.
(From a python riddle at work)
Things declared in if __name__ == '__main__'
are in global scope. Not because it’s special, but because ..global scope. All these bugs go away if you move main()
to a separate function.
Code from SO answer:[^2]
In main:
>>> if __name__ == '__main__':
... x = 1
... print 'x' in globals()
True
Inside a function:
>>> def foo():
... if __name__ == '__main__':
... bar = 1
... foo()
... print 'bar' in globals()
False
Python doesn’t have block-local scope, so any variables you use inside an if block will be added to the closest enclosing “real” scope.
Someone mentioned that if __name__ == '__main__'
can happen anywhere in the code. Never thought about this
If sync is enabled, in settings -> Sync there’s a “Deleted files” with versions and actions.
If not, unless a setting is set to delete to Obsidian’s trash, it’s left to the filesystem, so trash can or extundelete
in my case or whatever.
Link by M.O.: nix-community/nix-data-science: Standard set of packages and overlays for data-scientists [maintainer=@tbenst]
Detectron’s Instances object gets created like this, creating attributes with names unknown initially:
def __init__(self, image_size: Tuple[int, int], **kwargs: Any):
"""
Args:
image_size (height, width): the spatial size of the image.
kwargs: fields to add to this `Instances`.
"""
self._image_size = image_size
self._fields: Dict[str, Any] = {}
for k, v in kwargs.items():
self.set(k, v)
Which is neat.
To create an Instances object for unit tests I did:
pred_boxes = Boxes(tensor(
[
[ 143.8892, 1166.6632, 1358.7292, 1411.6588],
[ 131.3727, 864.3126, 1355.7804, 1144.3668],
[ 585.6373, 747.7184, 922.6433, 815.9998]
]))
scores = tensor(
[0.9971, 0.9967, 0.9938]
)
pred_classes = tensor([3, 3, 3])
instances = Instances(
image_size=(2122, 1500),
scores=scores,
pred_classes=pred_classes,
pred_boxes=pred_boxes
)
Found this in old markdown code from my old blog, I guess I forgot about this:
<what@ever.com>
<https://example.com>
When opening a lot of files as vim -p *.md*
only 10 kept being opened, finally googled it.
Solution: adding set tabpagemax=50
to ~/.vimrc
From SO1:
find . -name '*.php' -exec sed -i -e 's/www.fubar.com/www.fubar.ftw.com/g' {} \;
title: “211121-2123 Undoing git add / unstaging files” tags:
Two different questions here! Both options are: 1
If you add a file for the first time, git rm --cached .
or git -rm -r --cached .
will reverse that.
If you want to un-add changes to a file that’s already in the repo, git reset <file>
/ git reset
will undo that.
(heard at work)
The basic concept of mob programming is simple: the entire team works as a team together on one task at the time. That is: one team – one (active) keyboard – one screen (projector of course).
— Marcus Hammarberg, Mob programming – Full Team, Full Throttle1
“”Mob programming is a software development approach where the whole team works on the same thing, at the same time, in the same space, and at the same computer. “Mob code review is a software development approach where the whole team reviews on the same thing, at the same time, in the same space, and at the same computer.”2