Skip to content

Instantly share code, notes, and snippets.

View tot-ra's full-sized avatar
🐝
Processing video with AI

Artjom Kurapov tot-ra

🐝
Processing video with AI
View GitHub Profile
@tot-ra
tot-ra / gist:5192168
Created March 18, 2013 23:53
Conversion of number to one of the countable forms in russian
function num2MultipleRus($int){
$str=strval($int);
$fin=$str[strlen($str)-1];
if ($fin==1) return 1;
elseif ($fin>1 && $fin<5) return 2;
elseif ($fin>4) return 3;
}
@tot-ra
tot-ra / gist:5192149
Last active December 15, 2015 03:09
Cyryllic transliteration to latin
function Translit_iso($str) {
$str=strtr($str,"абвгдезиклмнопрстуфцъыь","abvgdeziklmnoprstufс\"y’");
$str=strtr($str,"АБВГДЕЗИКЛМНОПРСТУФЦЪЫЬ", "ABVGDEZIKLMNOPRSTUFС\"Y’");
$str=strtr($str, array( "э"=>"eh", "х"=>"kh", "й"=>"jj", "ё"=>"jo", "ж"=>"zh", "ч"=>"ch", "ш"=>"sh", "щ"=>"shh", "ю"=>"yu", "я"=>"ya", "э"=>"eh", "х"=>"kh", "й"=>"jj", "ё"=>"jo", "ж"=>"zh", "ч"=>"ch", "ш"=>"sh", "щ"=>"shh", "ю"=>"yu", "я"=>"ya", "ї"=>"i", "ї"=>"yi", "є"=>"ie", "є"=>"ye" ));
return $str;
}
function toTranslit($text, $type = 'translit') {
$data = explode(" ", $text);
if (count($data) == '') {
@tot-ra
tot-ra / gist:5192145
Created March 18, 2013 23:51
UTF - Win1251 conversion
function win1251_utf8($s){
$t='';
for($i=0, $m=strlen($s); $i<$m; $i++)
{
$c=ord($s[$i]);
if ($c<=127) {$t.=chr($c); continue; }
if ($c>=192 && $c<=207) {$t.=chr(208).chr($c-48); continue; }
if ($c>=208 && $c<=239) {$t.=chr(208).chr($c-48); continue; }
if ($c>=240 && $c<=255) {$t.=chr(209).chr($c-112); continue; }
@tot-ra
tot-ra / gist:5192075
Created March 18, 2013 23:43
English stemmer
class StemmerEnglish{
function pluralize($word) {
$pos = strlen($word)-1;
// Check last letter
switch ($word{$pos}) {
case 's': // Maby already plural
if ($word{$pos-1} == 's')
return $word.'es';
@tot-ra
tot-ra / gist:5191093
Created March 18, 2013 21:43
Mobile client detection
/**
* @return bool|string
*/
function detectMobileDevice() {
$mobile_browser = false;
$user_agent = $_SERVER['HTTP_USER_AGENT'];
$accept = $_SERVER['HTTP_ACCEPT'];
switch(true) {
@tot-ra
tot-ra / gist:4251018
Created December 10, 2012 14:55
CRC calculations
function crc16($string, $crc = 0) {
for($x = 0; $x < strlen($string); $x++) {
$crc = $crc ^ ord($string[$x]);
echo $crc . '<br />';
for($y = 0; $y < 8; $y++) {
if(($crc & 0x0001) == 0x0001) {
$crc = (($crc >> 1) ^ 0x10589);