Skip to content

Instantly share code, notes, and snippets.

@msg7086
Last active December 29, 2015 03:48
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save msg7086/7609816 to your computer and use it in GitHub Desktop.
Save msg7086/7609816 to your computer and use it in GitHub Desktop.
t/90174
<?php
function myfilter($src, $limit = 5)
{
$ips = array_map(function ($entry) { return $entry['ip']; }, $src);
$ipcount = array_count_values($ips);
$filtered_data = array_filter($src, function ($entry) use ($ipcount, $limit) { return $ipcount[$entry['ip']] >= $limit; });
return $filtered_data;
}
def myfilter src, limit = 5
ips = src.inject(Hash.new(0)) { |ips, entry| ips[entry[:ip]] += 1 ; ips }
src.select { |entry| ips[entry[:ip]] >= limit }
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment