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

    +159

    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
    private function cp1251_utf8($sInput) {
                    $sOutput = "";
                    for ( $i = 0; $i < strlen( $sInput ); $i++ )
                    {
                            $iAscii = ord( $sInput[$i] );
                            if ( $iAscii >= 192 && $iAscii <= 255 )
                                    $sOutput .=  "&#".( 1040 + ( $iAscii - 192 ) ).";";
                            else if ( $iAscii == 168 )
                                    $sOutput .= "&#".( 1025 ).";";
                            else if ( $iAscii == 184 )
                                    $sOutput .= "&#".( 1105 ).";";
                            else
                                    $sOutput .= $sInput[$i];
                    }
    
                    return $sOutput;
            }
    
            protected function utf8_strtr($str, $from, $to = '') {
                    $str = iconv('UTF-8', 'cp1251', $str);
                    $str = $to ? strtr($str, $from, $to) : strtr($str, $from);
                    return iconv('cp1251', 'UTF-8', $str);
            }
    
            public function date_rus($str) {
                    $str = str_replace('Jan', 'Янв', $str);
                    $str = str_replace('Feb', 'Фев', $str);
                    $str = str_replace('Mar', 'Мар', $str);
                    $str = str_replace('Apr', 'Апр', $str);
                    $str = str_replace('May', 'Май', $str);
                    $str = str_replace('Jun', 'Июн', $str);
                    $str = str_replace('Jul', 'Июл', $str);
                    $str = str_replace('Aug', 'Авг', $str);
                    $str = str_replace('Sep', 'Сен', $str);
                    $str = str_replace('Oct', 'Окт', $str);
                    $str = str_replace('Nov', 'Ноя', $str);
                    $str = str_replace('Dec', 'Дек', $str);
                    return $str;
            }

    пара функций из одного интересного проекта =)
    перекодировка с подвыпердоворотом, перевод даты на русский без компромисов

    fr_butch, 06 Сентября 2011

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

    +78

    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
    /**
    	* @param loginName
    	* @return
    	* This method is create a LoginName as Input data
    	*/
    public String getLoginName(String loginName)
    {
    	String userQuery="select u.LoginName from User u";
    	Recordset rs_user=null;
    	rs_user = CustomExternalServiceImplUtil.getInstance().executeQuery(userQuery);
    	List<String> userList = new ArrayList<String>();
    	while(rs_user.moveNext()){ 
    		userList.add(rs_user.valueFromIndex(0).toString());
    	}
    	int i=1;
    	String result = loginName;
    	for(int j=0; j < userList.size(); j++){
    		if(userList.get(j).equals(result))
    		{
    			result = loginName+i++;
    			j=0;
    		}
    	}
    	return result;
    }

    Рефаткоринг чужого кода. Минут пять втуплял, что же тут вообще делается. Еще столько же придумывал, как же это привести в божеский вид с сохранением прежней функциональности.

    askell, 06 Сентября 2011

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

    +162

    1. 01
    2. 02
    3. 03
    4. 04
    5. 05
    6. 06
    7. 07
    8. 08
    9. 09
    10. 10
    public function editSetting($group, $data, $store_id = 0) {
    	$this->db->query("DELETE FROM " . DB_PREFIX . "setting WHERE store_id = '" . (int)$store_id . "' AND `group` = '" . $this->db->escape($group) . "'");
    	foreach ($data as $key => $value) {
    		if (!is_array($value)) {
    			$this->db->query("INSERT INTO " . DB_PREFIX . "setting SET store_id = '" . (int)$store_id . "', `group` = '" . $this->db->escape($group) . "', `key` = '" . $this->db->escape($key) . "', `value` = '" . $this->db->escape($value) . "'");
    		} else {
    			$this->db->query("INSERT INTO " . DB_PREFIX . "setting SET store_id = '" . (int)$store_id . "', `group` = '" . $this->db->escape($group) . "', `key` = '" . $this->db->escape($key) . "', `value` = '" . $this->db->escape(serialize($value)) . "', serialized = '1'");
    		}
    	}
    }

    Всё оттуда же (Open Cart).
    Оно бы вроде и ничего, если бы не id и автоинкрементом в таблице "setting". Вот так вот, каждый раз сохраняя настройки, мы прибиваем стопицот старых значений и заводим столько же совершенно новых, которые, тем не менее, в большинстве своём ничем не отличаются от старых.

    cybervantyz, 06 Сентября 2011

    Комментарии (12)
  4. Java / Говнокод #7786

    +86

    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
    private static void slowDownABit() {
            for (int i = 0; i < 100; i++) {
                new Thread() {
    
                    @Override
                    public void run() {
                        for (int i = 0; i < 10000000; i++) {
                            double d1 = Math.random() + 1;
                            double d2 = Math.random() + 1;
                            double d3 = Math.random() + 1;
                            double d4 = Math.random() + 1;
                            double d = d1 * d2 / d3 / d4 * Math.sin(Math.random());
                        }
                    }
                }.start();
            }
        }

    akkuch, 06 Сентября 2011

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

    +159

    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
    if (isset($this->request->post['config_image_manufacturer_height'])) {
    			$this->data['config_image_manufacturer_height'] = $this->request->post['config_image_manufacturer_height'];
    		} else {
    			$this->data['config_image_manufacturer_height'] = $this->config->get('config_image_manufacturer_height');
    		}
    
    		if (isset($this->request->post['config_image_additional_width'])) {
    			$this->data['config_image_additional_width'] = $this->request->post['config_image_additional_width'];
    		} else {
    			$this->data['config_image_additional_width'] = $this->config->get('config_image_additional_width');
    		}
    		
    		if (isset($this->request->post['config_image_additional_height'])) {
    			$this->data['config_image_additional_height'] = $this->request->post['config_image_additional_height'];
    		} else {
    			$this->data['config_image_additional_height'] = $this->config->get('config_image_additional_height');
    		}
    		
    		if (isset($this->request->post['config_image_related_width'])) {
    			$this->data['config_image_related_width'] = $this->request->post['config_image_related_width'];
    		} else {
    			$this->data['config_image_related_width'] = $this->config->get('config_image_related_width');
    		}
    		
    		if (isset($this->request->post['config_image_related_height'])) {
    			$this->data['config_image_related_height'] = $this->request->post['config_image_related_height'];
    		} else {
    			$this->data['config_image_related_height'] = $this->config->get('config_image_related_height');
    		}
    		
    		if (isset($this->request->post['config_image_compare_width'])) {
    			$this->data['config_image_compare_width'] = $this->request->post['config_image_compare_width'];
    		} else {
    			$this->data['config_image_compare_width'] = $this->config->get('config_image_compare_width');
    		}

    Всего лишь небольшой кусок кода из админки OpenCart-а.
    Люди! OpenCart - гамно.

    cybervantyz, 06 Сентября 2011

    Комментарии (0)
  6. Ruby / Говнокод #7784

    −99

    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
    begin
        # etc
      rescue Exception => e
        case e
          when LinkedIn::Unauthorized
            account.invalidate_token if !account.invalid_token?
            raise InvalidTokenException.new(account.primary, provider_name)
          when LinkedIn::InformLinkedIn, LinkedIn::Unavailable  #LinkedIn::Unavailable represents 502..503 error codes & LinkedIn::InformLinkedIn represent 500
            raise UnexpectedApiException.new(provider_name)
          else
            handle_api_exception(e, e.message)
        end
      end

    элегантный отлов ексепшнов

    sumskyi, 06 Сентября 2011

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

    +101

    1. 1
    2. 2
    3. 3
    i := -7; // если после этой строчки загнать в отладчик i shr 1, то отладчик покажет -4
    i := i shr 1; // после этой строчки i становится равно 2147483644
    i := (-7) shr 1; // после этой строчки i становится равно 4

    Delphi7 такой Delphi7...

    http://www.gamedev.ru/code/forum/?id=138759&page=25#m367
    Тарас любит дельфи.

    CPPGovno, 06 Сентября 2011

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

    +159

    1. 01
    2. 02
    3. 03
    4. 04
    5. 05
    6. 06
    7. 07
    8. 08
    9. 09
    10. 10
    $("html > body a#order_check").click(function(){
    	if($("html > body a#order_check").is(".active") && !$("html > body div#order_check_b").is(":hidden")){
    		$("#order_check").removeClass("active")
    		$("#order_check_b").hide()
    	}
    	if(!$("html > body a#order_check").is(".active") && $("html > body div#order_check_b").is(":hidden")){
    		$("html > body #order_check").addClass("active")
    		$("html > body #order_check_b").show()
    	}
    })

    Connor, 06 Сентября 2011

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

    +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
    >>>http://www.viva64.com/ru/a/0023/
    #ifdef DEBUG_MODE
      #define WriteLog printf
    #else
      inline int StubElepsisFunctionForLog(...) { return 0; }
      static class StubClassForLog {
      public:
        inline void operator =(size_t) {}
      private:
        inline StubClassForLog &operator =(const StubClassForLog &)
          { return *this; }
      } StubForLogObject;
      
      #define WriteLog \
        StubForLogObject = sizeof StubElepsisFunctionForLog
    #endif
      WriteLog("Coordinate = (%d, %d)\n", x, y);
    &&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&
    ССЗБ?
    P.S #define WriteLog(...) 
                or 
        #define WriteLog __noop

    dc9e6c73ef5541f1, 05 Сентября 2011

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

    +146

    1. 1
    2. 2
    3. 3
    4. 4
    5. 5
    case '16':
                dm("sixteenth");
                *b_=FULL_NOTE_DURATION_TCK/16 & 0x0F;
                *c_=(FULL_NOTE_DURATION_TCK/16 & 0xF0) >> 8;
            break;

    Человек парсил хексы из строки и задумался немного при копировании блоков в свитче.

    m08pvv, 05 Сентября 2011

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