import re


def binder_spec_from_github_url(github_url):
    """
    Converts GitHub origin into a Binder spec.

    For example:
    git@github.com:SamLau95/nbinteract.git -> SamLau95/nbinteract/master
    https://github.com/Calebs97/riemann_book -> Calebs97/riemann_book/master
    """
    if github_url.endswith('.git'):
        github_url = github_url[:-4]
    tokens = re.split(r'/|:', github_url)
    # The username and reponame are the last two tokens
    return '{}/{}/master'.format(tokens[-2], tokens[-1])