This file contains hidden or 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
| package framework.utils; | |
| import java.io.FileInputStream; | |
| import java.io.IOException; | |
| import java.util.Properties; | |
| public final class AppConfig { | |
| private static Properties properties; |
This file contains hidden or 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
| Optional.ofNullable(properties.getProperty(key)) | |
| .filter(value -> value != null || !value.isEmpty()) | |
| .orElse(AnotherValue); |
This file contains hidden or 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
| pip list --outdated | sed 's/ (.*Latest: /==/g;s/ \[.*//g' |
This file contains hidden or 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
| from typing import Any, Dict | |
| class PropertyTypeMixin: | |
| """ | |
| Enforce type checking of attributes at runtime | |
| """ | |
| _properties_type: Dict[str, Any] = {} | |
| def __setattr__(self, key, value): |
This file contains hidden or 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
| parser = argparse.ArgumentParser(description="input `a=b&c=d` becomes `dict({'a':'b', 'c':'d'})`") | |
| parser.add_argument( | |
| "-p", "--params", | |
| help="Convert parameters in the form `--params a=b&c=d` to a dictionary", | |
| action=type('', (argparse.Action,), dict( | |
| __call__=lambda a, _, n, v, __: setattr(n, a.dest, dict([kv.split('=') for kv in v.split('&')])) | |
| )), | |
| default={}, | |
| ) |
This file contains hidden or 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 find_all(session: Session, offset: int, limit: int, order_by: str = "", filters: Optional[list] = None, joins: Optional[list] = None): | |
| if not filters: | |
| filters = [] | |
| if not joins: | |
| joins = [] | |
| query = session.query(self._model_type) | |
| if joins: | |
| query = query.join(*joins) |
This file contains hidden or 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
| from alembic import config | |
| from alembic import script | |
| from alembic.autogenerate import compare_metadata | |
| from alembic.runtime import migration | |
| from alembic.runtime.environment import EnvironmentContext | |
| # other imports ... | |
| def assert_database_is_up_to_date(): | |
| """ Database is up to date with migration head version """ |
This file contains hidden or 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
| import traceback | |
| from typing import Optional, Union | |
| def format_exception(exception: Optional[Union[Exception, BaseException]]) -> str: | |
| """ Format a prettier exception trace """ | |
| if exception: | |
| return f"\n{type(exception).__name__} Exception: {exception}" f"\n{''.join(traceback.format_tb(exception.__traceback__))}" | |
| return " Exception." |
This file contains hidden or 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
| import traceback | |
| from typing import Optional, Union | |
| def format_exception(exception: Optional[Union[Exception, BaseException]]) -> str: | |
| """ Format a prettier exception trace """ | |
| if exception: | |
| return f"\n{type(exception).__name__} Exception: {exception}" f"\n{''.join(traceback.format_tb(exception.__traceback__))}" | |
| return " Exception." |
OlderNewer