1. Си / Говнокод #6306

    +136

    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
    [...]
    	switch (dssdev->type) {
    #ifdef CONFIG_OMAP2_DSS_DPI
    	case OMAP_DISPLAY_TYPE_DPI:
    #endif
    #ifdef CONFIG_OMAP2_DSS_RFBI
    	case OMAP_DISPLAY_TYPE_DBI:
    #endif
    #ifdef CONFIG_OMAP2_DSS_SDI
    	case OMAP_DISPLAY_TYPE_SDI:
    #endif
    #ifdef CONFIG_OMAP2_DSS_DSI
    	case OMAP_DISPLAY_TYPE_DSI:
    #endif
    #ifdef CONFIG_OMAP2_DSS_VENC
    	case OMAP_DISPLAY_TYPE_VENC:
    #endif
    #ifdef CONFIG_OMAP2_DSS_HDMI
    	case OMAP_DISPLAY_TYPE_HDMI:
    #endif
    		break;
    	default:
    		DSSERR("Support for display '%s' not compiled in.\n",
    				dssdev->name);
    		return;
    	}
    
    	switch (dssdev->type) {
    #ifdef CONFIG_OMAP2_DSS_DPI
    	case OMAP_DISPLAY_TYPE_DPI:
    		r = dpi_init_display(dssdev);
    		break;
    #endif
    #ifdef CONFIG_OMAP2_DSS_RFBI
    	case OMAP_DISPLAY_TYPE_DBI:
    		r = rfbi_init_display(dssdev);
    		break;
    #endif
    #ifdef CONFIG_OMAP2_DSS_VENC
    	case OMAP_DISPLAY_TYPE_VENC:
    		r = venc_init_display(dssdev);
    		break;
    #endif
    #ifdef CONFIG_OMAP2_DSS_SDI
    	case OMAP_DISPLAY_TYPE_SDI:
    		r = sdi_init_display(dssdev);
    		break;
    #endif
    #ifdef CONFIG_OMAP2_DSS_DSI
    	case OMAP_DISPLAY_TYPE_DSI:
    		r = dsi_init_display(dssdev);
    		break;
    #endif
    #ifdef CONFIG_OMAP2_DSS_HDMI
    	case OMAP_DISPLAY_TYPE_HDMI:
    		r = hdmi_init_display(dssdev);
    		break;
    #endif
    	default:
    		BUG();
    	}
    
    	if (r) {
    		DSSERR("failed to init display %s\n", dssdev->name);
    		return;
    	}
    
    [...]

    linux kernel..
    Драйвер контроллера дисплея (drivers/video/omap2/dss/display.c).
    Про кошмар из #ifndef-ов молчу, но к чему первый switch?

    grub670, 11 Апреля 2011

    Комментарии (11)
  2. Pascal / Говнокод #6305

    +110

    1. 1
    2. 2
    3. 3
    4. 4
    5. 5
    6. 6
    7. 7
    8. 8
    DirName:=OpenDialog1.FileName;
        i:=Length(Dirname);
        While (i>0) and(Dirname[i]<>'\') do
        begin
          i:=i-1;
        end;
        If Dirname[i]='\' then Dirname:=Copy(Dirname,1,i-1);
        Edit1.Text:=DirName;

    Для определения директории, выбирается в ней файл, абсолютный путь к которому вырезается до первого найденного слеша

    replay, 10 Апреля 2011

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

    +159

    1. 1
    2. 2
    3. 3
    4. 4
    5. 5
    6. 6
    7. 7
    for($j = 0, $k = count($cats[$i][TREE_CHILD_ID]); $j < $k; $j++){
    	$child_id = SafeDB($cats[$i][TREE_CHILD_ID][$j]['id'], 11, int);
    	$child_counters = $this->GetCountersRecursive($child_id);
    	$link = 'index.php?name='.$this->moduleName.'&'.$this->id_par_name.'='.$child_id;
    	$sub .= '<a href="'.$link.'">'.$cats[$i][TREE_CHILD_ID][$j]['title'].'</a>'.' ('.$child_counters['files'].'), ';
    }
    $childs .= substr($sub, 0, strlen($sub) - 7).'.';

    Из одной русской CMS. Вывод списка категорий через разделитель. Аффтар не знал про implode.

    Мартин, 10 Апреля 2011

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

    +165

    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
    function securityMode(c_f)                                                                                                                                   
    {                                                                                                                                                            
            var security_mode;
    
            changed = c_f;
    
            hideWep();
    
            document.getElementById("div_security_shared_mode").style.visibility = "hidden";
            document.getElementById("div_security_shared_mode").style.display = "none";
            document.getElementById("div_wpa").style.visibility = "hidden";
            document.getElementById("div_wpa").style.display = "none";
            document.getElementById("div_wpa_algorithms").style.visibility = "hidden";
            document.getElementById("div_wpa_algorithms").style.display = "none";
            document.getElementById("wpa_passphrase").style.visibility = "hidden";
            document.getElementById("wpa_passphrase").style.display = "none";
            document.getElementById("wpa_key_renewal_interval").style.visibility = "hidden";
            document.getElementById("wpa_key_renewal_interval").style.display = "none";
            document.getElementById("wpa_PMK_Cache_Period").style.visibility = "hidden";
            document.getElementById("wpa_PMK_Cache_Period").style.display = "none";
            document.getElementById("wpa_preAuthentication").style.visibility = "hidden";
            document.getElementById("wpa_preAuthentication").style.display = "none";
            document.security_form.cipher[0].disabled = true;
            document.security_form.cipher[1].disabled = true;
            document.security_form.cipher[2].disabled = true;
    
            // etc...                                                                                                                                                           
    }

    Китайский говнокод, который пока даже страшно рефакторить.

    SadKo, 10 Апреля 2011

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

    +162

    1. 1
    2. 2
    3. 3
    4. 4
    5. 5
    6. 6
    7. 7
    function db_date_time($time = null) {
    	if (is_null($time)) {
    		$time = time();
    	}
    	$s = explode('.', date("d.m.Y.H.i.s", $time));
    	return $s[2] . '-' . $s[1] . '-' . $s[0] . ' ' . $s[3] . ':' . $s[4] . ':' . $s[5];
    }

    Silentium, 10 Апреля 2011

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

    +116

    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
    // Установка обработкчиков событий
                tbTitle.TextChanged += (x, y) => _target.Title = tbTitle.Text;
                cbContractorType.SelectedIndexChanged += (x, y) => _target.ContractorType = cbContractorType.SelectedIndex;
                tbFullTitle.TextChanged += (x, y) => _target.Title = tbFullTitle.Text;
                tbINN.TextChanged += (x, y) => _target.INN = tbINN.Text;
                // Для физ. лица
                dtpBirthDate.ValueChanged += (x, y) => _target.birthDate = dtpBirthDate.Value;
                tbPassportSeria.TextChanged += (x, y) => _target.PassportSeria = tbPassportSeria.Text;
                tbPassportNumber.TextChanged += (x, y) => _target.PassportNumber = tbPassportNumber.Text;
                dtpPassportDateRegistred.ValueChanged += (x, y) => _target.PassportDateRegistred = dtpPassportDateRegistred.Value;
                tbPassportOrganizationRegistred.TextChanged += (x, y) => _target.PassportOrganizationRegistred = tbPassportOrganizationRegistred.Text;
                tbRegistredPassportAddress.TextChanged += (x, y) => _target.RegistredPassportAddress = tbRegistredPassportAddress.Text;
                // Для юр лица
                tbOgranizationJuridicalAddress.TextChanged += (x ,y) => _target.OgranizationJuridicalAddress = tbRegistredPassportAddress.Text;
                tbOrganizationMainBankAcouuntNumber.TextChanged += (x, y) => _target.OrganizationMainBankAcouuntNumber = tbOrganizationMainBankAcouuntNumber.Text;
                tbOrganizationKPP.TextChanged += (x, y) => _target.OrganizationKPP = tbOrganizationKPP.Text;
                tbOrganizationOGRNIP.TextChanged += (x, y) => _target.OrganizationOGRNIP = tbOrganizationOGRNIP.Text;
                tbOrganizationIFNS.TextChanged += (x, y) => _target.OrganizationIFNS = tbOrganizationIFNS.Text;
                tbOrganizationOKATO.TextChanged += (x, y) => _target.OrganizationOKATO = tbOrganizationOKATO.Text;
                tbOrganizationOKPO.TextChanged += (x, y) => _target.OrganizationOKPO = tbOrganizationOKPO.Text;

    У меня денюха поэтому решил отмаппить форму по новому

    glilya, 10 Апреля 2011

    Комментарии (11)
  7. Куча / Говнокод #6300

    +137

    1. 1
    <a id="top_home_link" class="top_home_link fl_l" href="/" onclick="return nav.go(this, event)" class="fl_l" style=""></a>

    Duplicate attribute class.
    Простите за контактик, не удержался.

    nsauk, 10 Апреля 2011

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

    +176

    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
    $navChain=array();
       for($i = 0; $i < count($menu); $i++){
    		if (is_array($menu[$i]['subMenu'])) {
    			for($j = 0; $j < count($menu[$i]['subMenu']); $j++){
    				if (is_array($menu[$i]['subMenu'][$j]['subMenu'])) {
    					for($k = 0; $k < count($menu[$i]['subMenu'][$j]['subMenu']); $k++){
    						if (is_array($menu[$i]['subMenu'][$j]['subMenu'][$k]['subMenu'])) {
    							for($l = 0; $l < count($menu[$i]['subMenu'][$j]['subMenu'][$k]['subMenu']); $l++){
    								if (is_array($menu[$i]['subMenu'][$j]['subMenu'][$k]['subMenu'][$l]['subMenu'])) {
    									for($m = 0; $m < count($menu[$i]['subMenu'][$j]['subMenu'][$k]['subMenu'][$l]['subMenu']);$m++){
    										if ($menu[$i]['subMenu'][$j]['subMenu'][$k]['subMenu'][$l]['subMenu'][$m]['selected']=='1') {
    											$navChain[]=$menu[$i]['subMenu'][$j]['subMenu'][$k]['subMenu'][$l]['subMenu'][$m];
    											$menu[$i]['subMenu'][$j]['subMenu'][$k]['subMenu'][$l]['selected']=1;
    											$navChain[]=$menu[$i]['subMenu'][$j]['subMenu'][$k]['subMenu'][$l];
    											$menu[$i]['subMenu'][$j]['subMenu'][$k]['selected']=1;
    											$navChain[]=$menu[$i]['subMenu'][$j]['subMenu'][$k];
    											$menu[$i]['subMenu'][$j]['selected']=1;
    											$navChain[]=$menu[$i]['subMenu'][$j];
    											$menu[$i]['selected']=1;
    											$navChain[]=$menu[$i];
    										}
    									} // for
    								}
    								if ($menu[$i]['subMenu'][$j]['subMenu'][$k]['subMenu'][$l]['selected']=='1') {
    									$navChain[]=$menu[$i]['subMenu'][$j]['subMenu'][$k]['subMenu'][$l];
    									$menu[$i]['subMenu'][$j]['subMenu'][$k]['selected']=1;
    									$navChain[]=$menu[$i]['subMenu'][$j]['subMenu'][$k];
    									$menu[$i]['subMenu'][$j]['selected']=1;
    									$navChain[]=$menu[$i]['subMenu'][$j];
    									$menu[$i]['selected']=1;
    									$navChain[]=$menu[$i];
    								}
    							} // for
    						}
    						if ($menu[$i]['subMenu'][$j]['subMenu'][$k]['selected']=='1') {
    						$navChain[]=$menu[$i]['subMenu'][$j]['subMenu'][$k];
    							$menu[$i]['subMenu'][$j]['selected']=1;
    							$navChain[]=$menu[$i]['subMenu'][$j];
    							$menu[$i]['selected']=1;
    							$navChain[]=$menu[$i];
    						}
    					} // for
    				}
    				if ($menu[$i]['subMenu'][$j]['selected']=='1') {
    					$navChain[]=$menu[$i]['subMenu'][$j];
    					$menu[$i]['selected']=1;
    					$navChain[]=$menu[$i];
    				}
    			} // for
    		}
    		if ($menu[$i][selected] && empty($navChain)) {
    			$navChain[]=$menu[$i];
    		}
    	} // for

    volatile, 09 Апреля 2011

    Комментарии (28)
  9. Python / Говнокод #6298

    −179

    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
    class Student(models.Model):
        fio = models.CharField(max_length=100)
        birthday = models.DateField()
        stud_tick = models.IntegerField()
        group = models.ForeignKey("Group")
        starosta = models.BooleanField()
     
        class Meta:
              unique_together = (("group", "starosta"),)
     
     
    class Group(models.Model):
        name = models.CharField(max_length=20)
     
    admin.site.register(Student)
    admin.site.register(Group)

    qbasic, 09 Апреля 2011

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

    +127

    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
    if (accNum > 0 && accNum < accModels.Count){
                switch (accNum)
                {
                    case 1: accModels[0].WorldMatrix = Matrix.CreateScale(0.7f) * Matrix.CreateRotationX(0.3f) * Matrix.CreateRotationY(chrYaw + MathHelper.Pi) * Matrix.CreateTranslation(plPos + Vector3.Up * 9.0f + Vector3.Transform(Vector3.Backward * 2.0f, Matrix.CreateRotationY(chrYaw + MathHelper.Pi))); break;
                    case 2: accModels[1].WorldMatrix = Matrix.CreateScale(0.5f) * Matrix.CreateRotationY(chrYaw + MathHelper.PiOver2) * Matrix.CreateTranslation(plPos + Vector3.Up * 11.0f + Vector3.Transform(Vector3.Backward + Vector3.Right * 3.0f, Matrix.CreateRotationY(chrYaw + MathHelper.PiOver2))); break;
                    case 3: accModels[2].WorldMatrix = Matrix.CreateScale(0.5f) * Matrix.CreateRotationY(chrYaw + MathHelper.PiOver2) * Matrix.CreateTranslation(plPos + Vector3.Up * 11.0f + Vector3.Transform(Vector3.Backward + Vector3.Right * 3.0f, Matrix.CreateRotationY(chrYaw + MathHelper.PiOver2))); break;
    
                    case 4: accModels[3].WorldMatrix = Matrix.CreateScale(0.5f) * Matrix.CreateRotationY(chrYaw - MathHelper.PiOver2) * Matrix.CreateTranslation(plPos + Vector3.Up * 5.0f + Vector3.Transform(Vector3.Backward * 0.0f + Vector3.Right * 0.7f, Matrix.CreateRotationY(chrYaw + MathHelper.PiOver2))); break;
                    case 5: accModels[4].WorldMatrix = Matrix.CreateScale(0.55f) * Matrix.CreateRotationZ(0.3f) * Matrix.CreateRotationY(chrYaw - MathHelper.PiOver2) * Matrix.CreateTranslation(plPos + Vector3.Up * 5.0f + Vector3.Transform(Vector3.Backward * 0.0f + Vector3.Right * 0.7f, Matrix.CreateRotationY(chrYaw + MathHelper.PiOver2))); break;
                    case 6: accModels[5].WorldMatrix = Matrix.CreateScale(0.5f) * Matrix.CreateRotationY(chrYaw - MathHelper.PiOver2) * Matrix.CreateTranslation(plPos + Vector3.Up * 18.0f + Vector3.Transform(Vector3.Right * -0.4f, Matrix.CreateRotationY(chrYaw - MathHelper.PiOver2))); break;
                    <...>
                   case 11: accModels[10].WorldMatrix = Matrix.CreateScale(1.2f) * Matrix.CreateRotationX(-0.3f) * Matrix.CreateRotationY(chrYaw) * Matrix.CreateTranslation(plPos + Vector3.Up * 8.5f + Vector3.Transform(Vector3.Backward * 1.4f, Matrix.CreateRotationY(chrYaw + MathHelper.Pi))); break;
                    case 12: accModels[11].WorldMatrix = Matrix.CreateScale(1.0f) * Matrix.CreateRotationX(0.3f) * Matrix.CreateRotationY(chrYaw + MathHelper.Pi) * Matrix.CreateTranslation(plPos + Vector3.Up * 9.0f + Vector3.Transform(Vector3.Backward * 2.0f, Matrix.CreateRotationY(chrYaw + MathHelper.Pi))); break;
                    case 13: accModels[12].WorldMatrix = Matrix.CreateScale(1.0f) * Matrix.CreateRotationY(chrYaw - MathHelper.PiOver2) * Matrix.CreateTranslation(plPos + Vector3.Up * -1.0f + Vector3.Transform(Vector3.Backward * 2.0f, Matrix.CreateRotationY(chrYaw + MathHelper.Pi))); break;
                    case 14: accModels[13].WorldMatrix = Matrix.CreateScale(1.0f) * Matrix.CreateRotationZ(-0.3f) * Matrix.CreateRotationY(chrYaw + MathHelper.PiOver2) * Matrix.CreateTranslation(plPos + Vector3.Up * 4.0f + Vector3.Transform(Vector3.Backward * 1.3f, Matrix.CreateRotationY(chrYaw + MathHelper.Pi))); break;
    
                    case 15: accModels[14].WorldMatrix = Matrix.CreateScale(0.4f) * Matrix.CreateRotationY(chrYaw) * Matrix.CreateTranslation(plPos + Vector3.Up * 22.0f + Vector3.Transform(Vector3.Right * 1.3f + Vector3.Backward * 3.8f, Matrix.CreateRotationY(chrYaw + MathHelper.Pi))); break;
    
                    default: accModels[accNum - 1].WorldMatrix = Matrix.CreateScale(0.7f) * Matrix.CreateRotationX(0.3f) * Matrix.CreateRotationY(chrYaw + MathHelper.Pi) * Matrix.CreateTranslation(plPos + Vector3.Up * 9.0f + Vector3.Transform(Vector3.Backward * 1.3f, Matrix.CreateRotationY(chrYaw + MathHelper.Pi))); break;
    
                }
    }

    Ой как мне не хотелось это в XMLку выносить...

    RaZeR, 09 Апреля 2011

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