1. Лучший говнокод

    В номинации:
    За время:
  2. Ruby / Говнокод #7902

    −105

    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
    def show
        @updates = UpdateList.new
        update_id = params[:update_id]
    
        if 'twitter' == @provider_key
          provider_api = ProviderApi::Twitter.new(current_user)
    
          if update_id.present?
            begin
              benchmark(" Twitter API: status") do
                @api_response = provider_api.status(update_id)
              end
              @update = update = SocialUpdate.from_twitter_response(@api_response, true)
              while update && (in_reply_to = update.in_reply_to_update_id)
                benchmark(" Twitter API: status") do
                  @previous_status = provider_api.status(in_reply_to)
                end
    
                if error = @previous_status['error']
                  @updates << SocialUpdate.from_twitter_error(error)
                  break
                else
                  update = SocialUpdate.from_twitter_response(@previous_status, true)
                  @updates << update
                end
              end
            rescue => e
              logger.info("Error in fetching status #{in_reply_to || update_id}: #{e}")
            end
          end
        end
    
        @update.flag_for_user(current_user) if @update
        @updates.flag_for_user(current_user)
      end

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

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

    +143

    1. 1
    2. 2
    3. 3
    4. 4
    void crash()
    {
        (( void(*)() )0)();
    }

    Crash ;]

    petersvp, 19 Сентября 2011

    Комментарии (1)
  4. Objective C / Говнокод #7875

    −111

    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
    if(selectedLanguage==French)
        {
    
            FinalString = [[NSString alloc] initWithFormat:@"http://www.xyz.com/api_com.php?page_id=%d",IDValue];
            url = [[NSURL alloc] initWithString:FinalString];
        }
        else if(selectedLanguage==German)
        {
    
            FinalString = [[NSString alloc] initWithFormat:@"http://www.x.com/api_com.php?page_id=%d",IDValue];
            url = [[NSURL alloc] initWithString:FinalString];
        }
        else if(selectedLanguage==Nepali)
        {
    
            FinalString = [[NSString alloc] initWithFormat:@"http://www.xy.com/api_com.php?page_id=%d",IDValue];
            url = [[NSURL alloc] initWithString:FinalString];
    
        }

    mazder, 16 Сентября 2011

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

    −116

    1. 1
    2. 2
    3. 3
    4. 4
    5. 5
    --Если идентификатор аккаунта не передан возвращаем NULL
    IF @AccountID <= 0 OR @AccountID IS NULL RETURN 3;
    
    --Для администраторов всегда возвращаем NULL
    IF @Role = 'admin' OR @Role = 'super_admin' RETURN 3;

    Тело одной из хранимых процедур. Комментарии, видать, протухли.

    dante, 02 Сентября 2011

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

    +161

    1. 1
    2. 2
    3. 3
    4. 4
    5. 5
    6. 6
    7. 7
    class OnBeginRequest
    {
    	public static function run( CEvent $event )
    	{
    		Order::model()->onOrderCreate = function( Cevent $event ) {};
    	}
    }

    Cервис на yii framework. Какой сакральный смысл заложен, неизвестно. Скорее всего, какой-то невероятной крутости костыль, типа не срабатывало событие.

    mitallast, 31 Августа 2011

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

    +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
    // mysql_affected_rows порядка 200 записей
    while ($row_ex=mysql_fetch_array($res_ex)){
       $e_arr[trim(strtoupper($row_ex[0]))] = $row_ex[1];
        $exc .= "(".preg_replace("/(\*|\+|\(|\))/","\\\\$0",$row_ex[0])."(\ |\,|\<|\n|\.)+)|";
    }
    
    if ($exc){
        preg_match_all("/(".$exc.")(?!<\/a>)/i",$Tour['info'],$maches);
         $mach=array_unique($maches[0]);
         unset($maches);
         foreach ($mach as $e_name){
           $last_c=substr($e_name,-1);
           if ($last_c=="<" || $last_c=="," || $last_c==".") $e_name = substr($e_name,0,-1);
           if ($e_name[trim(strtoupper($e_name))])
           $Tour['info'] = preg_replace("/$e_name(?!.?<\/a>)/","<a href='".$e_arr[trim(strtoupper($e_name))]."\.html'>".$e_name."<\/a>",$Tour['info']);
         }
    
        preg_match_all("/(".$exc.")(?!<\/a>)/i",$Tour['info1'],$maches);
         $mach=array_unique($maches[0]);
         unset($maches);
         foreach ($mach as $e_name){
           $last_c=substr($e_name,-1);
           if ($last_c=="<" || $last_c=="," || $last_c==".") $e_name = substr($e_name,0,-1);
    $e_arr[trim(strtoupper($e_name))]."\.html'>".$e_name."<\/a>",$Tour['info1']);
         }
    
        preg_match_all("/(".$exc.")(?!<\/a>)/i",$Tour['info2'],$maches);
         $mach=array_unique($maches[0]);
         unset($maches);
         foreach ($mach as $e_name){
           $last_c=substr($e_name,-1);
           if ($last_c=="<" || $last_c=="," || $last_c==".") $e_name = substr($e_name,0,-1);
    $e_arr[trim(strtoupper($e_name))]."\.html'>".$e_name."<\/a>",$Tour['info2']);
         }
    
        preg_match_all("/(".$exc.")(?!<\/a>)/i",$Tour['shedulle'],$maches);
         $mach=array_unique($maches[0]);
         unset($maches);
         foreach ($mach as $e_name){
           $last_c=substr($e_name,-1);
           if ($last_c=="<" || $last_c=="," || $last_c==".") $e_name = substr($e_name,0,-1);
         }
    
      }

    http://govnokod.ru/7602 "Регулярки? Да, слышал!"
    Итого + 8-10 секунд на исполнение.

    govnoacc, 21 Августа 2011

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

    +115

    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
    //1
    directory = WebConfigurationManager.ConnectionStrings[Page.Server.MachineName.ToUpper() + Request.QueryString["number"]].ConnectionString;
    //2
    web.config:
    <connectionStrings>
      <add name="ServerName1" connectionString="D:\bla\incoming\" /> 
      <add name="ServerName2" connectionString="D:\bla\outcoming\" /> 
      ...
     </connectionStrings>
    //3
    function Upload(currFile) {
    if (grafWin == null || grafWin.closed) {
    	grafWin = open('UpLoad.aspx?number=' + currFile,'Attachment','width=300,height=150,scrollbars=no,left=800,top=400');
    	self.name = "winPARENT";
    }
    }
    //4
    <input type="button" name="filePlus1" value=" + " style="visible;" onclick="javascript: Upload('1')">

    1) Сохранение документов на стороне сервера выбор папки назначения
    2) web.config
    3) js-function для вызова страницы
    4) html контрол для вызова страницы которая сохранит документ в папку D:\bla\incoming

    TasmX, 17 Августа 2011

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

    +159

    1. 1
    2. 2
    3. 3
    4. 4
    5. 5
    6. 6
    7. 7
    8. 8
    9. 9
    var path = [
        (this.gridSetId || this.projection.projCode.replace(":", "_")) + "_" + this.zeroPad(z, 2),
        //this.zeroPad(halfX, digits) + "_" + this.zeroPad(halfY, digits),
    /*
    * ОООООООЧЕНЬ ГРЯЗНО!!!!!!!!!!!!
    * */
        this.zeroPad(halfX, 1) + "_" + this.zeroPad(halfY, 1),
        this.zeroPad(x, 2 * digits) + "_" + this.zeroPad(y, 2 * digits) + "." + this.type
    ].join("/");

    musuk, 12 Августа 2011

    Комментарии (1)
  10. Java / Говнокод #7505

    +75

    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
    public static boolean checkInt(String value, SocketMessage message,
    			int min, int max, boolean isNullCheck, Settings settings) {
    		if (value == null) {
    			if (!isNullCheck)
    				return true;
    			if (message != null && settings != null)
    				message.addSubMessage(ErrorSubElement.createErrorSubMessage(
    						ErrorSubElement.INVALID_ARGUMENT, "Invalid Int value",
    						settings));
    			return false;
    		}
    
    		if (value.length() > 9) {
    			if (message != null && settings != null)
    				message.addSubMessage(ErrorSubElement.createErrorSubMessage(
    						ErrorSubElement.INVALID_ARGUMENT, "Invalid Int value: "
    								+ value, settings));
    			return false;
    		}
    		try {
    			int val = Integer.parseInt(value);
    			MyLog.d(LOG_TAG, "Check Val:" + val);
    			if (val < min) {
    				if (message != null && settings != null)
    					message.addSubMessage(ErrorSubElement
    							.createErrorSubMessage(
    									ErrorSubElement.INVALID_ARGUMENT,
    									"Invalid Int value: " + value
    											+ " lower than " + min, settings));
    				return false;
    			}
    
    			if (val > max) {
    				if (message != null && settings != null)
    					message.addSubMessage(ErrorSubElement
    							.createErrorSubMessage(
    									ErrorSubElement.INVALID_ARGUMENT,
    									"Invalid Int value: " + value
    											+ " bigger than " + max, settings));
    				return false;
    			}
    			return true;
    		} catch (NumberFormatException e) {
    			if (message != null && settings != null)
    				message.addSubMessage(ErrorSubElement.createErrorSubMessage(
    						ErrorSubElement.INVALID_ARGUMENT, "Invalid Int value: "
    								+ value, settings));
    			return false;
    		}
    	}

    xitx, 10 Августа 2011

    Комментарии (1)
  11. C# / Говнокод #7503

    +126

    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
    //calculate elapsed time
    TimeSpan elapsed = DateTime.Now - startTime;
    //if a second has elapsed
    if (lastSecond != elapsed.Seconds)
    {
    	//store last second
    	lastSecond = elapsed.Seconds;
    	//get hours
    	string hours;
    	if (elapsed.Hours < 10)
    		hours = "0" + elapsed.Hours.ToString();
    	else
    		hours = elapsed.Hours.ToString();
    	//get minutes
    	string minutes;
    	if (elapsed.Minutes < 10)
    		minutes = "0" + elapsed.Minutes.ToString();
    	else
    		minutes = elapsed.Minutes.ToString();
    	//get seconds
    	string seconds;
    	if (elapsed.Seconds < 10)
    		seconds = "0" + elapsed.Seconds.ToString();
    	else
    		seconds = elapsed.Seconds.ToString();
    	//update label
    	this.lblElapsedTime.Text = "Elapsed time: " + hours + ":" + minutes + ":" + seconds;
    }

    Явно автор сего кода был не знаком со string.format.

    xxxcoderxxx, 10 Августа 2011

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