Get min and max value in PHP Array

Option 1. First you map the array to get those numbers (and not the full details): $numbers = array_column($array, ‘weight’) Then you get the min and max: $min = min($numbers); $max = max($numbers); Option 2. (Only if you don’t have PHP 5.5 or better) The same as option 1, but to pluck the values, use … Read more

How to extract top-level domain name (TLD) from URL

Here’s a great python module someone wrote to solve this problem after seeing this question: https://github.com/john-kurkowski/tldextract The module looks up TLDs in the Public Suffix List, mantained by Mozilla volunteers Quote: tldextract on the other hand knows what all gTLDs [Generic Top-Level Domains] and ccTLDs [Country Code Top-Level Domains] look like by looking up the … Read more

python pandas extract year from datetime: df[‘year’] = df[‘date’].year is not working

If you’re running a recent-ish version of pandas then you can use the datetime attribute dt to access the datetime components: In [6]: df[‘date’] = pd.to_datetime(df[‘date’]) df[‘year’], df[‘month’] = df[‘date’].dt.year, df[‘date’].dt.month df Out[6]: date Count year month 0 2010-06-30 525 2010 6 1 2010-07-30 136 2010 7 2 2010-08-31 125 2010 8 3 2010-09-30 84 … Read more

What is so wrong with extract()?

I find that it is only bad practice in that it can lead to a number of variables which future maintainers (or yourself in a few weeks) have no idea where they’re coming from. Consider this scenario: extract($someArray); // could be $_POST or anything /* snip a dozen or more lines */ echo $someVariable; Where … Read more

Read Content from Files which are inside Zip file

If you’re wondering how to get the file content from each ZipEntry it’s actually quite simple. Here’s a sample code: public static void main(String[] args) throws IOException { ZipFile zipFile = new ZipFile(“C:/test.zip”); Enumeration<? extends ZipEntry> entries = zipFile.entries(); while(entries.hasMoreElements()){ ZipEntry entry = entries.nextElement(); InputStream stream = zipFile.getInputStream(entry); } } Once you have the InputStream … Read more