PHP – Generate Luhn checksum (for valid account numbers)
Here's a function to calculate the Luhn checksum of a 15 digits account number (the checksum'll be the 16th digit) :
-
public function luhnChecksum($accountNumber) {
-
-
// Buffer
-
$sum = 0;
-
-
// Process each digit
-
for ($i = 0; $i < 15; $i++) {
-
$digit = $accountNumber{$i};
-
-
// each 2 digits
-
if ($i % 2 == 0) {
-
$double = $digit * 2;
-
-
// if over 10, sum of the 2 digits
-
if ($double > 10) {
-
$double = (string)$double;
-
$sum += ((int)$double{0} + (int)$double{1});
-
} else {
-
$sum += $digit;
-
}
-
} else {
-
$sum += $digit;
-
}
-
}
-
-
// Euclidian division
-
$rest = $sum % 10;
-
-
// luhn key
-
$key = 10 - $rest;
-
-
return $key;
-
}
Article for teaching purposes.
I can not in any way be held liable for its use
TYPO3 – Change files/images upload limit
Today I'll explain how to change the limit for files, images and other medias upload.
To do the trick, you have multiple changes to make.
Javascript – Test if variable is numeric
Here's a simple way to check if a variable is numeric or not in javascript
-
function isNumeric(input) {
-
return (input - 0) == input && input.length > 0;
-
}
Enjoy
TYPO3 – Get content element from extension code
I've not wrote something from long time, so today I give you a little snippet.
If you have to use in your extension a content element from another page, you can use this function to get it from it's uid :
-
function loadContentElement($uid) {
-
-
'tables' => 'tt_content',
-
'source' => $uid,
-
'dontCheckPid' => 1,
-
);
-
-
return $this->cObj->RECORDS($conf);
-
}
Google Maps – Center and fit map to a group of markers
Today I'll explain how you can center and auto zoom to the correct value your map to fit a group of markers.
Suppose that we have our map called myMap and a group of markers called markers (^.^')
