This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class AutoIncrementIDMeta(type): | |
__counter = {} | |
def __call__(cls, *args, **kwargs): | |
if cls.__name__ not in cls.__counter: | |
cls.__counter[cls.__name__] = 0 | |
cls.__counter[cls.__name__] += 1 | |
instance = super().__call__(*args, **kwargs) | |
instance.id = cls.__counter[cls.__name__] | |
return instance |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
code --list-extensions | xargs -L 1 echo code --install-extension > install_extensions.sh |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def seconds_to_midnight() -> int: | |
now = datetime.now() | |
midnight = now + timedelta(days=1) | |
midnight = midnight.replace(hour=0, minute=0, second=0, microsecond=0) | |
return (midnight - now).seconds |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class QuerysetBatchIterator: | |
def __init__(self, qs, batch_size=1000): | |
self.qs = qs | |
self.batch_size = batch_size | |
self._total = None | |
def __iter__(self): | |
for start in range(0, self.total, self.batch_size): | |
end = min(start + self.batch_size, self.total) |