1. PHP / Говнокод #5088

    +160

    1. 01
    2. 02
    3. 03
    4. 04
    5. 05
    6. 06
    7. 07
    8. 08
    9. 09
    10. 10
    11. 11
    12. 12
    13. 13
    14. 14
    15. 15
    16. 16
    17. 17
    18. 18
    19. 19
    20. 20
    21. 21
    22. 22
    23. 23
    24. 24
    25. 25
    26. 26
    27. 27
    28. 28
    29. 29
    30. 30
    31. 31
    32. 32
    33. 33
    34. 34
    35. 35
    36. 36
    37. 37
    38. 38
    39. 39
    40. 40
    41. 41
    42. 42
    43. 43
    44. 44
    45. 45
    46. 46
    47. 47
    48. 48
    49. 49
    50. 50
    51. 51
    52. 52
    53. 53
    54. 54
    55. 55
    56. 56
    57. 57
    58. 58
    59. 59
    60. 60
    61. 61
    62. 62
    63. 63
    64. 64
    65. 65
    66. 66
    67. 67
    68. 68
    69. 69
    70. 70
    71. 71
    72. 72
    73. 73
    74. 74
    75. 75
    76. 76
    77. 77
    78. 78
    79. 79
    80. 80
    81. 81
    82. 82
    83. 83
    84. 84
    85. 85
    86. 86
    87. 87
    88. 88
    89. 89
    90. 90
    91. 91
    92. 92
    93. 93
    94. 94
    95. 95
    96. 96
    #!/usr/bin/php5
     
    <?php
    set_time_limit(0);
    //include("crypt.php");
     
    exec("rm jtv.zip");
    exec("wget http://www.teleguide.info/download/new3/jtv.zip"); //скачать архив телепрограммы в формате itv.zip//
    exec("rm list/*.* "); //очистить каталог "list"//
    exec("unzip -x jtv.zip -d list "); //извлеч файлы из архива в папку "list"//
    sleep(3);
     
    $dir = "/home/tt/wwwplaylist/list/";
     
    exec("ls list | grep '.ndx'", $tmplist);
    $ch = array(
    1=>1,2=>2,3=>3,250=>195,241=>196,209=>197,177=>168,
    //170=>198,186=>199,191=>200,174=>201,172=>202,189=>203,188=>204,
    //161=>205,171=>206,187=>207,211=>208,223=>209,212=>210,210=>211,
    //245=>212,213=>213,181=>214,254=>215,222=>216,218=>217,219=>218,
    //217=>219,253=>220,221=>221,175=>222,180=>223,199=>192,252=>193,
    //233=>194,226=>195,228=>196,224=>197,173=>168,229=>198,231=>199,
    //234=>200,235=>201,232=>202,239=>203,238=>204,236=>205,196=>206,
    //197=>207,201=>208,230=>209,198=>210,244=>211,246=>212,242=>213,
    //251=>214,249=>215,214=>216,220=>217,248=>218,163=>219,216=>220,
    //251=>214,249=>215,214=>216,220=>217,248=>218,163=>219,216=>221,
    215=>222,131=>223,0=>220);
      
    $serveraddress="localhost";
    $mysqluser="root";
    $mysqlpassword="12345";
    $mysqldatabase="pl";
     
    $descriptor = mysql_connect($serveraddress,$mysqluser,$mysqlpassword);
    mysql_select_db($mysqldatabase,$descriptor);
    mysql_query("SET NAMES CP1251");
     
    mysql_query("truncate table TV_epg");
     
    function int2float($i) {
          $x32 = 4294967296;
          $i = (float)$i;
          if ($i < 0) return $i + $x32 + 1; else return $i; /* signed int32 overflow */
    }
     
    function FILETIMEtoUNIXtime($FILETIME) {
      $x32 = 4294967296;
      $sec_btw_epoch = (float)(116444736 * 100);
      $low  =        (ord($FILETIME[0])) | (ord($FILETIME[1]) << 8) | (ord($FILETIME[2]) << 16) | (ord($FILETIME[3]) << 24);
      $high =        (ord($FILETIME[4])) | (ord($FILETIME[5]) << 8) | (ord($FILETIME[6]) << 16) | (ord($FILETIME[7]) << 24);
      $f64 = (int2float($high) * $x32 + int2float($low)) / 10000000;
      return (int)($f64 - $sec_btw_epoch);
    }
     
    foreach ($tmplist as $key=>$value) {
        $f=substr($value, 0, -4);
        $res=$f;
     
        for($i=0; $i<strlen($res); $i++) $res[$i]=(array_key_exists(ord($res[$i]),$ch)) ? chr($ch[ord($res[$i])]) : $res[$i];
     
        $f1=fopen("list/".$f.".ndx", "rb");
        $f2=fopen("list/".$f.".pdt", "rb");
     
        $test1 = bin2hex(fread($f1, 1));
        $test2 = bin2hex(fread($f1, 1));
        $countpr = hexdec($test2.$test1);
     
    for ($i=0; $i<$countpr; $i++ )
    {
        $tmp=0;
        $ft='';
        $tmp = fread($f1, 2);
        for ($j=0; $j<8; $j++)
        $ft.= (fread($f1, 1));//.$ft;
     
        $dates= date("Y-m-d H:i:s", FILETIMEtoUNIXtime($ft));
     
    //////////////index f2////////////
        $offset=0;
        $str = bin2hex(fread($f1, 1));
        $str2 = bin2hex(fread($f1, 1));
        $offset = hexdec($str2.$str);
    ///////////////name////////////////
        $len=0;
        fseek($f2, $offset);
        $str = bin2hex(fread($f2, 1));
        $str2 = bin2hex(fread($f2, 1));
        $len = hexdec($str2.$str);
        $name = fread($f2, $len);
     
        mysql_query("insert into `TV_epg` set `epg_ch`='$res',`epg_date`='$dates',`epg_name`='$name' ");
        }
    }
            #mysql_quuery("update TV_epg set epg_date=epg_date-interval 4 hour;");
            mysql_query("update TV_epg set epg_date=epg_date-interval 1 hour;");
    ?>

    qbasic, 28 Декабря 2010

    Комментарии (17)
  2. PHP / Говнокод #5087

    +157

    1. 01
    2. 02
    3. 03
    4. 04
    5. 05
    6. 06
    7. 07
    8. 08
    9. 09
    10. 10
    11. 11
    12. 12
    13. 13
    14. 14
    15. 15
    16. 16
    17. 17
    18. 18
    19. 19
    20. 20
    21. 21
    22. 22
    23. 23
    24. 24
    25. 25
    26. 26
    27. 27
    28. 28
    29. 29
    30. 30
    31. 31
    32. 32
    33. 33
    34. 34
    35. 35
    36. 36
    37. 37
    38. 38
    39. 39
    40. 40
    41. 41
    42. 42
    43. 43
    44. 44
    45. 45
    46. 46
    47. 47
    48. 48
    49. 49
    50. 50
    51. 51
    52. 52
    53. 53
    54. 54
    55. 55
    56. 56
    57. 57
    58. 58
    59. 59
    60. 60
    61. 61
    62. 62
    63. 63
    64. 64
    65. 65
    66. 66
    67. 67
    68. 68
    69. 69
    70. 70
    71. 71
    function get_file_info($glob, $freq = 0)
    {
      static $cache = array();
    
      if (isset($cache[$glob])) {
    
        return $cache[$glob];
    
      } else {
    
        $ret = new stdClass;
    
        $g = glob($glob);
    
        $test = trim(`ls $glob`);
        $g = split( "\n", $test );
        if (!is_array($g)) {
          return $ret;
        }
    
        $g = array_reverse($g);
    
        $ret->files = array();
        $now = time();
        $first = true;
    
        foreach($g as $filename) {
    
          $f = new stdClass;
    
          $f->name = $filename;
          $f->size = @filesize($f->name);
          $f->size_str = sprintf("%.1f",$f->size/1024/1024);
    
          if (preg_match("((\\d{12}))", $f->name, $m)) {
        $t = strtotime($m[1]);
        $f->time = $t;
        $f->time_str = str_replace(" ", " ", date("M d, Y H:i T", $f->time));
    
        if ($freq) {
          
          $to = $t + $freq - $now;
    
          if ($to < 0) {
            if ($to > -600) {
              $res = '<em>any moment now.</em>';
            } else {
              $res = '<em>please consult /dev/urandom</em>';
            }
          } else {
            $h = floor($to/3600);
            $m = floor(($to - $h * 3600) / 60);
            
            if ($h) {
              $res = $h . ' hour'.($h==1?'':'s').' and ' . $m . ' minute'.($m==1?'':'s');
            } else {
              $res = $m . ' minute'.($m==1?'':'s');        
            }
          }
    
          $f->next = $res;
        }
    
          }
    
          $ret->files[] = $f;
        }
    
        return $ret;
      }
    }

    Говнокод на сайте php.net :)
    Исходник: http://snaps.php.net/?source

    P.S. это еще цветочки, после обеда будет зачетный с http://www.php.net/source.php?url=/index.php

    wmmorgun, 28 Декабря 2010

    Комментарии (10)
  3. C++ / Говнокод #5086

    +166

    1. 01
    2. 02
    3. 03
    4. 04
    5. 05
    6. 06
    7. 07
    8. 08
    9. 09
    10. 10
    11. 11
    12. 12
    13. 13
    14. 14
    for (i=0; i<n; i++){
    		for (int j=0; j<n; j++){
    			if (x[i]>x[j] && x[i]-x[j] > zx && (y[i]>y[j] && y[i]-y[j] > zy) || (y[i]<y[j] && y[j]-y[i] > zy)){
    				zx = x[i] - x[j]; a1=i; a2=j;
    				if (y[i]>y[j] && y[i]-y[j] > zy && sum < zx + (y[i]-y[j])) zy = y[i] - y[j]; b1=i; b2=j; sum = zx + zy;
    				if (y[i]<y[j] && y[j]-y[i] > zy && sum < zx + (y[j]-y[i])) zy = y[j] - y[i]; b1=i; b2=j; sum = zx + zy;
    			}
    			if (x[i]<x[j] && x[j]-x[i] > zx && (y[i]>y[j] && y[i]-y[j] > zy) || (y[i]<y[j] && y[j]-y[i] > zy)){
    				zx = x[j] - x[i]; a1=i; a2=j;
    				if (y[i]>y[j] && y[i]-y[j] > zy && sum < zx + (y[i]-y[j])) zy = y[i] - y[j]; b1=i; b2=j; sum = zx + zy;
    				if (y[i]<y[j] && y[j]-y[i] > zy && sum < zx + (y[j]-y[i])) zy = y[j] - y[i]; b1=i; b2=j; sum = zx + zy;
    			}
    		}
    	}

    нахождение координат двух наиболее отдаленных точек среди заданных=)

    ALIVE-SpiriT, 28 Декабря 2010

    Комментарии (110)
  4. JavaScript / Говнокод #5085

    +159

    1. 01
    2. 02
    3. 03
    4. 04
    5. 05
    6. 06
    7. 07
    8. 08
    9. 09
    10. 10
    11. 11
    12. 12
    13. 13
    14. 14
    15. 15
    16. 16
    17. 17
    18. 18
    19. 19
    20. 20
    21. 21
    22. 22
    23. 23
    24. 24
    25. 25
    26. 26
    27. 27
    28. 28
    29. 29
    30. 30
    31. 31
    32. 32
    33. 33
    34. 34
    35. 35
    36. 36
    37. 37
    38. 38
    39. 39
    40. 40
    41. 41
    42. 42
    43. 43
    44. 44
    45. 45
    46. 46
    47. 47
    48. 48
    49. 49
    50. 50
    51. 51
    52. 52
    53. 53
    54. 54
    55. 55
    56. 56
    57. 57
    58. 58
    59. 59
    60. 60
    61. 61
    62. 62
    63. 63
    64. 64
    /** Связанный JavaScript **/
    /*	
    	var script = new Array();
    	var s = 0;
    	
    
    
    	linked = e.match(/<script type=("|')text\/javascript("|') src=("|').*?("|')><\/script>/gi);
    	
    	if (linked != null)
    	{
    		src_link = new Array();
    		j = 0;
    		
    		for (i = 0; i < linked.length; i++)
    		{
    			e = e.replace(linked[i], '');
    			
    			new_link = linked[i].match(/src=("|').*?("|')>/gi);
    			
    			if (new_link != null)
    			{
    				script[s] = document.createElement('script');
    				script[s].setAttribute('type', 'text/javascript');		
    				script[s].id = 'JavaScript_' + hist.length + '_' + j;
    		
    				script[s].setAttribute('src', new_link[0].substr(5, (new_link[0].length - (5 + 2))));
    				
    				s++; j++;
    			}	
    		}
    	}
    	*/
    	/** Внедрённый JavaScript **/
    /*
    	e = e.replace(/[\r\n]/g, ' ');
    	intruded = e.match(/<script type=("|')text\/javascript("|')>.*?<\/script>/gi);
    		
    	if (intruded != null)
    	{			
    		for (i = 0; i < intruded.length; i++)
    		{
    			inner = '';
    		
    			e = e.replace(intruded[i], '');
    			inner = intruded[i].replace(/<script type=("|')text\/javascript("|')>/, '').replace(/<\/script>/, '');
    			
    			if (navigator.appName == 'Microsoft Internet Explorer')
    			{
    				script[s] = inner;
    			}
    			else
    			{
    				script[s] = document.createElement('script');
    				script[s].setAttribute('type', 'text/javascript');
    				script[s].id = 'JavaScript_' + hist.length + '_' + i;
    			
    				script[s].innerHTML = inner;
    			}
    			
    			s++;
    		}
    	}
    	*/

    А вставить в элемент и найти через getElementsByTagName("script") слишком просто :D

    Genka, 28 Декабря 2010

    Комментарии (4)
  5. PHP / Говнокод #5084

    +159

    1. 1
    2. 2
    3. 3
    function is_int_string ($str) {
    	return ((string)(int)($str) == $str);
    }

    Уже даже не помню зачем оно было нужно.

    byss, 27 Декабря 2010

    Комментарии (4)
  6. PHP / Говнокод #5083

    +152

    1. 1
    2. 2
    3. 3
    $result = mysql_query ("SELECT f.name, f.category, c.name AS cat_name, f.size, f.datetime, f.filename " .  
                           "FROM ${DB_PREFIX}_files AS f, ${DB_PREFIX}_categories AS c " .
                           "WHERE f.id=$id AND f.category = c.id");

    На момент написания совершенно не подозревал о существовании JOIN'а.

    byss, 27 Декабря 2010

    Комментарии (33)
  7. C++ / Говнокод #5082

    +173

    1. 1
    2. 2
    3. 3
    4. 4
    if (button == GLUT_LEFT_BUTTON && state == GLUT_DOWN)
        lb = true;
    else
        lb = false;

    Уроки какого-то умника по OpenGL. И вот такие "творения" на каждом шагу.

    psina-from-ua, 27 Декабря 2010

    Комментарии (15)
  8. ActionScript / Говнокод #5081

    −346

    1. 01
    2. 02
    3. 03
    4. 04
    5. 05
    6. 06
    7. 07
    8. 08
    9. 09
    10. 10
    11. 11
    if( isTarget )
    {
    	//Some code
    }
    else
    {
    	if( !isTarget )
    	{
    		//Some code
    	}
    }

    Слов нет

    Werdn, 27 Декабря 2010

    Комментарии (46)
  9. PHP / Говнокод #5080

    +146

    1. 1
    $dateStart = date('1900-01-01');

    Продолжая тему функции date(). Здесь он судя по всему ещё не добрался до документации.

    trinkl, 27 Декабря 2010

    Комментарии (0)
  10. Куча / Говнокод #5079

    +129

    1. 1
    2. 2
    3. 3
    4. 4
    5. 5
    6. 6
    <form method="POST" name="submit_form" action="form1.php"> 
    <input name="form" value="form" /> 
    < .... >
    <input type="submit" value="отобразить отчет" onclick="document.submit_form.action='form1.php';" />  
    <input type="submit" value="сохранить отчет" onclick="document.submit_form.action='form2.php';" />  
    </form>

    qbasic, 27 Декабря 2010

    Комментарии (8)