Skip to content

Instantly share code, notes, and snippets.

@tdebatty
tdebatty / SumAggregator.java
Created June 9, 2016 07:53
Helper class to perform the sum of a large number of values (sum aggregation).
import java.util.ArrayList;
/**
* Helper class to perform the sum of a large number of values.
* A double value in java only has 15 significant digits. Hence, when performing
* the sum of a large number of double values, the precision of the result
* may be highly altered. For example, if performing the sum of 1E9 values,
* the result only has 6 significant digits. This helper class performs the
* addition using groups of 1E5 values. The result has 10 significant digits,
* for sums of up to 1E10 values.
@tdebatty
tdebatty / delete_older_than.php
Last active July 19, 2024 07:42
A simple PHP function to delete files older than a given age. Very handy to rotate backup or log files, for example...
<?php
/**
* A simple function that uses mtime to delete files older than a given age (in seconds)
* Very handy to rotate backup or log files, for example...
*
* $dir String whhere the files are
* $max_age Int in seconds
* return String[] the list of deleted files
*/
@tdebatty
tdebatty / NNDescent.php
Last active August 29, 2015 13:56
NN-Descent - A PHP implementation of NN-Descent algorithm : "Efficient k-nearest neighbor graph construction for generic similarity measures"
<?php
/* A quick and dirty PHP implemenation of NNDescent algorithm, as proposed in the paper
* Efficient k-nearest neighbor graph construction for generic similarity measures
* http://dl.acm.org/citation.cfm?id=1963487
*
*/
/**
* The algorithm can be used with any kind of item, as long as some
* similarity metric is defined