This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def binary_search_all(li, target, left, right): | |
result = [] | |
while left <= right: | |
mid = left + (right - left) // 2 | |
if li[mid][0] == target: | |
result.append(li[mid][1]) | |
i = mid - 1 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
switch (province) { | |
case 'THR': | |
case 'TE': | |
return "تهران"; | |
case 'GIL': | |
case 'GI': | |
return "گیلان"; | |
case 'EAZ': |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function to_en( $string ) { | |
$persian = array( '۰', '۱', '۲', '۳', '۴', '۵', '۶', '۷', '۸', '۹' ); | |
$arabic = array( '٠', '١', '٢', '٣', '٤', '٥', '٦', '٧', '٨', '٩' ); | |
$english = range( 0, 9 ); | |
$converted = str_replace( $persian, $english, $string ); | |
$converted = str_replace( $arabic, $english, $converted ); | |
return $converted; | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
/** | |
* Iran's province and city php class | |
* @author Amin Rasouli <[email protected]> | |
* @version 1.0 | |
*/ | |
class City | |
{ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
String.prototype.toPersianDigit = function (a) { | |
return this.replace(/\d+/g, function (digit) { | |
var enDigitArr = [], peDigitArr = []; | |
for (var i = 0; i < digit.length; i++) { | |
enDigitArr.push(digit.charCodeAt(i)); | |
} | |
for (var j = 0; j < enDigitArr.length; j++) { | |
peDigitArr.push(String.fromCharCode(enDigitArr[j] + ((!!a && a == true) ? 1584 : 1728))); | |
} | |
return peDigitArr.join(''); |