1. C++ / Говнокод #13087

    +23

    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
    #ifndef SAFE_RELEASE
    #define SAFE_RELEASE(x) \
       if(x != NULL)        \
       {                    \
          x->Release();     \
          x = NULL;         \
       }
    #endif
    
    #define SAFE_DELETE(a) if( (a) != NULL ) delete (a); (a) = NULL;
    
    #ifndef SAFE_ARRAY_DELETE
    #define SAFE_ARRAY_DELETE(x) \
       if(x != NULL)             \
       {                         \
          delete[] x;            \
          x = NULL;              \
       }
    #endif
    
    #define SAFE_FREE( p )      if( p ) { free( p ) ; p=NULL ; }

    Я вот все никак не могу забыть старый код из доков макрософт по COM, а также из книги Андре Ла Мота.

    Два макроса до сих пор висят среди доков на сайте мс (по коду догадаетесь какие):

    http://msdn.microsoft.com/ru-RU/library/windows/desktop/dd743946(v=vs.85).aspx

    LispGovno, 01 Июня 2013

    Комментарии (48)
  2. Куча / Говнокод #13086

    +118

    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
    <div class="is-element-border-top">
              <div class="is-element-border-right">
                <div class="is-element-border-bottom">
                  <div class="is-element-border-left">
                    <div class="is-element-corner-top-left">
                      <div class="is-element-corner-top-right">
                        <div class="is-element-corner-bottom-right">
                          <div class="is-element-corner-bottom-left">
                            <span class="curr_show ">
                              5 days                        </span>
                          </div>
                        </div>
                      </div>
                    </div>
                  </div>
                </div>
              </div>
            </div>

    Каскадная таблица стилей, ёпта.

    bot-minurast, 01 Июня 2013

    Комментарии (3)
  3. Java / Говнокод #13085

    +76

    1. 1
    https://github.com/mongodb/mongo-java-driver/blob/master/src/main/com/mongodb/ConnectionStatus.java#L213

    wtf?!

    orion, 31 Мая 2013

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

    −117

    1. 01
    2. 02
    3. 03
    4. 04
    5. 05
    6. 06
    7. 07
    8. 08
    9. 09
    10. 10
    [storeButton performSelectorInBackground:@selector(onTouchUp) withObject:nil];
    ...
    -(void)onTouchUp{
       [self                   setHighlighted:NO];
       [self.storeNameLabel         setHighlighted:NO];
       [self.storeAddressLabel      setHighlighted:NO];
       [self.storePhoneLabel        setHighlighted:NO];
       [self.storeAddress2Label     setHighlighted:NO];
       
    }

    torip3ng, 31 Мая 2013

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

    +77

    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
    public CommandResult update() {
                CommandResult res = null;
                try {
                    long start = System.nanoTime();
                    res = _port.runCommand(_mongo.getDB("admin"), isMasterCmd);
                    long end = System.nanoTime();
                    float newPingMS = (end - start) / 1000000F;
                    if (!successfullyContacted)
                        _pingTimeMS = newPingMS;
                    else
                        _pingTimeMS = _pingTimeMS + ((newPingMS - _pingTimeMS) / latencySmoothFactor);
    
                    getLogger().log(Level.FINE, "Latency to " + _addr + " actual=" + newPingMS + " smoothed=" + _pingTimeMS);
    
                    successfullyContacted = true;
    
                    if (res == null) {
                        throw new MongoInternalException("Invalid null value returned from isMaster");
                    }
    
                    if (!_ok) {
                        getLogger().log(Level.INFO, "Server seen up: " + _addr);
                    }
                    _ok = true;
    
                    // max size was added in 1.8
                    if (res.containsField("maxBsonObjectSize")) {
                        _maxBsonObjectSize = (Integer) res.get("maxBsonObjectSize");
                    } else {
                        _maxBsonObjectSize = Bytes.MAX_OBJECT_SIZE;
                    }
                } catch (Exception e) {
                    if (!((_ok) ? true : (Math.random() > 0.1))) {
                        return res;
                    }
    
                    final StringBuilder logError = (new StringBuilder("Server seen down: ")).append(_addr);
    
                    if (e instanceof IOException) {
    
                        logError.append(" - ").append(IOException.class.getName());
    
                        if (e.getMessage() != null) {
                            logError.append(" - message: ").append(e.getMessage());
                        }
    
                        getLogger().log(Level.WARNING, logError.toString());
    
                    } else {
                        getLogger().log(Level.WARNING, logError.toString(), e);
                    }
                    _ok = false;
                }
    
                return res;
            }

    https://github.com/mongodb/mongo-java-driver/blob/master/src/main/com/mongodb/ConnectionStatus.java

    Незаметен.

    serpinski, 31 Мая 2013

    Комментарии (7)
  6. Objective C / Говнокод #13082

    −105

    1. 1
    if(ignoreSelection?[atml extraCharges]!=NULL:[atml extraCharges]&&![atml selectedAttribute])

    Лесенки для слабаков!!

    Psionic, 31 Мая 2013

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

    +155

    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
    if (!$left || !$right) return true;
            $sql = "DELETE FROM {$this->_tableName} WHERE `user_id`=$user_id";
            $this->_db->exec($sql);
    
            if (!$this->_isTriggers) {
                if (($right - $left) == 1) {
                    $sql = "UPDATE {$this->_tableName} SET `left`=IF(`left` >= $left,`left`-2,`left`),`right`=`right`-2 WHERE `right` >= $left";
                } else {
                    $sql = "UPDATE {$this->_tableName} SET 
                    `left`=IF(`left` BETWEEN $left AND $right,`left`-1,`left`),
                    `right`=IF(`right` BETWEEN $left AND $right,`right`-1,`right`),
                    `level`=IF(`left` BETWEEN $left AND $right,`level`-1,`level`),
                    `left`=IF(`left`>$right,`left`-2,`left`),
                    `right`=IF(`right`>$right,`right`-2,`right`)
    		WHERE `right` > $left
                    ";
                }
                $this->_db->exec($sql);

    Только ручной сбор запроса. Zend Db

    coderxlsn, 30 Мая 2013

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

    −108

    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
    - (void) fixUIAfterRotation: (UIInterfaceOrientation) interfaceOrientation
    {
    	[self.view setBackgroundColor:[UIColor colorWithPatternImage:[UIImage imageNamed:UIInterfaceOrientationIsPortrait(interfaceOrientation)? @"bg_new.png":@"bg_new_90.png"]]];
      	NSString *path = [[NSBundle mainBundle] bundlePath];
    	NSURL *baseURL = [NSURL fileURLWithPath:path];
    	NSString *htmlStr;
    	webError = NO;
        orient = UIInterfaceOrientationIsPortrait(interfaceOrientation)? 1:2;
        float width_ = [[UIScreen mainScreen] bounds].size.height;
        viewNews.frame = isRotation? (UIInterfaceOrientationIsPortrait(interfaceOrientation)? 
               CGRectMake(0, 0, width_, 240):CGRectMake(0, 0, width_, width_ - 90)):(UIInterfaceOrientationIsPortrait(interfaceOrientation)? CGRectMake(0, 0, 320, width_ - 81):CGRectMake(0, 0, width_, 240));
        isRotation = isRotation? NO:isRotation;
        
    #if defined(PRO_PROJECT)    
     	if (UIInterfaceOrientationIsPortrait(interfaceOrientation))
    	{
    		htmlStr = [NSString stringWithFormat:@"<!DOCTYPE html PUBLIC \"-//W3C//DTD XHTML 1.0 Transitional//EN\" 
                              \"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd\"><html xmlns=\"http://www.w3.org/1999/xhtml\">
                               <head><meta http-equiv=\"Content-Type\" content=\"text/html; charset=utf-8\" /><title>Untitled Document</title>
                               <style>body {margin:0px; padding:0px; font:13px arial; background:none;}
                               a {text-decoration:underline; color:#fbcf04; font-weight:bold; !important;} a:hover {text-decoration:none;}
                               .title{background:#575757 left top repeat-x; font:bold 15px Arial; color:#FFF; padding:14px 30px 0px 0px; height:31px; 
                               border-bottom:1px solid #000000; line-height:14px}.titleIm{background:#575757 left top repeat-x; padding:13px 8px 13px 13px; height:31px; 
                               border-bottom:1px solid #000000;}.news_body {border-top:1px solid #414141; padding:10px 14px 14px 14px; 
                               color:#FFF; line-height:19px; background:#3d3d3d;}.news_body p {padding-top:0px;}</style></head>
                              <body><table cellpadding=\"0\" cellspacing=\"0\" border=\"0\" width=\"320\" height=\"388\"><tr><td width=\"75\" valign=\"top\" class=\"titleIm\">
                              <img src=%@ height=\"70\" width=\"70\"></td><td valign=\"top\" class=\"title\">%@ 
                              <div style=\"font:11px Arial; color:#858585; line-height:18px;\">%@</div></td></tr><tr>
                              <td colspan=\"2\" valign=\"top\" class=\"news_body\">%@</td></tr></table></body></html>",
                               imageName, [newsDescription objectForKey:@"titleNews"], 
                               [CORENewsTitleList getDataString:[newsDescription objectForKey:@"dateNews"]], 
                               [newsDescription objectForKey:@"discriptionNews"]];
    	}
    	else
    	{
    		htmlStr = [NSString stringWithFormat:@"<!DOCTYPE html PUBLIC \"-//W3C//DTD XHTML 1.0 Transitional//EN\" 
                              \"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd\"><html xmlns=\"http://www.w3.org/1999/xhtml\">
                             <head><meta http-equiv=\"Content-Type\" content=\"text/html; charset=utf-8\" /><title>Untitled Document</title>
                             <style>body {margin:0px; padding:0px; font:13px arial; background:none;}
                             a {text-decoration:underline; color:#fbcf04; font-weight:bold; !important;}a:hover {text-decoration:none;}
                             .title {background:#575757 left top repeat-x; font:bold 15px Arial; color:#FFF; padding:14px 30px 0px 0px; height:31px; 
                              border-bottom:1px solid #000000; line-height:14px}.titleIm {background:#575757 left top repeat-x; padding:13px 8px 13px 13px; height:31px; 
                              border-bottom:1px solid #000000;}.news_body {border-top:1px solid #414141; padding:10px 14px 14px 14px; 
                              color:#FFF; line-height:19px; background:#3d3d3d;}.news_body p {padding-top:0px;}</style></head>
                              <body><table cellpadding=\"0\" cellspacing=\"0\" border=\"0\" width=\"%f\" height=\"240\"><tr><td width=\"75\" valign=\"top\" class=\"titleIm\">
                              <img src=%@ height=\"70\" width=\"70\"></td><td valign=\"top\" class=\"title\">%@ 
                              <div style=\"font:11px Arial; color:#858585; line-height:18px;\">%@</div></td></tr><tr>
                              <td colspan=\"2\" valign=\"top\" class=\"news_body\">%@</td></tr></table></body></html>",
                              width_, imageName, [newsDescription objectForKey:@"titleNews"], 
                              [CORENewsTitleList getDataString:[newsDescription objectForKey:@"dateNews"]], 
                              [newsDescription objectForKey:@"discriptionNews"]];
    	}
    #else
        if (UIInterfaceOrientationIsPortrait(interfaceOrientation))
    	{
                    // тот же упоротый код, что и выше, за исключением цветов для бэкграунда и надписей.
            }
    	else
    	{
                    // тот же упоротый код, что и выше, за исключением цветов для бэкграунда и надписей.
    	}
    #endif
    	[viewNews loadHTMLString:htmlStr baseURL:baseURL];
    }

    Поворачиваем вебвью во вью-контроллере, который может использоваться в 2 проектах, имеющих различные темы (отличается бэкграунд и цвет надписей).

    QuickNick, 30 Мая 2013

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

    +150

    1. 1
    2. 2
    3. 3
    4. 4
    5. 5
    6. 6
    7. 7
    8. 8
    if (isset($_trade) && $_trade == 'wholesale') {
    	header('Location: /market/order/');
    	exit;
    }
    else {
    	header('Location: /market/order/');
    	exit;
    }

    Нашел в коде магазина

    Tek, 30 Мая 2013

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

    +136

    1. 1
    2. 2
    3. 3
    4. 4
    5. 5
    6. 6
    7. 7
    8. 8
    9. 9
    public static bool isLaterThan()
    {
      string hd = DateTime.Now.ToString("tt", new CultureInfo("en-US")).ToLower();
    
      if (hd == "pm")
       return false;
    
       return DateTime.Now.Hour < 1;
    }

    уже есть час ночи?

    taburetka, 30 Мая 2013

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