import time


def ago(past_timestamp):
        """
        Returns a string, the number of days, hours, minutes, or seconds ago a timestamp is.

        Example output:
        5h30m ago
        3d5h ago
        2m30s ago
        """
        time_diff = int(time.time() - past_timestamp)
        time_diff_units = []
        for unit, unitname in [(86400, "d"), (3600, "h"), (60, "m"), (1, "s")]:
                u = time_diff // unit
                if u > 0:
                        time_diff_units.append(str(u))
                        time_diff_units.append(unitname)
                        time_diff -= u * unit
                if len(time_diff_units) >= 4:
                        break
        return "".join(time_diff_units) + " ago"