1. Pascal / Говнокод #12471

    +95

    1. 01
    2. 02
    3. 03
    4. 04
    5. 05
    6. 06
    7. 07
    8. 08
    9. 09
    10. 10
    11. 11
    12. 12
    if length(fsizeS)<=9 then fsize:=strtoint(fsizeS);
    if (length(fsizeS)>9) and (length(fsizeS)<18) then
      fsize:=strtoint(copy(fsizeS,length(fsizeS)-8,length(fsizeS)-9))+
         strtoint(copy(fsizeS,1,length(fsizeS)-9))*1000000000{10**9};
    if length(fsizeS)>18 then
     begin
      writeln;
      writeln('File:'+curstr);
      writeln('Size:'+fsizeS);
      write('Please input file''s size, written above:');
      readln(fsize);
     end;

    Интересный способ конвертации строки в число. Думаю, у вас здесь такого ещё не было. Нашел в своих исходниках времён 8 - 9 класса.

    vovams, 24 Января 2013

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

    +137

    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
    private void SetRowColor()
            {
                DataGridView dg = new DataGridView();
                dg.Sorted += new EventHandler(DataGridView1_Sorted);
                foreach (DataGridViewColumn col in DataGridView1.Columns)
                {
                    if (col is DataGridViewTextBoxColumn)
                    {
                        if (col.HeaderText == "Status")
                        {
                            foreach (DataGridViewRow dgRow in DataGridView1.Rows)
                            {
                                if (dgRow.Cells[col.Index].Value.ToString() == "0" || dgRow.Cells[col.Index].Value.ToString() == "Inactive")
                                {
                                    DataGridViewCellStyle dStyle = new DataGridViewCellStyle();
                                    dStyle.BackColor = Color.Goldenrod;
                                    dStyle.Padding = new System.Windows.Forms.Padding(3, 0, 0, 0);
                                    dgRow.DefaultCellStyle = dStyle;
                                }
                            }
                        }
                        if (col.HeaderText == "StatusID")
                        {
                            foreach (DataGridViewRow dgRow in DataGridView1.Rows)
                            {
                                if (dgRow.Cells[col.Index].Value.ToString() == "0" || dgRow.Cells[col.Index].Value.ToString() == "Inactive")
                                {
                                    DataGridViewCellStyle dStyle = new DataGridViewCellStyle();
                                    dStyle.BackColor = Color.Goldenrod;
                                    dStyle.Padding = new System.Windows.Forms.Padding(3, 0, 0, 0);
                                    dgRow.DefaultCellStyle = dStyle;
                                }
                            }
                        }
                    }
                    //if (DataGridView1.Columns[i].ValueType == typeof(System.DateTime) && DataGridView1.Columns[i].Name != "CreateTS" && DataGridView1.Columns[i].Name != "ModifyTS" && DataGridView1.Columns[i].Name != "InactiveTS" && DataGridView1.Columns[i].Name != "PrintedTS")
                    //{
                    //    DataGridView1.Columns[i].DefaultCellStyle.Format = m_strDateFormat;
                    //    DataGridView1.Columns[i].Width = m_strDateFormat == "dd MMM yyyy hh:mm:ss tt" ? 150 : DataGridView1.Columns[i].Width;
                    //}
                    //DataGridView1.Columns[i].DefaultCellStyle.
                }
            }

    Новая работа. WinForms.
    90% примерно такое.

    kore_sar, 24 Января 2013

    Комментарии (4)
  3. Си / Говнокод #12469

    +133

    1. 1
    2. 2
    3. 3
    4. 4
    5. 5
    6. 6
    7. 7
    #if __BYTE_ORDER == __BIG_ENDIAN
    struct DWstruct { Wtype high, low;};
    #elif __BYTE_ORDER == __LITTLE_ENDIAN
    struct DWstruct { Wtype low, high;};
    #else
    #error Unhandled endianity
    #endif

    glibc, sysdeps/wordsize-32/divdi3.c

    bormand, 24 Января 2013

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

    +21

    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
    #define SWITCH(str)  switch(str_hash_for_switch(str))
    #define CASE(str)    static_assert(str_is_correct(str) && (str_len(str) <= MAX_LEN),\
    "CASE string contains wrong characters, or its length is greater than 9");\
    case str_hash(str, str_len(str))
    #define DEFAULT  default
    
    typedef unsigned char uchar;
        typedef unsigned long long ullong;
    
        const uchar MAX_LEN = 9;
        const ullong N_HASH = static_cast<ullong>(-1);
    
        constexpr ullong raise_128_to(const uchar power)
        {
            return 1ULL << 7 * power;
        }
    
        constexpr bool str_is_correct(const char* const str)
        {
            return (static_cast<signed char>(*str) > 0) ? str_is_correct(str + 1) : (*str ? false : true);
        }
    
        constexpr uchar str_len(const char* const str)
        {
            return *str ? (1 + str_len(str + 1)) : 0;
        }
    
        constexpr ullong str_hash(const char* const str, const uchar current_len)
        {
            return *str ? (raise_128_to(current_len - 1) * static_cast<uchar>(*str) + str_hash(str + 1, current_len - 1)) : 0;
        }
    
        inline ullong str_hash_for_switch(const char* const str)
        {
            return (str_is_correct(str) && (str_len(str) <= MAX_LEN)) ? str_hash(str, str_len(str)) : N_HASH;
        }
    
        inline ullong str_hash_for_switch(const std::string& str)
        {
            return (str_is_correct(str.c_str()) && (str.length() <= MAX_LEN)) ? str_hash(str.c_str(), str.length()) : N_HASH;
        }

    Запостил из-за ошибки на некоторых платформах и компиляторах.

    LispGovno, 23 Января 2013

    Комментарии (37)
  5. JavaScript / Говнокод #12467

    +163

    1. 1
    2. 2
    3. 3
    4. 4
    5. 5
    6. 6
    /**
     * Удаляет файл из контрола
     */
    function deleteFile(controlName) {
    	document.getElementById(controlName).innerHTML = document.getElementById(controlName).innerHTML;
    }

    Вот так вот удаляют содержимое input file в проекте у меня, сбрасывают то что выбрали.

    smpl, 23 Января 2013

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

    +130

    1. 01
    2. 02
    3. 03
    4. 04
    5. 05
    6. 06
    7. 07
    8. 08
    9. 09
    10. 10
    11. 11
    public XDocument GetHelpFile(string path)
    {
          try
          {
            return _dataFacade.LoadDocument(path);
          }
          catch
          {
            return null;
          }
    }

    taburetka, 23 Января 2013

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

    +15

    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
    /**
     * @brief Serializer generic interface.
     */
    template<typename ValueType>
    struct serializer
    {
        /**
         * @brief Parses value from raw bytes.
         * @param  from byte buffer parse value from
         */
        static ValueType parse(uint8_t *from);
    
        /**
         * @brief Writes value to raw byte buffer.
         * @param  value value to write
         * @param  dest destination buffer
         */
        static void write(ValueType value, uint8_t *dest);
    };
    
    template<>
    struct serializer<uint8_t>
    {
        static uint8_t parse(uint8_t *from)
        {
            return *from;
        }
        static void write(const uint8_t value, uint8_t *to)
        {
            *to = value;
        }
    };
    
    template<>
    struct serializer<uint16_t>
    {
        static uint16_t parse(uint8_t *from)
        {
            return (uint16_t)from[0] << 8 | from[1];
        }
        static void write(const uint16_t value, uint8_t *to)
        {
            to[0] = (value >> 8);
            to[1] = value & 0xff;
        }
    };
    
    template<>
    struct serializer<uint32_t>
    {
        static uint32_t parse(uint8_t *from)
        {
            return from[0] << 24 | from[1] << 16 | from[2] << 8 | from[3];
        }
        static void write(const uint32_t value, uint8_t *to)
        {
            serializer<uint16_t>::write(value >> 16, to);
            serializer<uint16_t>::write(value & 0xffff, to + 2);
        }
    };
    
    template<>
    struct serializer<uint64_t>
    {
        static uint64_t parse(uint8_t *from)
        {
            const uint32_t high = serializer<uint32_t>::parse(from);
            const uint32_t low = serializer<uint32_t>::parse(from + 4);
            return ((uint64_t) high << 32) | low;
        }
        static void write(const uint64_t value, uint8_t *to)
        {
            serializer<uint32_t>::write(value >> 32, to);
            serializer<uint32_t>::write(value & 0xffffffff, to + 4);
        }
    };

    Тут поднялась тема неуместного битолюбства... Решил поделиться одним из моих первых крестОпусов.
    "кроссплатформенный hton(sl)".

    roman-kashitsyn, 22 Января 2013

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

    +154

    1. 1
    http://kbyte.ru/ru/Programming/Sources.aspx?id=824&mode=show

    063

    dos_, 22 Января 2013

    Комментарии (2)
  9. JavaScript / Говнокод #12463

    +149

    1. 1
    document.getElementById('out').value = document.getElementById('in').value.toString().translit().split(' ').join('_').toString().toLowerCase()

    translit() видимо самописный...

    TRANE73, 22 Января 2013

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

    +48

    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
    $title = get_the_title();
    if ( $title == "Portfolio")  $data['sl_portfolio_style'] = "2 Columns Portfolio";
    if ( $title == "3 Columns Portfolio")  $data['sl_portfolio_style'] = "3 Columns Portfolio";
    if ( $title == "4 Columns Portfolio")  $data['sl_portfolio_style'] = "4 Columns Portfolio";
    if ( $title == "6 Columns Portfolio")  $data['sl_portfolio_style'] = "6 Columns Portfolio";
    if ( $title == "Portfolio")  query_posts( '&post_type=portfolio-type&posts_per_page=4&paged=' . $paged );
    if ( $title == "4 Columns Portfolio")  query_posts( '&post_type=portfolio-type&posts_per_page=8&paged=' . $paged );
    if ( $title == "6 Columns Portfolio")  query_posts( '&post_type=portfolio-type&posts_per_page=12&paged=' . $paged );
    if ( $title == "3 Columns Portfolio")  query_posts( '&post_type=portfolio-type&posts_per_page=6&paged=' . $paged );
    if ( $title == "Portfolio Right Sidebar")  $data['sl_portfolio_style'] = "Portfolio with Sidebar";
    if ( $title == "Portfolio Right Sidebar")  $data['portfolio_sidebar_position'] = "Right Sidebar";
    if ( $title == "Portfolio Left Sidebar")  $data['sl_portfolio_style'] = "Portfolio with Sidebar";
    if ( $title == "Portfolio Left Sidebar")  $data['portfolio_sidebar_position'] = "Left Sidebar";
    
    if ( $title == "Portfolio Left Sidebar")  query_posts( '&post_type=portfolio-type&posts_per_page=12&paged=' . $paged );
    if ( $title == "Portfolio Right Sidebar")  query_posts( '&post_type=portfolio-type&posts_per_page=12&paged=' . $paged );

    "switch - case" - Не не слышал!
    И это в покупной теме для wordpress на тимфоресте.
    Стоимость темы - 45 уе...

    tsybulskyserg, 22 Января 2013

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