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

    0

    1. 1
    2. 2
    3. 3
    4. 4
    5. 5
    6. 6
    7. 7
    function isDateGreaterOrEqualNow($d)
    {
        if (!$d) return false;
        $t = getdate();
        $t = mktime(0, 0, 0, $t['mon'], $t['mday'], $t['year']);
        return $d >= $t;
    }

    Космическое сравнение дат

    SeniorShaurman, 07 Июля 2017

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

    −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
    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
    <CustomTimePicker
                        ref={ref => {
                            if (!ref || this.moved || this.handled)
                                return;
    
                            this.handled = true;
    
                            ref.picker.addEventListener('click', () => {
                                if (this.moved)
                                    return;
    
                                setTimeout(() => {
                                    const panel = ref.panelInstance;
    
                                    if (!panel || !panel._reactInternalInstance)
                                        return;
    
                                    const node = panel._reactInternalInstance._renderedComponent._hostNode.parentNode.parentNode.parentNode;
    
                                    this.moved = true;
                                    this.refs.container.appendChild(node);
    
                                    ref.picker.click();
                                    ref.picker.click();
                                }, 0);
                            });
                        }}
                        showSecond={false}
                        value={this.props.value || moment()}
                        className="timepicker"
                        onChange={(e) => this.handleChange(e)}
                        format={this.format}
                        use12Hours
                    />

    Efog, 07 Июля 2017

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

    +2

    1. 001
    2. 002
    3. 003
    4. 004
    5. 005
    6. 006
    7. 007
    8. 008
    9. 009
    10. 010
    11. 011
    12. 012
    13. 013
    14. 014
    15. 015
    16. 016
    17. 017
    18. 018
    19. 019
    20. 020
    21. 021
    22. 022
    23. 023
    24. 024
    25. 025
    26. 026
    27. 027
    28. 028
    29. 029
    30. 030
    31. 031
    32. 032
    33. 033
    34. 034
    35. 035
    36. 036
    37. 037
    38. 038
    39. 039
    40. 040
    41. 041
    42. 042
    43. 043
    44. 044
    45. 045
    46. 046
    47. 047
    48. 048
    49. 049
    50. 050
    51. 051
    52. 052
    53. 053
    54. 054
    55. 055
    56. 056
    57. 057
    58. 058
    59. 059
    60. 060
    61. 061
    62. 062
    63. 063
    64. 064
    65. 065
    66. 066
    67. 067
    68. 068
    69. 069
    70. 070
    71. 071
    72. 072
    73. 073
    74. 074
    75. 075
    76. 076
    77. 077
    78. 078
    79. 079
    80. 080
    81. 081
    82. 082
    83. 083
    84. 084
    85. 085
    86. 086
    87. 087
    88. 088
    89. 089
    90. 090
    91. 091
    92. 092
    93. 093
    94. 094
    95. 095
    96. 096
    97. 097
    98. 098
    99. 099
    100. 100
    switch (address & 0xF000)
        {
            case 0x0000:
            case 0x1000:
            case 0x2000:
            case 0x3000:
                return rom[address];
            case 0x4000:
            case 0x5000:
            case 0x6000:
            case 0x7000:
                return rom[address + 0x4000 * (bank_index - 1)];
            case 0x8000:
            case 0x9000:
                return vram[address - 0x8000];
            case 0xA000:
            case 0xB000:
                return sram[address - 0xA000];
            case 0xC000:
            case 0xD000:
                return wram[address - 0xC000];
            case 0xE000:
            case 0xF000:
                switch (address & 0x0F00)
                {
                    case 0x0000:
                    case 0x0100:
                    case 0x0200:
                    case 0x0300:
                    case 0x0400:
                    case 0x0500:
                    case 0x0600:
                    case 0x0700:
                    case 0x0800:
                    case 0x0900:
                    case 0x0A00:
                    case 0x0B00:
                    case 0x0C00:
                    case 0x0D00:
                        return wram[address - 0xF000];
                    case 0x0E00:
                        switch (address & 0x00F0)
                        {
                            case 0x0000:
                            case 0x0010:
                            case 0x0020:
                            case 0x0030:
                            case 0x0040:
                            case 0x0050:
                            case 0x0060:
                            case 0x0070:
                            case 0x0080:
                            case 0x0090:
                                return oam[address - 0xFE00];
                            case 0x00A0:
                            case 0x00B0:
                            case 0x00C0:
                            case 0x00D0:
                            case 0x00E0:
                            case 0x00F0:
                                return 0b00;
                        }
                    case 0x0F00:
                        switch (address & 0x00F0)
                        {
                            case 0x0000:
                            case 0x0010:
                            case 0x0020:
                            case 0x0030:
                            case 0x0040:
                            case 0x0050:
                            case 0x0060:
                            case 0x0070:
                                return io_regs[address - 0xFF00];
                            case 0x0080:
                            case 0x0090:
                            case 0x00A0:
                            case 0x00B0:
                            case 0x00C0:
                            case 0x00D0:
                            case 0x00E0:
                            case 0x00F0:
                                switch (address & 0x000F)
                                {
                                    case 0x0000:
                                    case 0x0001:
                                    case 0x0002:
                                    case 0x0003:
                                    case 0x0004:
                                    case 0x0005:
                                    case 0x0007:
                                    case 0x0008:
                                    case 0x0009:
                                    case 0x000A:
                                    case 0x000B:
                                    case 0x000C:
                                    case 0x000D:
                                    case 0x000E:
                                        return hram[address - 0xFF80];
                                    case 0x000F:

    jangolare, 06 Июля 2017

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

    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
    88. 88
    89. 89
    90. 90
    91. 91
    92. 92
    93. 93
    94. 94
    95. 95
    96. 96
    97. 97
    98. 98
    #include <optional>
    
    namespace aim {
    
            template <typename T, template <typename> typename Cont>
            struct is_valid {};
    
            template <typename T, template <typename> typename Cont>
            struct chain;
    
            template <typename T, template <typename> typename Cont>
            struct chain {
                    using value_type_t = T;
                    using holder_t = Cont<value_type_t>;
    
                    chain()
                    {}
    
                    chain(holder_t&& value_)
                    : value(std::move(value_))
                    {}
    
                    template <typename Func>
                    constexpr auto otherwise(Func&& func) {
                            return chain<T, Cont>{std::move(func())};
                    }
    
                    template <typename Func>
                    constexpr auto with(Func&& func) -> chain<value_type_t, Cont> {
                            if (bool(value)) {
                                    return chain<value_type_t, Cont>{Cont<value_type_t>{func(*value)}};
                            }
                            else {
                                    return chain<value_type_t, Cont>{};
                            }
                    }
    
                    holder_t value;
            };
    
            template <typename T, template <typename> typename Cont>
            chain(Cont<T>&&) -> chain<T, Cont>;
    
            template <typename T, template <typename> typename Cont>
            struct use {
                    using value_type_t = T;
                    using holder_t = Cont<value_type_t>;
    
                    use(holder_t&& value)
                    : value(std::move(value))
                    {}
    
                    template <typename Func>
                    constexpr auto with(Func&& func) -> chain<value_type_t, Cont> {
                            if (is_valid<T, Cont>{}(value)) {
                                    return chain<value_type_t, Cont>{Cont<value_type_t>{func(*value)}};
                            }
                            else {
                                    return chain<value_type_t, Cont>{};
                            }
                    }
    
                    holder_t value;
            };
    
            template <typename T, template <typename> typename Cont>
            use(Cont<T>&&) -> use<T, Cont>;
            
    }
    
    namespace aim {
            template <typename T>
            struct is_valid<T, std::optional> {
                    constexpr bool operator()(std::optional<T> const& value) {
                            return bool(value);
                    }
            };
    }
    
    #include <iostream>
    #include <memory>
    
    int main() {
            {
                    std::optional<int> a;
    
                    aim::use(std::move(a)).with([](auto v) {
                            std::cout << v << '\n';
                            return 1;
                    }).otherwise([](){
                            std::cout << "it's none!\n";
                            return 2;
                    }).with([](auto v){
                            std::cout <<  v << '\n';
                            return 3;
                    });
            }
    }

    говно

    j123123, 06 Июля 2017

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

    +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
    $value = $grandTotal  - $tax;
            $total_name = $this->__('Grandtotal_excl_tax')." (".$this->__('excl. tax').")";
            $row = '<div class="columns xsmall-6 small-6">';
            $row .= $total_name;
            $row .= '</div><div class="columns xsmall-6 small-6 align-right">'.$this->helper('checkout')->formatPrice($value).'</div>';
    
            $totals["grand_total_excl_tax"] = $row;
    
    
            //$orderedTotals = Mage::getStoreConfig('onestepcheckout/general/summary_totals');
            $orderedTotals =  "subtotal,aw_giftcard_duty,aw_giftcard_duty_discount,shipping,cashondelivery,shipping_discount,discount,aw_giftcard,grand_total_excl_tax,tax,grand_total";
            $orderedTotals = explode(',', $orderedTotals);
            foreach($orderedTotals as $total) {
                $total = trim($total);
                if (isset($totals[$total])) {
                    echo $totals[$total];
                }
            }
            ?>
        </div>

    Разгребаем проект на Magento доставшийся в наследство. Умеете ли вы готовить Array() так как готовят его в строках 11-12 ?

    #littleitaly

    mrdink, 06 Июля 2017

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

    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
    # returns yesterday reports
        def get_yesterday_reports(self):
            pass
    
        def get_waterfall_sources(self, wf_id, active_only=False):
            # TODO: check if meta property is equal to the number of items in the array
            # return test.mock_waterfall_sources.get_sources()
            status = '1' if active_only else urllib.quote('0,1')  # '0%2C1&'
            self.get_auth_token()
            encoded = urllib.urlencode({'authorization': self.token})
            url = BASE_URL + "/waterfall-ad-sources?advertiser=&itemsPerPage=9999&name=&page=1&sortAsc=true&sortBy=tier&status={}&tier=&waterfall={}&{}" \
                .format(status, wf_id, encoded)
    
            retries = 1
            while retries <= 3:
                response = requests.get(url)
                if response.status_code == 200:
                    break
                else:
                    logging.error('Failed GET request to StreamRail, status code {}, {} retries'
                                  .format(response.status_code, retries))
                retries += 1
    
            assert response.status_code == 200
            try:
                data = simplejson.loads(response.content)
                waterfall_sources = data['waterfallAdSources']
                assert int(data['meta']['total']) == len(waterfall_sources)
                return waterfall_sources
            except:
                logging.exception("Could not load ad sources for waterfall {} from StreamRail:\n"
                                  "{}".format(wf_id, response.headers))
                raise

    Хотя, с другой стороны, все эти рекламораспространители так выглядят. Но тут просто кучно так получилось.

    wvxvw, 06 Июля 2017

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

    +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
    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
    <div class="checkbox removeSpan">
      <input id="all-standard-colors" name="all-standard-colors" type="checkbox"
                         data-bind="checked: $parent.selectAllStandardColors enable: $parent.isTabEnabled"/>
      <label for="all-standard-colors">All standard</label>
    </div>
    
    <style>
    div.checkbox > input + label {
        padding: 4px 0 4px 29px;
        background-image: url("../images/unchecked-checkbox.png");
        background-size: 21px;
        background-position: left center;
        background-repeat: no-repeat;
    }
    
    div.checkbox > input:checked + label {
        background-image: url("../images/checkbox-checked.png");
        background-size: 21px;
        background-position: left center;
        background-repeat: no-repeat;
    }
    </style>
    
    <script>
    $(document).ready(function() {
        setInterval(function(){
            $('.removeSpan span').remove();
        }, 2000);
    });
    </script>

    UI на knockout.js. Есть бага - пропадает галочка на чекбоксе. Выясняется что knockout для валидации вставляет после input тега невидимый span
    <span></span>
    Неизвестный товарищ фиксит это не вдаваясь в детали верстки и CSS селекторы - добавляет специальный класс, которым маркает все чекбоксы и поллер который убирает из них span каждые 2 секунды. Но про это никто не узнает. В течении полугода появляется еще десяток другой багов с отображением чекбоксов которые фиксят не вдаваясь в детали. И только потом замечают странный класс removeSpan и находят поллер в недрах domUtil.js, удаляют его и меняют один символ в стилях - вместо div.checkbox > input + label стало div.checkbox > input ~ label

    frenzykryger, 05 Июля 2017

    Комментарии (10)
  8. Си / Говнокод #23156

    −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
    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
    static bool
    do_convert(iconv_t cd, const char * src, int src_len,
               char ** dst, int *dst_len)
      {
      char * ret;
    
      char *inbuf;
      char *outbuf;
      int alloc_size;
      int output_pos;
      size_t inbytesleft;
      size_t outbytesleft;
    
      if(src_len < 0)
        src_len = strlen(src);
    #if 0
      fprintf(stderr, "Converting:\n");
      bgav_hexdump(src, src_len, 16);
    #endif
      alloc_size = src_len + BYTES_INCREMENT;
    
      inbytesleft  = src_len;
    
      /* We reserve space here to add a final '\0' */
      outbytesleft = alloc_size-1;
    
      ret    = malloc(alloc_size);
    
      inbuf  = (char *)src;
      outbuf = ret;
    
      while(1)
        {
    
        if(iconv(cd, (ICONV_CONST char **)&inbuf, &inbytesleft,
                 &outbuf, &outbytesleft) == (size_t)-1)
          {
          switch(errno)
            {
            case E2BIG:
              output_pos = (int)(outbuf - ret);
    
              alloc_size   += BYTES_INCREMENT;
              outbytesleft += BYTES_INCREMENT;
    
              ret = realloc(ret, alloc_size);
              if (ret == NULL)
                {
                cdio_warn("Can't realloc(%d).", alloc_size);
                return false;
                }
              outbuf = ret + output_pos;
              break;
            default:
              cdio_warn("Iconv failed: %s", strerror(errno));
              if (ret != NULL)
                free(ret);
              return false;
              break;
            }
          }
        if(!inbytesleft)
          break;
        }
      /* Zero terminate */
      *outbuf = '\0';
    
      /* Set return values */
      *dst = ret;
      if(dst_len)
        *dst_len = (int)(outbuf - ret);
    #if 0
      fprintf(stderr, "Conversion done, src:\n");
      bgav_hexdump(src, src_len, 16);
      fprintf(stderr, "dst:\n");
      bgav_hexdump((uint8_t*)(ret), (int)(outbuf - ret), 16);
    #endif
      return true;
    }

    https://github.com/pbatard/rufus/blob/edcfd43ed550b17f23f9534f4b3b5cdd7fffdefc/src/libcdio/driver/utf8.c#L170-L248

    А вы тут видите тут баг?

    j123123, 05 Июля 2017

    Комментарии (16)
  9. Си / Говнокод #23155

    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
    void SetTitleBarIcon(HWND hDlg)
    {
    	int i16, s16, s32;
    	HICON hSmallIcon, hBigIcon;
    
    	// High DPI scaling
    	i16 = GetSystemMetrics(SM_CXSMICON);
    	// Adjust icon size lookup
    	s16 = i16;
    	s32 = (int)(32.0f*fScale);
    	if (s16 >= 54)
    		s16 = 64;
    	else if (s16 >= 40)
    		s16 = 48;
    	else if (s16 >= 28)
    		s16 = 32;
    	else if (s16 >= 20)
    		s16 = 24;
    	if (s32 >= 54)
    		s32 = 64;
    	else if (s32 >= 40)
    		s32 = 48;
    	else if (s32 >= 28)
    		s32 = 32;
    	else if (s32 >= 20)
    		s32 = 24;
    
    	// Create the title bar icon
    	hSmallIcon = (HICON)LoadImage(hMainInstance, MAKEINTRESOURCE(IDI_ICON), IMAGE_ICON, s16, s16, 0);
    	SendMessage (hDlg, WM_SETICON, ICON_SMALL, (LPARAM)hSmallIcon);
    	hBigIcon = (HICON)LoadImage(hMainInstance, MAKEINTRESOURCE(IDI_ICON), IMAGE_ICON, s32, s32, 0);
    	SendMessage (hDlg, WM_SETICON, ICON_BIG, (LPARAM)hBigIcon);
    }

    https://github.com/pbatard/rufus/blob/92d046e663811fd922262f1f347ad2ebe8e09b97/src/stdlg.c#L1607-L1639

    j123123, 05 Июля 2017

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

    +1

    1. 1
    2. 2
    3. 3
    def gsubn text
      text.gsub('\n','').gsub('\t','').gsub('\r','').gsub(/\"/,'').gsub('@@@@','. ').gsub("  "," ")
    end

    последний gsub меняет два пробела на один

    ll14m4n, 04 Июля 2017

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