1. Java / Говнокод #6289

    +76

    1. 1
    2. 2
    3. 3
    4. 4
    5. 5
    6. 6
    private  void sortPropertyTypeList(List<PropertyTypeDTO> list){
    		Set<PropertyTypeDTO> propertyTypeSet = new TreeSet<PropertyTypeDTO>(propertyTypeComparator);
    		propertyTypeSet.addAll(list);
    		list.clear();
    		list.addAll(propertyTypeSet);
    	}

    Новаторская сортировочка:)

    hellwalker, 08 Апреля 2011

    Комментарии (1)
  2. SQL / Говнокод #6288

    −855

    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
    SELECT h.*,
    			      if(h.gender_id != 0, (SELECT g.title FROM p_cm5_horses_gender g WHERE h.gender_id = g.id AND h.lang_id = g.lang_id),"") AS gender,
    			        if(h.colour_id != 0, (SELECT c.title FROM p_cm5_horses_colour c WHERE h.colour_id = c.id AND h.lang_id = c.lang_id),"") AS colour,
    			        if(h.color_group != 0, (SELECT cg.title FROM p_cm5_horses_colour_group cg WHERE h.color_group = cg.id AND h.lang_id = cg.lang_id),"") AS color_group_name,
    			        if(h.temper_id != 0, (SELECT t.title FROM p_cm5_horses_temper t WHERE h.temper_id = t.id AND h.lang_id = t.lang_id),"") AS temper,
    			        if(h.grading_id != 0, (SELECT t.title FROM p_cm5_horses_grading t WHERE h.temper_id = t.id AND h.lang_id = t.lang_id),"") AS grading,
    			        if(h.breed_id != 0, (SELECT b.title FROM p_cm5_horses_studbook b WHERE h.breed_id = b.id AND h.lang_id = b.lang_id),"") AS breed,
    			        if(h.training_first != 0, (SELECT t.training_name FROM p_cm5_horses_training t WHERE h.training_first = t.id AND h.lang_id = t.lang_id),"") AS training_first_name,
    			        if(h.level_first != 0, (SELECT t.level_name FROM p_cm5_horses_training_level t WHERE h.level_first = t.id AND h.lang_id = t.lang_id),"") AS level_first_name,
    			        if(h.training_second != 0, (SELECT t.training_name FROM p_cm5_horses_training t WHERE h.training_second = t.id AND h.lang_id = t.lang_id),"") AS training_second_name,
    			        if(h.level_second != 0, (SELECT t.level_name FROM p_cm5_horses_training_level t WHERE h.level_second = t.id AND h.lang_id = t.lang_id),"") AS level_second_name,
    			        if(h.price_id != 0, (SELECT p.title FROM p_cm5_horses_price p WHERE h.price_id = p.id AND h.lang_id = p.lang_id),"") AS price,
    			        if(h.price_id != 0, (SELECT p.title FROM p_cm5_horses_price p WHERE h.price_id = p.id AND p.lang_id = 2),"") AS price2
    			        FROM p_cm5_horses h
    			        WHERE h.enabled = 1 AND h.lang_id = 1 AND h.id = 219

    копался в одном проекте который нам отдали на аутсорс, нашел своего рода LEFT JOIN-ины

    fosco, 08 Апреля 2011

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

    +162

    1. 1
    2. 2
    3. 3
    4. 4
    $val = $_POST["value"];
    $val = str_replace("e", "&#0101;", $val);
    $val = str_replace("E", "&#0069;", $val);
    mysql_query("insert into `table` (`value`) values '$val'");

    Это мы так спасаемся от mysql-инъекций.

    ling, 08 Апреля 2011

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

    +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
    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
    #ifndef _header_hpp_included_
    #define _header_hpp_included_
     
    #include <iostream>
    #include <cstdio>
    #include <boost/bind.hpp>
    #include <boost/asio.hpp>
    #include <boost/thread.hpp>
    #include <boost/lexical_cast.hpp>
     
    enum { recv_buffer_size = 13 };
    enum { send_buffer_size = 13 };
     
    volatile size_t counter = 0;
     
    void client_readed(
       boost::asio::ip::tcp::socket&,
       char*,
       FILE*,
       const boost::system::error_code&
    );
     
    void client_read(
       boost::asio::ip::tcp::socket& sock,
       FILE* out
    ) {
       char* buf = new char[recv_buffer_size];
       boost::asio::async_read(
          sock,
          boost::asio::buffer(buf, recv_buffer_size),
          boost::bind(
             &client_readed,
             boost::ref(sock),
             buf,
             out,
             boost::asio::placeholders::error));}
     
    void client_readed(
       boost::asio::ip::tcp::socket& sock,
       char* buf,
       FILE* out,
       const boost::system::error_code& e) {
       if ( e ) {
          if ( !counter ) return;
          std::cout << "read handler: " << e.message() << std::endl;
          return;
       }
        fwrite(buf, recv_buffer_size, 1, out);
        counter--;
     
    #ifdef _my_debug_
       printf("client_readed(): %s", buf);
       fflush(stdout);
    #endif
     
       static size_t idx = 0;
       size_t tmp = 0;
       char* p = strchr(buf, ':');
       if ( p ) {
          p++;
          sscanf(p, "%8d", &tmp);
       } else
          throw std::runtime_error("input data error!");
       delete[] buf;
       if ( idx != tmp ) {
          std::ostringstream os;
          os << "read error. expected " << idx << " get " << tmp;
          throw std::runtime_error(os.str());
       }
       idx++;
       client_read(sock, out);
    }
     
    void writen(
       char*,
       FILE*,
       const boost::system::error_code&
    );
     
    void start_write(
       boost::asio::ip::tcp::socket& sock,
       char* buf,
       FILE* out) {
       counter++;
       boost::asio::async_write(
          sock,
          boost::asio::buffer(buf, send_buffer_size),
          boost::bind(
             &writen,
             buf,
             out,
             boost::asio::placeholders::error) 
        ); 
    }

    qbasic, 08 Апреля 2011

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

    +161

    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
    #include "header.hpp"
     
    int main(int argc, char** argv) {
       if ( argc != 4 ) {
          std::cout << "client ip port 0/1 - sleed disabled/enabled" << std::endl;
          return 0;
       }
       std::string ip = argv[1];
       boost::uint16_t port = boost::lexical_cast<boost::uint16_t>(argv[2]);
       bool wsleep = (argv[3][0] == '1');
       std::cout << "sleep " << (wsleep?"enabled":"disabled") << std::endl;
       
       FILE* in = fopen("client_in.log", "wb");
       FILE* out= fopen("client_out.log", "wb");
       if ( !out || !in ) {
          std::cout << "can`t open file!" << std::endl;
          return 1;
       }
     
       boost::asio::ip::tcp::endpoint endpoint(
          boost::asio::ip::address::from_string(ip), port
       );
     
       boost::asio::io_service ios;
       boost::shared_ptr<boost::asio::io_service::work> work(new boost::asio::io_service::work(ios));
     
       boost::thread thread(boost::bind(&boost::asio::io_service::run, &ios));
       
       boost::asio::ip::tcp::socket socket(ios);
       socket.connect(endpoint);
     
       boost::asio::socket_base::non_blocking_io non_blocking_io(true);
       socket.io_control(non_blocking_io);
     
       client_read(socket, in);
     
       for ( size_t idx = 0; idx < 100000000; ++idx ) {
          char* buf = new char[send_buffer_size];
          sprintf(buf, "cs:%8dn", idx);
          start_write(socket, buf, out);
          if ( wsleep ) {
             boost::this_thread::sleep(boost::posix_time::microseconds(1000));
          }
       }
     
       std::cout
       << "send data to server finished!" << std::endl
       << "waiting for all ask`s from server..." << std::endl;
     
       work.reset();
     
       while ( counter ) {
          boost::this_thread::sleep(boost::posix_time::microseconds(1000));
          std::cout << "." << std::flush;
       }
     
       std::cout << std::endl << std::endl
       << "all ask`s received." << std::endl
       << "terminate client..." << std::endl;
     
       socket.cancel();
       socket.close();
     
       thread.join();
       fclose(in);
       fclose(out);
    }

    qbasic, 08 Апреля 2011

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

    +166

    1. 1
    $dctEvent =new EventData_IEM_ADDON_DYNAMICCONTENTTAGS_REPLACETAGCONTENT();

    Из одной системы мэйлмаркетинга. Там еще много ГК...

    rO_ot, 08 Апреля 2011

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

    +161

    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
    $tmpProduct = array(
    ...
        'FARE' => $tmpFares,
        '~FARE' => CTRSCurrency::GetStringFull($row['FARE'], $o['CURRENCY']),
        'TAX' => CTRSCurrency::GetString($row['TAX'], $o['CURRENCY']),
        '~TAX' => CTRSCurrency::GetStringFull($row['TAX'], $o['CURRENCY']),
    ...
    );
    
    ...
    	
    $tmpProduct['FARE_'] = $tmpProduct['~FARE'];
    $tmpProduct['TAX_'] = $tmpProduct['~TAX'];
    $tmpProduct['~FARE_'] = $row['FARE'];
    $tmpProduct['~TAX_'] = $row['TAX'];

    Из одного очень большего компонента...

    wwwguru, 08 Апреля 2011

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

    +161

    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
    //стандарт
    		$price_st = mysql_query("select price from db_tarif where `from` = '$start' and `to` = '$finish' and ves_ot <= '$izmer' and  ves_do>= '$izmer' and `type`='$type_st' limit 1");
    		$price_st = mysql_result($price_st, 0);
    
    		$minprice_st = mysql_query("select minprice from db_tarif where `from` = '$start' and `to` = '$finish' and ves_ot <= '$izmer' and ves_do >= '$izmer' and `type`='$type_st' limit 1");
    		$minprice_st = mysql_result($minprice_st, 0);
    		$time_st = mysql_query("select time from db_tarif where `from` = '$start' and `to` = '$finish' and ves_ot <= '$izmer' and ves_do >= '$izmer' and `type`='$type_st' limit 1");
    		$time_st = mysql_result($time_st, 0);
    
    	//экспресс
    		$price_ex = mysql_query("select price from db_tarif where `from` = '$start' and `to` = '$finish' and ves_ot <= '$izmer' and  ves_do>= '$izmer' and `type`='$type_ex' limit 1");
    		$price_ex = mysql_result($price_ex, 0);
    		$minprice_ex = mysql_query("select minprice from db_tarif where `from` = '$start' and `to` = '$finish' and ves_ot <= '$izmer' and ves_do >= '$izmer' and `type`='$type_ex' limit 1");
    		$minprice_ex = mysql_result($minprice_ex, 0);
    		$time_ex = mysql_query("select time from db_tarif where `from` = '$start' and `to` = '$finish' and ves_ot <= '$izmer' and ves_do >= '$izmer' and `type`='$type_ex' limit 1");
    		$time_ex = mysql_result($time_ex, 0);
    
    	//Ритейл
    		$price_pallet = mysql_query("select price from db_tarif where `from` = '$start' and `to` = '$finish' and ves_ot <= '$pallets' and  ves_do>= '$pallets' and `type`='$type_rit' limit 1");
    		$price_pallet = mysql_result($price_pallet, 0);
    
    		$time_pallet = mysql_query("select time from db_tarif where `from` = '$start' and `to` = '$finish' and ves_ot <= '$pallets' and ves_do >= '$pallets' and `type`='$type_rit' limit 1");
    		$time_pallet = mysql_result($time_pallet, 0);
    
    	//авиа
    		if ($start==getIdCity('Москва')){
    
    			if ($volume*167>$weight){
    				$izmer=(float)($volume*167);
    				$kol_av = $volume*167;
    			}
    			else
    			{
    				$izmer=$weight;
    				$kol_av = $weight;
    			}
    			$price_av = mysql_query("select price from db_tarif where `from` = '$start' and `to` = '$finish' and ves_ot <= '$izmer' and  ves_do>= '$izmer' and `type`='$type_av' limit 1");
    			$price_av = mysql_result($price_av, 0);
    			$minprice_av = mysql_query("select minprice from db_tarif where `from` = '$start' and `to` = '$finish' and ves_ot <= '$izmer' and ves_do >= '$izmer' and `type`='$type_av' limit 1");
    			$minprice_av = mysql_result($minprice_av, 0);
    			$time_av = mysql_query("select time from db_tarif where `from` = '$start' and `to` = '$finish' and ves_ot <= '$izmer' and ves_do >= '$izmer' and `type`='$type_av' limit 1");
    			$time_av = mysql_result($time_av, 0);
    		}
    		else{
    			$cost_av = "Тариф недоступен";
    		}

    калькулятор стоимости перевозки

    Shiz89, 08 Апреля 2011

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

    +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
    13. 13
    14. 14
    $gun = 0;
    while ($gun < 10000000)
    {
     // Дохуя кода
     $gun++;
     if ( $win2 >= $casbank ) 
     {
      $gun = 12; 
     }
     else 
     {
      $gun = 13500000;               
     }
    }

    partizan22, 08 Апреля 2011

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

    +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
    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
    class CStateShortMap
    {
    public:
      CStateShortMap(int id, TDateTime time, TZReadOnlyQuery* query);
      void Load(TZReadOnlyQuery* query, TDateTime time);
      int GetTypeSize() const { return Items.size(); }
      char GetType(int idx)
      {
        return Items[idx].first;
      }
      std::vector< std::vector<CStateShortItem> >& GetItems(char type)
      {
        for(int i=0; i < Items.size(); i++)
        {
          if( Items[i].first == type )
            return Items[i].second;
        }
        return Items[0].second;
      }
    private:
      const int Id;
      std::vector< std::pair<char, std::vector< std::vector<CStateShortItem> > > > Items;
    };
    
    CStateShortMap::CStateShortMap(int id, TDateTime time, TZReadOnlyQuery* query)
     : Id(id)
    {
      Load( query, time );
    }
    
    void CStateShortMap::Load(TZReadOnlyQuery* query, TDateTime time)
    {
      Items.clear();
      String sql;
      sql.sprintf( "select map.id_, equipment.type_"
                   " from map left join equipment on map.equipment_id=equipment.id_"
                   " where map.station_id=%d order by equipment.type_", Id );
      query->SQL->Text = sql;
      query->Open();
      vector< pair<int, char> > mapId;
      while( !query->Eof )
      {
        mapId.push_back( pair<int, char>(query->FieldByName( "id_" )->AsInteger, query->FieldByName( "type_" )->AsString[1]) );
        query->Next();
      }
      Items.clear();
      for(int i=0; i<mapId.size(); i++)
      {
        sql.sprintf( "select status.color, status.name_, map.number_equipment, equipment_status.status_id, equipment_status.begin_, equipment_status.plan_end_"
                     " from equipment_status left join map on equipment_status.map_id=map.id_"
                     " left join status on equipment_status.status_id=status.id_"
                     " where equipment_status.map_id=%d and begin_<='%s' order by equipment_status.begin_ desc limit 1",
                     mapId[i].first, time.FormatString("yyyy-mm-dd hh:nn:ss") );   //equipment_status.id_
        query->SQL->Text = sql;
        query->Open();
        if( query->Eof ) continue;
        int id[] = { 0, 1, 1, 1, 1, 2, 3, 1, 1, 1 };
        int j;
        for(j=0; j<Items.size(); j++)
          if( Items[j].first==mapId[i].second )
            break;
        if( j!=Items.size() )
          Items[j].second[id[query->FieldByName( "status_id" )->AsInteger]].push_back( CStateShortItem( query ) );
        else
        {
          Items.push_back( std::pair<char, std::vector< std::vector<CStateShortItem> > >( mapId[i].second, std::vector< std::vector<CStateShortItem> >() ) );
          Items[ Items.size()-1 ].second.resize( 4 );
          Items[ Items.size()-1 ].second[ id[query->FieldByName( "status_id" )->AsInteger] ].push_back( CStateShortItem( query ) );
        }
      }
      for(int i=0; i<Items.size(); i++)
      {
        sort( Items[i].second[0].begin(), Items[i].second[0].end() );
        sort( Items[i].second[1].begin(), Items[i].second[1].end() );
        sort( Items[i].second[2].begin(), Items[i].second[2].end() );
        sort( Items[i].second[3].begin(), Items[i].second[3].end() );
      }
    }

    старый проект на борландбыдлере, найденный на новой работе

    ni3_inv, 08 Апреля 2011

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