Skip to content

Instantly share code, notes, and snippets.

View omry's full-sized avatar

Omry Yadan omry

View GitHub Profile
@omry
omry / config.yaml
Created March 6, 2021 10:29
Hydra C++ example
app: ${hydra:runtime.cwd}/main
db:
driver: mysql
user: omry
password: secret
@omry
omry / my_app.py
Created September 17, 2020 22:47
recursive example
# Copyright (c) Facebook, Inc. and its affiliates. All Rights Reserved
from dataclasses import dataclass, field
from typing import Any, List
from omegaconf import MISSING, II, OmegaConf
import hydra
from hydra.core.config_store import ConfigStore
from hydra.utils import instantiate
@omry
omry / recursive_example_my_app.py
Created September 17, 2020 22:32
Recursive instantiation usage prototype
# Copyright (c) Facebook, Inc. and its affiliates. All Rights Reserved
from dataclasses import dataclass, field
from typing import Any, List
from omegaconf import MISSING, II, OmegaConf
import hydra
from hydra.core.config_store import ConfigStore
from hydra.utils import instantiate
@omry
omry / Override.g4
Last active July 26, 2020 16:05
Hydra-interpolations-grammar
// Copyright (c) Facebook, Inc. and its affiliates. All Rights Reserved
// Regenerate parser by running 'python setup.py antlr' at project root.
// If you make changes here be sure to update the documentation (and update the grammar in command_line_syntax.md)
grammar Override;
single_override : override EOF;
overrides_file : override ('\n' override)*;
override: (
from typing import Any, Dict
class Singleton(type):
_instances: Dict[type, "Singleton"] = {}
def instance(cls: Any, *args: Any, **kwargs: Any) -> Any:
return cls(*args, **kwargs)
def __call__(cls, *args: Any, **kwargs: Any) -> Any:
from contextlib import contextmanager
from typing import Any
@contextmanager
def foo() -> Any:
print("1 before")
yield
print("1 after")
from contextlib import contextmanager
from typing import Any
@contextmanager
def foo() -> Any:
print("1 before")
yield
print("1 after")
@omry
omry / 1.py
Created June 23, 2020 23:09
dual_use_context
from contextlib import contextmanager
from typing import Any
@contextmanager
def foo() -> Any:
print("1 before")
yield
print("1 after")
@omry
omry / config.yaml
Created June 11, 2020 09:34
Hydra flask example
server:
host: 127.0.0.1
port: 8081
app:
username: ${env:USER}
flask:
ENV: production
DEBUG: false