1. Objective C / Говнокод #13082

    −105

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

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

    Psionic, 31 Мая 2013

    Комментарии (4)
  2. 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)
  3. 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)
  4. 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)
  5. 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)
  6. C# / Говнокод #13074

    +129

    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
    public static MvcHtmlString TextWithLinks(this HtmlHelper helper, string inputStr)
    {
      string html = String.Empty;
      Uri url;
      string[] arr = inputStr.Split(' ');
      for (int i = 0; i < arr.Length; i++)
      {
        if (i != 0)
        {
          html += " ";
        }
        if (Uri.TryCreate(arr[i],UriKind.Absolute, out url))
        {
          html += String.Format("<a href='{0}' target='_blank'>{0}</a>", url.AbsoluteUri);
        }else
        {
          html += arr[i];
        }
      }
      return new MvcHtmlString(html);
    }

    DarkThinker, 30 Мая 2013

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

    +143

    1. 1
    2. 2
    3. 3
    4. 4
    5. 5
    6. 6
    $result_set = mysql_query("SELECT * FROM $db.$class_table WHERE class_id = ".$_POST["class_id"]." ORDER BY `class_name_short` ASC LIMIT 0 , 1;")
    		or die("Invalid query: " . mysql_error());
    		while ($row = mysql_fetch_array($result_set, MYSQL_ASSOC))
    		{
    			echo(json_encode($row));
    		}

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

    Daiver, 29 Мая 2013

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

    +14

    1. 1
    std::set_unexpected( [] () {} );

    Студия достала и не позволяла обрабатывать исключения, а они нужны были для демонстрации работы, в итоге навесил такой костыль и включил SEH исключения в параметрах компиляции.

    maksim_ovcharik, 29 Мая 2013

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

    +138

    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
    // Преобразует BCD формат в число
    private static int BCDToInt(byte bIn)
    {
        return ((((bIn / 0x10) * 10) + bIn) - ((bIn / 0x10) * 0x10));
    }
    
    // Преобразует число в BCD формат
    private static byte IntToBCD(int value)
    {
        value -= (value / 100) * 100;
        byte bTH = (byte)(value / 10);
        byte bTL = (byte)(value - (bTH * 10));
        return (byte)(bTL + ((byte)(bTH << 4)));
    }

    навеяло сложными запутывающими большими и маленькими индейцами для элитных программистов

    референс-код от партнеров для конверсии binary-coded decimal вперёд и взад
    чтобы как бы верно срослось между ихним с# и нашим сраным с++

    defecate-plusplus, 29 Мая 2013

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

    +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
    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
    bool getSelectedFile(wchar_t *out, bool skip) {
    	HWND hwndFind = GetForegroundWindow();
    
    	TCHAR g_szPath[BUF_SIZE];
    	TCHAR g_szItem[BUF_SIZE];
    	//g_szPath[0] = TEXT('\0');
    	//g_szItem[0] = TEXT('\0');
    	memset(g_szPath, 0, sizeof(TCHAR) * BUF_SIZE);
    	memset(g_szItem, 0, sizeof(TCHAR) * BUF_SIZE);
    
    	IShellWindows *psw;
    	if(CoCreateInstance(CLSID_ShellWindows, NULL, CLSCTX_ALL, IID_IShellWindows, (void**)&psw) != S_OK) return false;
    	
    	VARIANT v;
    	v.vt = VT_I4;
    	IDispatch  *pdisp;
    	bool fFound = false;
    	bool pExtracted = false;
    	bool nExtracted = false;
    	
    	for (V_I4(&v) = 0; !fFound && psw->Item(v, &pdisp) == S_OK; V_I4(&v)++) {
    			IWebBrowserApp *pwba;
    			if(SUCCEEDED(pdisp->QueryInterface(IID_IWebBrowserApp, (void**)&pwba))) {
    				HWND hwndWBA;
    				if (SUCCEEDED(pwba->get_HWND((LONG_PTR*)&hwndWBA)) && hwndWBA == hwndFind) {
    					fFound = true;
    					IServiceProvider *psp;
    					if(SUCCEEDED(pwba->QueryInterface(IID_IServiceProvider, (void**)&psp))) {
    						IShellBrowser *psb;
    						if(SUCCEEDED(psp->QueryService(SID_STopLevelBrowser, IID_IShellBrowser, (void**)&psb))) {
    							IShellView *psv;
    							if(SUCCEEDED(psb->QueryActiveShellView(&psv))) {
    								IFolderView *pfv;
    								if(SUCCEEDED(psv->QueryInterface(IID_IFolderView, (void**)&pfv))) {
    									IPersistFolder2 *ppf2;
    									if(SUCCEEDED(pfv->GetFolder(IID_IPersistFolder2, (void**)&ppf2))) {
    										LPITEMIDLIST pidlFolder;
    										if(SUCCEEDED(ppf2->GetCurFolder(&pidlFolder))) {
    											if(SHGetPathFromIDList(pidlFolder, g_szPath)) {
    												pExtracted = true;
    												if(skip) {
    													lstrcpy(out, g_szPath);
    													out[lstrlen(g_szPath)] = 0;
    													return true;
    												}
    											}
    											int iFocus;
    											if(SUCCEEDED(pfv->GetFocusedItem(&iFocus))) {
    												LPITEMIDLIST pidlItem;
    												if (SUCCEEDED(pfv->Item(iFocus, &pidlItem))) {
    													IShellFolder *psf;
    													if (SUCCEEDED(ppf2->QueryInterface(IID_IShellFolder, (void**)&psf))) {
    														STRRET str;
    														if(SUCCEEDED(psf->GetDisplayNameOf(pidlItem, SHGDN_INFOLDER, &str))) {
    															StrRetToBuf(&str, pidlItem, g_szItem, 1024);
    															nExtracted = true;
    															int psz = lstrlen(g_szPath);
    															int isz = lstrlen(g_szItem);
    															if(pExtracted) {
    																lstrcpy(out, g_szPath);
    																out[psz] = '\\';
    															}
    															lstrcpy(out+psz+1, g_szItem);
    															out[psz + isz + 2] = 0;
    														}
    														psf->Release();
    													}
    													CoTaskMemFree(pidlItem);
    												}
    											}
    											CoTaskMemFree(pidlFolder);
    										}
    										ppf2->Release();
    									}
    									pfv->Release();
    								}
    								psv->Release();
    							}
    							psb->Release();
    						}
    						psp->Release();
    					}
    				}
    				pwba->Release();
    			}
    			pdisp->Release();
    	}
    	psw->Release();
    	return (pExtracted && nExtracted);
    }

    Две очаровательных (говно) лестницы из какой-то очередной переназначалки горячих клавиш в Windows.
    Оригинал тут: https://github.com/mapseamoff/KeyBinder/blob/master/ShellHelper/ShellHelper/main.cpp

    kovnogod, 29 Мая 2013

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