def as_int(x, default=0):
    """Convert a thing to an integer.

    Args:
        x (object): Thing to convert.
        default (int, optional): Default value to return in case the conversion fails.

    Returns:
        int: `x` as an integer.
    """
    try:
        return int(x)
    except ValueError:
        return default