1. Python / Говнокод #17927

    −118

    1. 1
    name = name.replace(u'c', u'с') # this is magia

    kyzi007, 03 Апреля 2015

    Комментарии (66)
  2. C# / Говнокод #17926

    +839

    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
    protected virtual string GetParentTableControlID()
            {
                try
                {
                    if (this.Parent is BaseApplicationTableControl) return this.Parent.ID;
                    if (this.Parent.Parent is BaseApplicationTableControl) return this.Parent.Parent.ID;
                    if (this.Parent.Parent.Parent is BaseApplicationTableControl) return this.Parent.Parent.Parent.ID;
                    if (this.Parent.Parent.Parent.Parent is BaseApplicationTableControl) return this.Parent.Parent.Parent.Parent.ID;
                }
                catch (Exception)
                {
                }
                return "";
            }

    greyb, 03 Апреля 2015

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

    +57

    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
    #include <iostream>
    #include <stdexcept>
    
    template<std::size_t N>
    static int constexpr date_component(const char (&s)[N], int i, bool last, int max) {
      return 
        (i + 2 + (last ? 0 : 1) >= N) 
            ? throw std::logic_error("Too short date string") :
        (!last && s[i + 2] != ':') 
            ? throw std::logic_error("Cannot find delimiter") :
        (s[i] < '0' || s[i] > '9' ||  s[i + 1] < '0' || s[i + 1] > '9') 
            ? throw std::logic_error("Not a number") :
        ((s[i] - '0') * 10 + (s[i + 1] - '0') > max) 
            ? throw std::logic_error("Too large number") :
                (s[i] - '0') * 10 + (s[i + 1] - '0');
    }
    
    struct time { 
        int hour; int minute; int second; 
        
        template<std::size_t N>
        constexpr time(const char (&datestr)[N]) :
            hour(date_component(datestr, 0, false, 24)), 
            minute(date_component(datestr, 3, false, 60)),
            second(date_component(datestr, 6, true, 60)) 
        {}
    };
    
    struct time constexpr midnight("00:00:00");
    struct time constexpr afternoon("12:00:00");
    
    int main(int argc, char* argv[]) {
        std::cout << "Midnight hour is " << midnight.hour << std::endl;
        std::cout << "Afternoon hour is " << afternoon.hour << std::endl;
    }

    C++ и даты времени компиляции

    myaut, 03 Апреля 2015

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

    +152

    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
    // Наткнулся в коде на
    try
    {
         throw new Provider_Exception($curl_error);
    }
    catch (Exception $e)
    {
          throw new Provider_Exception('No connection');
    }
    
    // и отрефакторил
    try
    {
         throw new Provider_Exception($curl_error);
    }
    catch (Exception $e)
    {
          throw new Provider_Exception($e->getMessage());
    }

    PROFIT!

    invision70, 03 Апреля 2015

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

    +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
    <select multiple  name="fields[]">
    <option value="idblank" <?php echo in_array("idblank", $book_fields)?"selected":""; ?> >idblank</option>
    <option value="n_dog" <?php echo in_array("n_dog", $book_fields)?"selected":""; ?> >n_dog</option>
    <option value="n_failpay" <?php echo in_array("n_failpay", $book_fields)?"selected":""; ?> >n_failpay</option>
    <option value="senior" <?php echo in_array("senior", $book_fields)?"selected":""; ?> >senior</option>
    <option value="fio" <?php echo in_array("fio", $book_fields)?"selected":""; ?> >fio</option>
    <option value="date_init" <?php echo in_array("date_init", $book_fields)?"selected":""; ?> >date_init</option>
    <option value="fio_client" <?php echo in_array("fio_client", $book_fields)?"selected":""; ?>>fio_client</option>
    <option value="date_plat" <?php echo in_array("date_plat", $book_fields)?"selected":""; ?>>date_plat</option>
    <option value="pros_total" <?php echo in_array("pros_total", $book_fields)?"selected":""; ?>>pros_total</option>
    <option value="summa_post" <?php echo in_array("summa_post", $book_fields)?"selected":""; ?>>summa_post</option>
    <option value="ostatok" <?php echo in_array("ostatok", $book_fields)?"selected":""; ?>>ostatok</option>
    <option value="effect" <?php echo in_array("effect", $book_fields)?"selected":""; ?>>effect</option>
    <option value="ef" <?php echo in_array("ef", $book_fields)?"selected":""; ?>>ef</option>
    <option value="idcolor" <?php echo in_array("idcolor", $book_fields)?"selected":""; ?>>idcolor</option>
    <option value="inn" <?php echo in_array("inn", $book_fields)?"selected":""; ?>>inn</option>
    <option value="n_schet" <?php echo in_array("n_schet", $book_fields)?"selected":""; ?>>n_schet</option>
    <option value="dom_tel" <?php echo in_array("dom_tel", $book_fields)?"selected":""; ?>>dom_tel</option>
    <option value="mob_tel" <?php echo in_array("mob_tel", $book_fields)?"selected":""; ?>>mob_tel</option>
    <option value="work_tel" <?php echo in_array("work_tel", $book_fields)?"selected":""; ?>>work_tel</option>
    <option value="reg_city" <?php echo in_array("reg_city", $book_fields)?"selected":""; ?>>reg_city</option>
    <option value="reg_region" <?php echo in_array("reg_region", $book_fields)?"selected":""; ?>>reg_region</option>
    <option value="reg_district" <?php echo in_array("reg_district", $book_fields)?"selected":""; ?>>reg_district</option>
    <option value="reg_settlement" <?php echo in_array("reg_settlement", $book_fields)?"selected":""; ?>>reg_settlement</option>
    <option value="reg_adress" <?php echo in_array("reg_adress", $book_fields)?"selected":""; ?>>reg_adress</option>
    <option value="live_city" <?php echo in_array("live_city", $book_fields)?"selected":""; ?>>live_city</option>
    <option value="live_region" <?php echo in_array("live_region", $book_fields)?"selected":""; ?>>live_region</option>
    <option value="live_district" <?php echo in_array("live_district", $book_fields)?"selected":""; ?>>live_district</option>
    <option value="live_settlement" <?php echo in_array("live_settlement", $book_fields)?"selected":""; ?>>live_settlement</option>
    <option value="live_adress" <?php echo in_array("live_adress", $book_fields)?"selected":""; ?>>live_adress</option>
     </select>

    Проверка на выделенный пункт списка

    noffily, 03 Апреля 2015

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

    +53

    1. 1
    for ( ; currnet->prev != NULL; (*this)-- );

    медод везвращения итератора к началу

    artembegood, 03 Апреля 2015

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

    +149

    1. 1
    -

    onnanon, 02 Апреля 2015

    Комментарии (323)
  8. JavaScript / Говнокод #17919

    +147

    1. 1
    -

    onnanon, 02 Апреля 2015

    Комментарии (375)
  9. C++ / Говнокод #17918

    +60

    1. 1
    2. 2
    3. 3
    4. 4
    5. 5
    for(int i=0;i<m;i++){
        if(i>0 && a[i-1][j]>=a[i][j])continue;
        if(i+1<n && a[i+1][j]>=a[i][j])continue;
        if(j>0 && a[i][j-1]>=a[i][j])continue;
        if(j+1<m && a[i][j+1]>=a[i][j])continue;}

    Я так и не понял, в чем смысл этого цикла, ну да ладно.

    Negovnokoder, 02 Апреля 2015

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

    +163

    1. 01
    2. 02
    3. 03
    4. 04
    5. 05
    6. 06
    7. 07
    8. 08
    9. 09
    10. 10
    11. 11
    12. 12
    /*--------Перевод текста в верхний регистр-------------*/
    function upper($str) { 
        $trans=array( 
         "а" => "А",  "б" => "Б",  "в" => "В",  "г" => "Г",  "д" => "Д",  "е" => "Е",  
         "ё" => "Ё",  "ж" => "Ж",  "з" => "З",  "и" => "И",  "й" => "Й",  "к" => "К",  
         "л" => "Л",  "м" => "М",  "н" => "Н",  "о" => "О",  "п" => "П",  "р" => "Р",  
         "с" => "С",  "т" => "Т",  "у" => "У",  "ф" => "Ф",  "х" => "Х",  "ц" => "Ц",  
         "ч" => "Ч",  "ш" => "Ш",  "щ" => "Щ",  "ь" => "Ь",  "ы" => "Ы",  "ъ" => "Ъ",  
         "э" => "Э",  "ю" => "Ю",  "я" => "Я",  
        );  
        return strtr($str,  $trans);  
    }

    noffily, 02 Апреля 2015

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