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

    0

    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
    <?
    //Ограничиваем время выполнения скрипта 3-мя минутами
    set_time_limit(180);
    
    //Подключаемся к MySQL, при неудаче выводим ошибку
    mysql_connect("localhost", "torrent", "password") or die("Could not connect to MySQL");
    
    //Выбираем БД, при неудаче выводим ошибку
    mysql_select_db("torrent") or die("Could not select database");
    
    //Переводим все общение с БД в кодировку utf8
    mysql_query("SET NAMES utf8");
    
    //Открываем файл указанный в url переменной "f"
    $fp = fopen($_GET[f], "r");
    
    //Запускаем цикл до конца строк в файле
    while (!feof($fp)) {
            //Считываем строку (да, функцию trim() выполнять не обязательно, но у каждого программиста свои "тараканы")
            $tmp = trim(fgets($fp));
            
            //Преобразуем строку в массив. За разделитель используем ";"
            $torrent = explode('";"', $tmp);
            
            //В первом и последнем элементе удаляем лишние символы "
            $torrent[0] = substr($torrent[0], 1);
            $torrent[6] = substr($torrent[6], 0, (strlen($torrent[6]) - 1));
            
            //Если раскомментировать следующую строку, то можно увидеть как распарсился первый торрент в файле
            //print '<pre>'; print_r($torrent); exit();
            
            //Вставляем данные текущего торрента в таблицу
            mysql_query("INSERT INTO `torrents` 
                (`name`,
                `hash`,
                `date`,
                `size`,
                `topic_id`,
                `cat_id`,
                `cat_name`) 
              VALUES 
                ('" . mysql_real_escape_string($torrent[4]) . "',
                '" . $torrent[3] . "',
                '" . $torrent[6] . "',
                '" . $torrent[5] . "',
                '" . $torrent[2] . "',
                '" . $torrent[0] . "',
                '" . mysql_real_escape_string($torrent[1]) . "')
            ");
    }
    //Закрываем файл
    fclose($fp);
    
    //Выводим сообщение о завершении работы
    print 'complete: ' . $_GET[f];
    ?>

    Импорт CSV в MySQL. Со швабры.

    gost, 23 Декабря 2015

    Комментарии (4)
  2. Куча / Говнокод #19219

    +4

    1. 01
    2. 02
    3. 03
    4. 04
    5. 05
    6. 06
    7. 07
    8. 08
    9. 09
    10. 10
    11. 11
    <font size="2" face="Courier New" color="black"><font color="#0000ff"><</font><font
    color="#800000">video</font><font color="#0000ff">></font>   <font
    color="#0000ff"><</font><font color="#800000">source</font> <font
    color="#ff0000">src</font><font color="#0000ff">="movie.mp4"</font> <font
    color="#ff0000">type</font><font color="#0000ff">='video/mp4; codecs="avc1.42E01E,
    mp4a.40.2"'</font> <font color="#0000ff">/></font>   <font color="#0000ff"><</font><font
    color="#800000">source</font> <font color="#ff0000">src</font><font
    color="#0000ff">="movie.webm"</font> <font color="#ff0000">type</font><font
    color="#0000ff">='video/webm; codecs="vp8, vorbis"'</font> <font color="#0000ff">
    /></font> <font color="#0000ff"></</font><font color="#800000">video</font><font
    color="#0000ff">></font></font>>

    «Итак, чтобы видео появилось на вашей веб-страничке пишем следующий код»

    KEKC, 23 Декабря 2015

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

    0

    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
    // channel.h
    
    #pragma once
    
    namespace AMQP {
    
    class Channel
    {
    private:
        std::shared_ptr<ChannelImpl> _implementation;
    
    public:
        Channel(Connection *connection) : _implementation(new ChannelImpl()) 
        {
            // attach the connection to the channel
            _implementation->attach(connection);
        }
        
        Channel(const Channel &channel) = delete;
    
        virtual ~Channel() 
        {
            // close the channel (this will eventually destruct the channel)
            _implementation->close();
        }
    
        //...
    };
    
    // ---------------------------------------------------------
    // amqpcpp.h
    
    /**
     *  AMQP.h
     *
     *  Starting point for all includes of the Copernica AMQP library
     *
     *  @documentation public
     */
    
    #pragma once
    
    // base C++ include files
    #include <vector>
    #include <string>
    #include <memory>
    #include <map>
    //...
    
    // base C include files
    #include <stdint.h>
    #include <math.h>
    
    // forward declarations
    #include <amqpcpp/classes.h>
    
    // utility classes
    #include <amqpcpp/endian.h>
    #include <amqpcpp/buffer.h>
    #include <amqpcpp/bytebuffer.h>
    //...
    
    // amqp types
    #include <amqpcpp/field.h>
    #include <amqpcpp/numericfield.h>
    #include <amqpcpp/decimalfield.h>
    #include <amqpcpp/stringfield.h>
    //...
    
    // envelope for publishing and consuming
    #include <amqpcpp/metadata.h>
    #include <amqpcpp/envelope.h>
    #include <amqpcpp/message.h>
    
    // mid level includes
    #include <amqpcpp/exchangetype.h>
    #include <amqpcpp/flags.h>
    #include <amqpcpp/callbacks.h>
    #include <amqpcpp/deferred.h>
    #include <amqpcpp/deferredconsumer.h>
    #include <amqpcpp/deferredqueue.h>
    #include <amqpcpp/deferreddelete.h>
    #include <amqpcpp/deferredcancel.h>
    #include <amqpcpp/deferredget.h>
    #include <amqpcpp/channelimpl.h>
    #include <amqpcpp/channel.h>
    //...

    https://github.com/CopernicaMarketingSoftware/AMQP-CPP

    scp, 23 Декабря 2015

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

    0

    1. 1
    2. 2
    3. 3
    if ($this->scenario == 'registration' || $this->scenario = 'changePassword') {
    	$this->password = HPasswordHelper::hashPassword($this->password);
    }

    Вот так сравнение сценарий в одном из проектов)))
    И самое странное всегда при сохранении, сценарий "changePassword" )

    ignatenkovnikita, 23 Декабря 2015

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

    −1

    1. 1
    #define GUIDSTR(s) __uuidof(class DECLSPEC_UUID(s) __guid_##__COUNTER__)

    Может можно покороче?

    Ccik, 22 Декабря 2015

    Комментарии (1)
  6. C++ / Говнокод #19215

    0

    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
    if( sync_ip_index < 0 && result() ) {
                QString tmp = tr(", нет синхронизации");
                addResultMessage( false, p->dev(), tmp);
                p->dev()->setState( CDiagramObject::e_Warning );
                setResult( false );
            }
            else if ( sources_from_xml.indexOf( sources_from_ntpq[ sync_ip_index ] ) < 0) {
                // ( ( (sync_ip_index >= 0)  ? ( sources_from_xml.indexOf( sources_from_ntpq[ sync_ip_index ] ) < 0 ) : false ) )  {
                // (p1 ( p2               )    ( p3                      ( f1                                 )                 )
                // p1..3 - predicates
                // Check sync_ip_index >= 0 (p2)
                //  true, then
                //    find sync source ip in list filled from xml config , and if there is finded, (p3) are true, else (p3) are false, and then (p1) will be false
                //  false, then
                //    (p1) will be false
                // This construction for one string check syncronized source ip for host, if host not synchronized
                QString tmp = tr(", хост синхронизирован с источником не указанным в схеме");
                addResultMessage( false, p->dev(), tmp);
                p->dev()->setState( CDiagramObject::e_Warning );
                setResult( false );
            }

    Под конец рабочего дня уже поехала крыша, см. комментарии.

    OlegUP, 22 Декабря 2015

    Комментарии (1)
  7. JavaScript / Говнокод #19212

    +2

    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
    function myRandom (from, to)  {return Math.floor((Math.random() * (to - from + 1)) + from);}
    function perehod(a,b,c){
        var cmdname="event";
        var cmdtime=a;
        var cmdparam="a;link;<getvar(host)>;click;-1";
        alert("prs::" + prskey + "::add::" + cmdname + "::" + cmdtime + "::" + cmdparam);
    
        var cmdname="link";
        var cmdtime=myRandom(b,c);
        var cmdparam="last;0";
        alert("prs::" + prskey + "::add::" + cmdname + "::" + cmdtime + "::" + cmdparam);
    
       var cmdname="script";
        var cmdtime=myRandom(1,3);
        var cmdparam="window.scrollTo(<rndr(100:500)>,<rndr(50:1000)>);";
        alert("prs::" + prskey + "::add::" + cmdname + "::" + cmdtime + "::" + cmdparam);
    
        var cmdname="script";
        var cmdtime=myRandom(1,3);
        var cmdparam="window.scrollTo(<rndr(100:1000)>,<rndr(50:1500)>);";
        alert("prs::" + prskey + "::add::" + cmdname + "::" + cmdtime + "::" + cmdparam);
    }
    
    if (m == 1){
        perehod(2, min_t_vr, max_t_vr);
    }
    else if (m == 2){
       perehod(2, min_t_vr, max_t_vr);
       perehod(2, min_t_vr, max_t_vr);
    }
    else if (m == 3){
      perehod(2, min_t_vr, max_t_vr);
      perehod(2, min_t_vr, max_t_vr);
      perehod(2, min_t_vr, max_t_vr);
    }
    else if (m == 4){
      perehod(2, min_t_vr, max_t_vr);
      perehod(2, min_t_vr, max_t_vr);
      perehod(2, min_t_vr, max_t_vr);
      perehod(2, min_t_vr, max_t_vr);
    }
    else if (m == 5){
      perehod(2, min_t_vr, max_t_vr);
      perehod(2, min_t_vr, max_t_vr);
      perehod(2, min_t_vr, max_t_vr);
      perehod(2, min_t_vr, max_t_vr);
      perehod(2, min_t_vr, max_t_vr);
    }
    else if (m == 6){
      perehod(2, min_t_vr, max_t_vr);
      perehod(2, min_t_vr, max_t_vr);
      perehod(2, min_t_vr, max_t_vr);
      perehod(2, min_t_vr, max_t_vr);
      perehod(2, min_t_vr, max_t_vr);
      perehod(2, min_t_vr, max_t_vr);
    }
    else if (m == 7){
      perehod(2, min_t_vr, max_t_vr);
      perehod(2, min_t_vr, max_t_vr);
      perehod(2, min_t_vr, max_t_vr);
      perehod(2, min_t_vr, max_t_vr);
      perehod(2, min_t_vr, max_t_vr);
      perehod(2, min_t_vr, max_t_vr);
      perehod(2, min_t_vr, max_t_vr);
    }
    else if (m == 8){
      perehod(2, min_t_vr, max_t_vr);
      perehod(2, min_t_vr, max_t_vr);
      perehod(2, min_t_vr, max_t_vr);
      perehod(2, min_t_vr, max_t_vr);
      perehod(2, min_t_vr, max_t_vr);
      perehod(2, min_t_vr, max_t_vr);
      perehod(2, min_t_vr, max_t_vr);
      perehod(2, min_t_vr, max_t_vr);
    }
    // и т.д. до m == 20 (sic!)
    else {
    	perehod(2, 15, 20);
    	perehod(2, 15, 20);
    	perehod(2, 15, 20);
    	perehod(2, 15, 20);
    	perehod(2, 15, 20);
    }

    Циклы? Не, не слышал...

    govnokod-observer, 22 Декабря 2015

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

    +1

    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
    $product = ORM::factory('product');
    
    // $product-> ... = ...;
    
    $price = ORM::factory('price');
    $price->save();
    $product->price = $price->id;
    $product->save();
    $price->product = $product->id;
    
    // $price-> ... = ...;
    
    $price->save();

    Для гарантии

    kgm-rj, 22 Декабря 2015

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

    +1

    1. 01
    2. 02
    3. 03
    4. 04
    5. 05
    6. 06
    7. 07
    8. 08
    9. 09
    10. 10
    <?php
    echo '<script type="text/javascript">';
    echo 'var categories = new Array();';
    if (count($categData)) {
        foreach ($categData as $id => $name) {
            echo ' categories[' . $id . '] = "' . $name . '";';
        }
    }
    echo ' </script>';
    ?>

    danielpetrovaliev, 22 Декабря 2015

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

    +1

    1. 1
    2. 2
    3. 3
    4. 4
    select value, value_type from b_iblock_element_property WHERE id = **;
    
    b_iblock_element_property.value: a:2:{s:4:"TYPE";s:4:"text";s:4:"TEXT";s:17:"Хорошее состояние";}
    b_iblock_element_property.value_type: text

    bitrix <3

    heyzea1, 21 Декабря 2015

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