Skip to content

Instantly share code, notes, and snippets.

Erenor / Countries iso-alpha-2 and iso-alpha-3 array
Created Jul 28, 2021
A simple array. indexed by iso-alpha-2, to convert country codes
View Countries iso-alpha-2 and iso-alpha-3 array
$countries = array (
'AF' =>
array (
'alpha2' => 'AF',
'alpha3' => 'AFG',
'full' => 'Afghanistan',
'AL' =>
array (
'alpha2' => 'AL',
Erenor /
Last active Feb 16, 2020
[PYTHON 3.6] A simple class used to create random names based on syllables dictionaries
# Needed built-in modules
import random
# Randomic names for "whatever"
class MyRandomName:
"""Class used to create randomized names based on syllables-ish lists
Tested with Python 3.6
Erenor / function-random-string-to-hex-color.php
Last active Feb 16, 2020
[PHP] A simple function to get a 6-chars hexadecimal color starting from any string
View function-random-string-to-hex-color.php
* Function takes a random string and returns an hex color in the 6-digits format
* @param string $input
* @return string
function meow_str_to_hex_color($input) {
//characters that we do not want into an hex color
$replace = range('g', 'z');
Erenor / php-comparison-with-two-equal-signs.php
Created Jun 14, 2018
[PHP] The comparison with two equal signs
View php-comparison-with-two-equal-signs.php
//to be used when you are not really sure about the outcome of a comparison, or when you get an "unexpected" result
$a = array( 'a', 0, '0', false, null, );
$b = $a;
foreach($a as $temp) {
foreach($b as $meow) {
echo var_export($temp, true) . ' == ' . var_export($meow, true) . ' : ' . var_export($temp == $meow, true);
echo '<br>';
Erenor / remove-duplicates-from-array.js
Last active May 23, 2018
[JAVASCRIPT] Function to remove duplicate items from an array of objects, using "key" as comparison (other keys are not considered)
View remove-duplicates-from-array.js
* Function to remove duplicate items, using "key" as comparison (other keys are not considered)
function ereUniques(arr, key) {
var len = arr.length;
var seen = [];
var final = [];
var finalCounter = 0;
var i, innerItem;
for (i = 0; i < len; i++) {
Erenor / ereg-workaround-for-php-7.php
Last active May 23, 2018
[PHP] Workaround for the absent "ereg()" function, in PHP 7+
View ereg-workaround-for-php-7.php
//make sure the function is not already there ;-)
if (!function_exists('ereg'))
function ereg($pattern, $string, $matches = null)
//quote delimiters, if already present in the pattern (ereg does not have delimiters)
$pattern = preg_quote($pattern, '~');
Erenor / countries-no-accents.php
Last active May 23, 2018
[PHP] Array of world countries (code => label), without special chars
View countries-no-accents.php
//an array of countries indexed by their country code
//names do NOT contain special or accented chars
$countriesByCountryCode = array (
'AF' => 'Afghanistan',
'AX' => 'Aland Islands',
'AL' => 'Albania',
'DZ' => 'Algeria',
'AS' => 'American Samoa',
Erenor / italian-provinces.php
Last active May 22, 2019
[PHP] Array of italian provinces (code => label) ordered by province's name, with accents (e.g. "Forlì") and single quotes (e.g. "L'Aquila") where needed
View italian-provinces.php
//we use double quotes to avoid having to escape the single quote within the city of L'Aquila
//accents are not html encoded: use UTF8 to ensure they will not be transformed to something strange
$provinces = array (
'AG' => "Agrigento",
'AL' => "Alessandria",
'AN' => "Ancona",
'AO' => "Aosta",
'AR' => "Arezzo",
'AP' => "Ascoli Piceno",