Skip to content

Instantly share code, notes, and snippets.

@dakaugu
dakaugu / timer.py
Last active July 4, 2019 11:25
Measure code execution time in Python
# coding=utf-8
import logging
import math
import time
from functools import wraps
logger = logging.getLogger(__name__)
@dakaugu
dakaugu / CalculateTimeAgo.java
Last active January 26, 2017 18:44
Calculate time ago, for social media, forum applications. Ex: "Just now", "a minute ago", "2 weeks ago", "5 years ago", "Yesterday"
public static String calculateTimeAgo(long timeStamp) {
long timeDifference;
long unixTime = System.currentTimeMillis() / 1000L; //get current time in seconds.
int j;
String[] periods = {"s", "min", "hour", "day", "week", "month", "year", "decade"};
// full time intervals like seconds, minutes, days and so on
double[] lengths = {60, 60, 24, 7, 4.35, 12, 10};
timeDifference = unixTime - timeStamp;
String tense = "ago";