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: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);