1. SQL / Говнокод #5278

    −860

    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
    SELECT
        node.nid AS nid,
        location.latitude AS location_latitude,
        location.longitude AS location_longitude,
        node.title AS node_title,
        node.language AS node_language,
        location.lid AS location_lid,
        (IFNULL(ACOS(0.501284223863*COS(RADIANS(location.latitude))*(0.863228195442*COS(RADIANS(location.longitude)) + 0.504813908876*SIN(RADIANS(location.longitude))) + 0.865282686124*SIN(RADIANS(location.latitude))), 0.00000)*6362105.74365) AS location_distance,
        node_data_field_rate_prior.field_rate_prior_amount AS node_data_field_rate_prior_field_rate_prior_amount,
        node_data_field_rate_prior.field_rate_prior_currency AS node_data_field_rate_prior_field_rate_prior_currency,
        node.type AS node_type, node.vid AS node_vid,
        node_data_field_rate_prior.field_rate_reg_amount AS node_data_field_rate_prior_field_rate_reg_amount,
        node_data_field_rate_prior.field_rate_reg_currency AS node_data_field_rate_prior_field_rate_reg_currency,
        node_data_field_rate_prior.field_rate_vip_amount AS node_data_field_rate_prior_field_rate_vip_amount,
        node_data_field_rate_prior.field_rate_vip_currency AS node_data_field_rate_prior_field_rate_vip_currency
      FROM node node
      LEFT JOIN location_instance location_instance ON node.vid = location_instance.vid
      LEFT JOIN location location ON location_instance.lid = location.lid
      LEFT JOIN content_type_dta_kiosk node_data_field_rate_prior ON node.vid = node_data_field_rate_prior.vid
      WHERE node.type in ('dta_kiosk')
        AND (location.latitude > 40.9991009563 
          AND location.latitude < 59.0008990437 
          AND location.longitude > 5.91311892539 
          AND location.longitude < 34.0868810746
        )
      ORDER BY location_distance ASC

    vectoroc, 14 Января 2011

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

    +164

    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
    // Licensed to Green Energy Corp (www.greenenergycorp.com) under one
    // or more contributor license agreements. See the NOTICE file
    // distributed with this work for additional information
    // regarding copyright ownership. Green Enery Corp licenses this file
    // to you under the Apache License, Version 2.0 (the
    // "License"); you may not use this file except in compliance
    // with the License. You may obtain a copy of the License at
    // http://www.apache.org/licenses/LICENSE-2.0
    // Unless required by applicable law or agreed to in writing,
    // software distributed under the License is distributed on an
    // "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
    // KIND, either express or implied. See the License for the
    // specific language governing permissions and limitations
    // under the License.
    //
    #include "Objects.h"
    
    #define MACRO_STATIC_INSTANCE(group, var) Group##group##Var##var Group##group##Var##var::mInstance;
    
    namespace apl { namespace dnp {
    
    MACRO_STATIC_INSTANCE(1,0)
    MACRO_STATIC_INSTANCE(1,1)
    MACRO_STATIC_INSTANCE(1,2)
    MACRO_STATIC_INSTANCE(2,0)
    MACRO_STATIC_INSTANCE(2,1)
    MACRO_STATIC_INSTANCE(2,2)
    MACRO_STATIC_INSTANCE(2,3)
    
    <... 100500 строк ...>
    
    MACRO_STATIC_INSTANCE(60,1)
    MACRO_STATIC_INSTANCE(60,2)
    MACRO_STATIC_INSTANCE(60,3)
    MACRO_STATIC_INSTANCE(60,4)
    
    MACRO_STATIC_INSTANCE(80,1)
    
    MACRO_STATIC_INSTANCE(110,0)
    MACRO_STATIC_INSTANCE(111,0)
    MACRO_STATIC_INSTANCE(112,0)
    MACRO_STATIC_INSTANCE(113,0)
    
    //////////////////////////////////////////////
    // Binary Input Types
    //////////////////////////////////////////////
    
    void Group1Var2::Write(apl::byte_t* p, const apl::Binary& v) const { DNPToStream::WriteQ(p, Group1Var2::Inst(), v); }
    void Group2Var1::Write(apl::byte_t* p, const apl::Binary& v) const { DNPToStream::WriteQ(p, Group2Var1::Inst(), v); }
    void Group2Var2::Write(apl::byte_t* p, const apl::Binary& v) const { DNPToStream::WriteQT(p, Group2Var2::Inst(), v); }
    void Group2Var3::Write(apl::byte_t* p, const apl::Binary& v) const { DNPToStream::WriteQT(p, Group2Var3::Inst(), v); }
    
    Binary Group1Var2::Read(const apl::byte_t* p) const { return DNPFromStream::ReadBinaryQV(p, Group1Var2::Inst()); }
    Binary Group2Var1::Read(const apl::byte_t* p) const { return DNPFromStream::ReadBinaryQV(p, Group2Var1::Inst()); }
    Binary Group2Var2::Read(const apl::byte_t* p) const { return DNPFromStream::ReadBinaryQV(p, Group2Var2::Inst()); }
    Binary Group2Var3::Read(const apl::byte_t* p) const { return DNPFromStream::ReadBinaryQVT(p, Group2Var3::Inst()); }

    "We provide world-class engineering services to companies leading the smart energy revolution."
    посредством копипасты. малаца.

    xXx_totalwar, 14 Января 2011

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

    +168

    1. 1
    2. 2
    3. 3
    4. 4
    TOutputConsoleWindow::TOutputConsoleWindow(void)
    {
                  //...
    	_mainWindow = new TConsoleOutputWindow(Rect);

    Говногость, 14 Января 2011

    Комментарии (14)
  4. SQL / Говнокод #5275

    −859

    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
    "SELECT c.type AS type, 
                                      ELT(c.type, g.genre_id, l.label_id, f.film_id, a.actor_id, s.show_id, ch.channel_id,aw.award_id) AS id,
    				  ELT(c.type, g.value, l.value, f.real_name, a.real_name, s.real_name, ch.name, aw.description) AS real_name,
    				  ELT(c.type, NULL, NULL, f.name, a.name, s.name, NULL, NULL) AS name
    				  FROM connector AS c
    				  LEFT JOIN genres AS g ON (c.second = g.genre_id)
                                      LEFT JOIN labels AS l ON (c.second = l.label_id)
                                      LEFT JOIN films AS f ON (c.second = f.film_id)
                                      LEFT JOIN actors AS a ON (c.second = a.actor_id)
                                      LEFT JOIN shows AS s ON (c.second = s.show_id)
                                      LEFT JOIN channels AS ch ON (c.second = ch.channel_id)
                                      LEFT JOIN awards AS aw ON (c.second = aw.award_id)
                                      WHERE c.first = ".$_SESSION['user_id']

    Вот как это делается!

    Elfet, 14 Января 2011

    Комментарии (2)
  5. Python / Говнокод #5274

    −179

    1. 1
    2. 2
    3. 3
    4. 4
    5. 5
    6. 6
    7. 7
    8. 8
    incoming=[2,0,4,6,2,1,0,4,3,0]
    outgoing=[5,0,3,3,0,2,3,5,0,2]
    
    for i in sorted(range(allopers.__len__()), reverse=True):
          if int(incoming[i])==int(outgoing[i])==0:
               del incoming[i]
               del outgoing[i]
               del allopers[i]

    длинна списков allopers, incoming и outgoing равна.
    наговнокожено: пытаюсь исключить из них элементы с номером n, для которых incoming[n]==outgoing[n]==0.
    типа иду с конца, и если совпало - удаляю элемент.

    fr_butch, 14 Января 2011

    Комментарии (11)
  6. Java / Говнокод #5273

    +145

    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
    public String readMessage(String subject) throws Exception {
        String messageString = null;
        try {
          for (final Message message : Arrays.asList(this.inbox.getMessages())) {
            if (subject.equals(message.getSubject())) {
              messageString = "To: " + Arrays.asList(message.getAllRecipients()) + "n" + "From: " + Arrays.asList(message.getFrom()) + "n" + "Sent: "
                + message.getSentDate() + "n" + "Subject: " + message.getSubject() + "n" + "Text: " + message.getContent();
              break;
            }
          }
        } catch (final MessagingException me) {
          throw new Exception("Error reading Inbox", me);
        } catch (final IOException e) {/* Not using streams, only plain text */
        }
        return messageString;
      }

    тестовый javamail клиент(отправка тест-письма,поиск его и удаление). В методе ищем письмо с нужной темой, возвращаем текстовое представление.

    говно, кроме очевидных ляпов, в том, что мы лазием по всем сообщениям, сверяя тему, а получение письма занимает около секунды. Надо ли говорить, что в современном ящике писем тысячи...
    для сравнения:
    если заменить в 4 строчке конструкцию

    Arrays.asList(this.inbox.getMessages())
    на
    new SubjectTerm(subject)
    , то время выполнения сокращается с (неизвестно,точно более времени чаепития) до пары секунд = )

    Lure Of Chaos, 14 Января 2011

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

    +159

    1. 1
    2. 2
    3. 3
    4. 4
    5. 5
    6. 6
    function DateFromDBToHr($date)
    {
    	$datetime = explode(" ", $date);
    	$dates = explode("-", $datetime[0]);
    	return (intval($dates[0])) ? date("d-M-Y", mktime(0, 0, 0, $dates[1], $dates[2], $dates[0])) : false;
    }

    про то, что форматировать дату можно в запросе или про существование strtotime автор даже не догадывается

    elw00d, 14 Января 2011

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

    +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
    (function(){ if(!window.adToken) { window.adToken = Math.floor(Math.random() * 999999999999999999); }
    		var d = new Date();
    		var url = (location.protocol=='https:'?'https://base.kiwi.kz/?':'http://base.kiwi.kz/?');
    		url += 'rnd=' + Math.floor(Math.random() * 99999999999);
    		url	+= '&slot_id=25';
    		url	+= '&type=js';
    		url	+= '&t=' + parseInt(((d.getTime() - (d.getTimezoneOffset() * 60)) / 1000));
    		url	+= '&token=' + window.adToken;
    		url	+= '&r=' + window.location;
    		var js	 = '<sc' + 'ript src="' + url + '"></sc' + 'ript>';
    		document.write(js);
    		}());

    sc' + 'ript ?

    govnozmey, 14 Января 2011

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

    +120

    1. 1
    2. 2
    3. 3
    4. 4
    5. 5
    6. 6
    7. 7
    8. 8
    public static string GetRedirectUrl(string userName, bool createPersistentCookie)
    {
        if (userName == null)
        {
            return null;
        }
        return GetReturnUrl(true);
    }

    из рефлектора, класс FormsAuthentication
    ахеренная роль у параметров userName и createPersistentCookie

    Semargl, 13 Января 2011

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

    +168

    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
    class TalentsWindow : public PopupWindow {
    	render::Sprite* m_background_sprite, *m_header_sprite, *m_fucking_sprite;
    ...
    ...
    };
    
    ...
    
    TalentsWindow::TalentsWindow()
    {
    ...
    	m_fucking_sprite = m_sprites.addSprite(render::SpriteRect(NOINITIALIZE)
                .setTop(591.0f)
                .setLeft(500.0f)
                .setWidth(411.0f)
                .setHeight(140.0f),
                m_tex,
                0.85f
            );
            m_fucking_sprite->setPosition(math::float2(818.0f, 50.0f));
    		m_fucking_sprite->idiot = true;
    ...
    }

    Самодокументирующий код.

    Kirinyale, 13 Января 2011

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