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

    +161

    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
    function ss ($id){ // получить дату рождения по ИНН для украины
    
    $result = array();
    
        //sex
        $result['sex'] = (substr($id,8,1) % 2) ? 'M' : 'F';
    
        //birthdate
        $days = substr($id,0,5);
        $year = 1900; $day = 01; $month = 01;
        while ($days > 0)
            {
            $daysInYear = (checkdate (02, 29, $year)) ? 366 : 365;
            if ($days > $daysInYear)
                {
                $days -= $daysInYear;
                $year ++;
                }
            else{
                for ($daysInMonth = 31; !checkdate($month, $daysInMonth, $year); $daysInMonth–) ;
                if ($days > $daysInMonth)
                    {
                    $days -= $daysInMonth;
                    $month ++;
                    }
                else{
                    $day = $days;
                    $days = 0;
                    }
                }
            }
        $result['year'] = $year;
        $result['month'] = $month;
        $result['day'] = $day;
    
        return $result;
    }
    
    обходить каждый день начиная с 1900 это сила

    быстрее было бы

    $inn = '2322222222';
    $inn = substr($inn,0,5);
    $normal_date = date("d.m.Y", strtotime('01/01/1900 + ' . $inn . ' days - 1 days'));

    ggggg, 09 Сентября 2010

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

    +144

    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
    // Строк 50 кода
    
    
    
    <style>
    
      switch ($view_mod)
      {
    
        default :
    
          echo ('
            // Здесь для элементов разметки стили выводятся
            ');
    
        break;
    
        2 :
    
          echo ('
            // Соответственно здесь
          ');
    
        break;
    
        3 :
    
          echo ('
            // И здесь
          ');
    
        break;
    
      }
    
    </style>
    
    
    
    // Еще строк 250 кода
    
    
    
    if (!isset ($color_theme)) then
    {
      $color_theme=$def_color_theme;
    }

    В универе учат в основном Delphi, решил, что надо самостоятельно хорошо изучить что-нить еще. Решил попробовать PHP и непривычно постоянно с одного языка на другой перескакивать. Блин, eб@нулся, пока нашел ошибки on lines: 18, 26 и 44...

    RESIN, 09 Сентября 2010

    Комментарии (8)
  3. SQL / Говнокод #4205

    −128

    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
    CREATE TABLE IF NOT EXISTS `ls_user` (
      `user_id` int(11) unsigned NOT NULL AUTO_INCREMENT,
      `user_login` varchar(30) NOT NULL,
      `user_password` varchar(50) NOT NULL,
      `user_mail` varchar(50) NOT NULL,
      `user_skill` float(9,3) unsigned NOT NULL DEFAULT '0.000',
      `user_date_register` datetime NOT NULL,
      `user_date_activate` datetime DEFAULT NULL,
      `user_date_comment_last` datetime DEFAULT NULL,
      `user_ip_register` varchar(20) NOT NULL,
      `user_rating` float(9,3) NOT NULL DEFAULT '0.000',
      `user_count_vote` int(11) unsigned NOT NULL DEFAULT '0',
      `user_activate` tinyint(1) unsigned NOT NULL DEFAULT '0',
      `user_activate_key` varchar(32) DEFAULT NULL,
      `user_profile_name` varchar(50) DEFAULT NULL,
      `user_profile_sex` enum('man','woman','other') NOT NULL DEFAULT 'other',
      `user_profile_country` varchar(30) DEFAULT NULL,
      `user_profile_region` varchar(30) DEFAULT NULL,
      `user_profile_city` varchar(30) DEFAULT NULL,
      `user_profile_birthday` datetime DEFAULT NULL,
      `user_profile_site` varchar(200) DEFAULT NULL,
      `user_profile_site_name` varchar(50) DEFAULT NULL,
      `user_profile_icq` bigint(20) unsigned DEFAULT NULL,
      `user_profile_about` text,
      `user_profile_date` datetime DEFAULT NULL,
      `user_profile_avatar` varchar(250) DEFAULT NULL,
      `user_profile_foto` varchar(250) DEFAULT NULL,
      `user_settings_notice_new_topic` tinyint(1) NOT NULL DEFAULT '1',
      `user_settings_notice_new_comment` tinyint(1) NOT NULL DEFAULT '1',
      `user_settings_notice_new_talk` tinyint(1) NOT NULL DEFAULT '1',
      `user_settings_notice_reply_comment` tinyint(1) NOT NULL DEFAULT '1',
      `user_settings_notice_new_friend` tinyint(1) NOT NULL DEFAULT '1',
      PRIMARY KEY (`user_id`),
      UNIQUE KEY `user_login` (`user_login`),
      UNIQUE KEY `user_mail` (`user_mail`),
      KEY `user_activate_key` (`user_activate_key`),
      KEY `user_activate` (`user_activate`),
      KEY `user_rating` (`user_rating`),
      KEY `user_profile_sex` (`user_profile_sex`)
    ) ENGINE=InnoDB  DEFAULT CHARSET=utf8;
    [/code]
    очень актуально смотрится эта таблица с приведённой выше. очень умно сделать таблицу "топик-стартер" и не выделить отдельно профиль пользователя. что чаще используется в выборке? =)
    про миллионы пользователей и лайвстрит - не смешите, не верю (с)
    загнётся до прихода в БД

    дополнение к http://govnokod.ru/4203
    выделил отдельным гауно-кодом из-за того, что комично смотрится вместе с указанной выше таблицей. ну и ограничение длины комментов есть. ярые искатели оптимизаций видимо идут мимо. очень актуально смотрится эта таблица с приведённой выше. очень умно сделать таблицу админов в один колумн и не выделить отдельно профиль пользователя. что чаще используется в выборке? =)

    hybroid, 09 Сентября 2010

    Комментарии (18)
  4. Python / Говнокод #4204

    −83

    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
    #Access Point: MTS Internet GPRS
    import gprsd
     #импортируем класс GPRS-демона
    import socket
    import thread
    import math
    s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
    gs = gprsd.getConn()
     #сокет с телефоном
    ga = gprsd.getConnAddr()
     #конечный адрес
    s.connect(ga);
    def thread_1():
      global gs, s;
      while 1:
        for i in range(0, 10005000):tmp=math.sin(math.acos(random.randint(-100500, 100500)));
     #выполняем сложное и неоправданное арифметическое дейстивие 100500 раз в цикле
        tmp = s.recv(8);
        gs.send(tmp);
        if tmp<8:
          break;
    def thread_2():
      global gs, s;
      while 1:
        for i in range(0, 10005000):tmp=math.sin(math.acos(random.randint(-100500, 100500)));
     #выполняем сложное и неоправданное арифметическое дейстивие 100500 раз в цикле
        tmp = gs.recv(8);
        s.send(tmp);
        if tmp<8:
          break;
    
    thread.start_new_thread(thread_1, ());
    thread.start_new_thread(thread_2, ());

    Скрипт МТС'ного инета

    startapp, 09 Сентября 2010

    Комментарии (6)
  5. SQL / Говнокод #4203

    −125

    1. 1
    2. 2
    3. 3
    4. 4
    CREATE TABLE IF NOT EXISTS `ls_user_administrator` (
      `user_id` int(11) unsigned NOT NULL,
      UNIQUE KEY `user_id` (`user_id`)
    ) ENGINE=InnoDB DEFAULT CHARSET=utf8;

    Видимо сделать столбец 'administrator' в таблице `ls_user` и ставить в него 1 или 0 - это слишком просто.. Или тут скрыта какая-то оптимизация?
    Дамп спёрт из LiveStreet.

    hybroid, 08 Сентября 2010

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

    +158

    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
    <?php
    class WikiParser{
    private $p;
    function __construct($p){
    $this->p=$p;
    }
    function parse(){
    $this->p = preg_replace('/\[\[([^\/"?[=|]+?)\]\]/siu', '<a href="link.php?sea=$1">$1</a>', $this->p);
    $this->p = preg_replace('/\[\[([^\/"?[=|]+?)\|(.+?)\]\]/siu', '<a href="link.php?sea=$1">$2</a>', $this->p);
    $this->p = preg_replace('/\[\[([a-z]+?:\/\/[^"|]*?)\|([^"?[=|]+?)\]\]/siu', '<a href="$1">$2</a>', $this->p);
    $this->p = preg_replace('/\[\[([a-z]+?:\/\/[^"|]*?)\]\]/siu', '<a href="$1">$1</a>', $this->p);
    
    $this->p = preg_replace('/&lt;&lt;([^\/"?[=|]+?)&gt;&gt;/siu', '<a href="link.php?sea=$1">$1</a>', $this->p);
    $this->p = preg_replace('/&lt;&lt;([^\/"?[=|]+?)\|(.+?)&gt;&gt;/siu', '<a href="link.php?sea=$1">$2</a>', $this->p);
    $this->p = preg_replace('/&lt;&lt;([a-z]+?:\/\/[^"|]*?)\|([^"?[=|]+?)&gt;&gt;/siu', '<a href="$1">$2</a>', $this->p);
    $this->p = preg_replace('/&lt;&lt;([a-z]+?:\/\/[^"|]*?)&gt;&gt;/siu', '<a href="$1">$1</a>', $this->p);
    $this->p = preg_replace('/\*\*\*?([^"?=#%]+?)\*\*\*?/siu', '<b>$1</b>', $this->p);
    $this->p = preg_replace('/\-\-\-?([^"?=#%]+?)\-\-\-?/siu', '<s>$1</s>', $this->p);
    $this->p = preg_replace('/\/\/\/?([^"?=#%]+?)\/\/\/?/siu', '<i>$1</i>', $this->p);
    $this->p = preg_replace('/\r?\n\r?\n/', '</p><p>', $this->p);
    $this->p = preg_replace('/\n/', '<br/>', $this->p);
    $this->p = preg_replace('/\{\{locked\}\}/', '<table style="clear: both; width: 90%; border-color:#333333; border-style: solid; border-width: 1px 1px 1px 2px; padding: 2px; margin: 1px auto 1px auto; vertical-align: center; background-color: #fefefe; text-align: left;"><tr><td style="vertical-align: middle">Статья огорожена от <a href="link.php?sea=вапераст">ваперастов</a></td></tr></table>', $this->p);
    $this->p = preg_replace('/\{\{locked\|(.*?)\}\}/', '<table style="clear: both; width: 90%; border-color:#333333; border-style: solid; border-width: 1px 1px 1px 2px; padding: 2px; margin: 1px auto 1px auto; vertical-align: center; background-color: #fefefe; text-align: left;"><tr><td style="vertical-align: middle">Статья огорожена от $1</td></tr></table>', $this->p);
    $this->p = preg_replace('/\{\{недопись\}\}/siu', '<table style="clear: both; width: 90%; border-color:#333333; border-style: solid; border-width: 1px 1px 1px 2px; padding: 2px; margin: 1px auto 1px auto; vertical-align: center; background-color: #fefefe; text-align: left;"><tr><td style="vertical-align: middle"><b>Недопись</b><br>Ваша статья - Гавно. Короткая, тупая и малоинформативная</td></tr></table>', $this->p);
    $this->p = preg_replace('/\{\{недопись\|([^|]*?)\}\}/siu', '<table style="clear: both; width: 90%; border-color:#333333; border-style: solid; border-width: 1px 1px 1px 2px; padding: 2px; margin: 1px auto 1px auto; vertical-align: center; background-color: #fefefe; text-align: left;"><tr><td style="vertical-align: middle">Недопись<br>Ваша статья - $1</td></tr></table>', $this->p);
    $this->p = preg_replace('/\{\{moved\|(.*?)\}\}/', '<table style="clear: both; width: 90%; border-color:#333333; border-style: solid; border-width: 1px 1px 1px 2px; padding: 2px; margin: 1px auto 1px auto; vertical-align: center; background-color: #fefefe; text-align: left;"><tr><td style="vertical-align: middle"><b>Статья перемещена</b><br>--&gt;$1</td></tr></table>', $this->p);
    $this->p = preg_replace('/[[<]#[]>]/', '', $this->p);
    if(!preg_match('#^<p>.*</p>$#siu', $this->p)) $this->p='<p>'.$this->p.'</p>';
    $this->p = preg_replace('/<p><\/p>/siu', '', $this->p);   
    }
    function get(){return $this->p;}
    }
    ?>

    Без комментариев

    startapp, 08 Сентября 2010

    Комментарии (40)
  7. PHP / Говнокод #4201

    +161

    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
    function renameimage($dir,$file) 
      {
         $words=array('fuck','blia','fuck_you_spilberg','mazfaka','simpsons');
         $rand=array_rand($words);
         $type_foto=end(explode(".", $file));
         $new_name_of_foto=md5($rand[$words].$file).'.'.$type_foto;
         $ren=rename($dir.$file,$dir.$new_name_of_foto);
        if($ren)
        {
    	    return $new_name_of_foto;
        }
        else  
        {
    	    echo 'не получилось...<br>';
        }
      }

    пыщ-пыщ

    GoodTalkBot, 08 Сентября 2010

    Комментарии (3)
  8. SQL / Говнокод #4200

    −863

    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
    if (($pol) and ($brand)) {
        $result = mysql_query("SELECT * FROM inetmag WHERE pol = '$pol' AND brand = '$brand'");
    }
    ;
    if ((!$pol) and ($brand)) {
        $result = mysql_query("SELECT * FROM inetmag WHERE brand = '$brand'");
    }
    ;
    if (($pol) and (!$brand)) {
        $result = mysql_query("SELECT * FROM inetmag WHERE pol = '$pol'");
    }
    ;
    if ((!$pol) and (!$brand)) {
        $result = mysql_query("SELECT * FROM inetmag");
    }
    ;

    мой учитель сильно негодовал, и предложил вот это:
    $url = <<< TEXT
    SELECT *
    FROM inetmag
    WHERE
    pol = IF(LENGTH('$pol')<>0,('$pol'),pol)
    AND
    brand = IF(LENGTH ('$brand')<>0,('$brand'),brand)
    TEXT;
    $result = mysql_query($url);

    truedizzy, 08 Сентября 2010

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

    +150

    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
    <?php
    
    function DaysDiff($d1,$d2){
    	$d2=1+strtotime($d2);
    	$d1=1+strtotime($d1);
    	
    	return floor(($d2-$d1)/86400);
    }
    
    ?>
    
    а надо бы:
    
    <?php
    
    function DaysDiff($d1,$d2){
    	return bcdiv(strtotime($d2)-strtotime($d1),86400);
    }
    
    ?>

    ferry-very-good, 08 Сентября 2010

    Комментарии (48)
  10. PHP / Говнокод #4198

    +160

    1. 1
    2. 2
    3. 3
    <?php
    
    if (preg_match("/\.[gjpi][ipnc][fgo]/i", $_SERVER['REQUEST_URI'])) exit;

    user654321, 08 Сентября 2010

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