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

    +74

    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
    # Определение IP адреса
    	static public function ip() {
    		
    		# Список возможных заголовков для получения ip адреса
    		$Sip 					= array();
    		$Sip['REMOTE_ADDR'] 			= getenv('REMOTE_ADDR');
    		$Sip['HTTP_FORWARDED_FOR'] 		= getenv('HTTP_FORWARDED_FOR');
    		$Sip['HTTP_X_FORWARDED_FOR'] 	= getenv('HTTP_X_FORWARDED_FOR');
    		$Sip['HTTP_X_COMING_FROM'] 	= getenv('HTTP_X_COMING_FROM');
    		$Sip['HTTP_VIA'] 			= getenv('HTTP_VIA');
    		$Sip['HTTP_XROXY_CONNECTION'] 	= getenv('HTTP_XROXY_CONNECTION');
    		$Sip['HTTP_CLIENT_IP'] 			= getenv('HTTP_CLIENT_IP');
    		$Sip['Unknow'] 				= '0.0.0.0';
    		
    		# Выбор найденного ip адреса
    		if(isset($Sip['REMOTE_ADDR'])) {
    			$Rip = $Sip['REMOTE_ADDR'];
    		} else if(isset($Sip['HTTP_FORWARDED_FOR'])) {
    			$Rip = $Sip['HTTP_FORWARDED_FOR'];
    		} else if(isset($Sip['HTTP_X_FORWARDED_FOR'])) {
    			$Rip = $Sip['HTTP_X_FORWARDED_FOR'];
    		} else if(isset($Sip['HTTP_X_COMING_FROM'])) {
    			$Rip = $Sip['HTTP_X_COMING_FROM'];
    		} else if(isset($Sip['HTTP_VIA'])) {
    			$Rip = $Sip['HTTP_VIA'];
    		} else if(isset($Sip['HTTP_XROXY_CONNECTION'])) {
    			$Rip = $Sip['HTTP_XROXY_CONNECTION'];
    		} else if(isset($Sip['HTTP_CLIENT_IP'])) {
    			$Rip = $Sip['HTTP_CLIENT_IP'];
    		} else {
    			$Rip = '0.0.0.0';
    		}
    		
    		# Валидация ip адреса
    		# Получение из секций массив
    		$ARip = explode( '.', $Rip );
    		
    		# Пересборка ip адреса
    		$RARip = array(0 => NULL, 1 => NULL, 2 => NULL, 3 => NULL);
    		for($n = 0; $n < 10; $n++) {
    			$RARip[0] .= isset( $ARip[0]{$n} ) ? $ARip[0]{$n} : NULL;
    			$RARip[1] .= isset( $ARip[1]{$n} ) ? $ARip[1]{$n} : NULL;
    			$RARip[2] .= isset( $ARip[2]{$n} ) ? $ARip[2]{$n} : NULL;
    			$RARip[3] .= isset( $ARip[3]{$n} ) ? $ARip[3]{$n} : NULL;
    		}
    		$BRip = substr( (int) $RARip[0], 0, 3 ) . '.' . substr( (int) $RARip[1], 0, 3 ) . '.' . substr( (int) $RARip[2], 0, 3 ) . '.' . substr( (int) $RARip[3], 0, 3 );
    		
    		# Возвращение пересобранного ip адреса
    		return $BRip;
    	}

    Не столько — «Г», сколько — «Извращение»...
    Улыбнуло имя переменной — $Rip;
    А раньше этот код был суровее — exit( $string ); в случаи не соответствия...

    nethak, 22 Мая 2012

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

    +93

    1. 1
    2. 2
    3. 3
    4. 4
    5. 5
    6. 6
    for (int i = 0; i < wastePeriods.Length; i++)
        {
              wastePeriods = 0;
              docPeriods = 0;
              wastePeriodsYear = 0;
        }

    Диггеры-рефакторщики раскопали очередной оригинальный цикл.
    wastePeriods - массив с over300+ записями.
    docPeriods, wastePeriodsYear - тоже массивы

    UfoDriver, 22 Мая 2012

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

    +69

    1. 1
    2. 2
    3. 3
    4. 4
    function all_sorting(
        $ids, //!< Массив ID элемента в карте сайта
        $_POST //!< Значения сортировки элементов
    ) {

    Определение локальной переменной с именем суперглобального массива вызывает ошибку "Fatal error: Cannot re-assign auto-global variable _POST in" в PHP 5.4

    Lblss, 22 Мая 2012

    Комментарии (14)
  4. ActionScript / Говнокод #10343

    −146

    1. 01
    2. 02
    3. 03
    4. 04
    5. 05
    6. 06
    7. 07
    8. 08
    9. 09
    10. 10
    11. 11
    12. 12
    public function FooClass() {
    	if (!_isConstructing) throw new Error("Singleton, use FooClass.instance");
    }
    
    public static function get instance():FooClass {
    	if (_instance == null)  {
    		_isConstructing = true;
    		_instance = new FooClass();
    		_isConstructing = false;
    	}
    	return _instance;
    }

    Новое слово в создании синглтонов.

    kyzi007, 22 Мая 2012

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

    +96

    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
    string AutoWait;
    int AutoStop;
    
    /*...*/
    
    RegistryKey sKey = Registry.LocalMachine.OpenSubKey("Platform\\Settings"); 
    AutoStop=(int)Key.GetValue("AutoStop");
    
    if (AutoStop == 1) { AutoWait = "yes"; wait.Enabled = false; } else { AutoWait = "no"; }
    
    /*...*/
    
                    if ((km4<=2)&(onTheWay)&(AutoWait=="yes"))
                    {
                        Waiting=true;
                        label3.BackColor = Color.Red;
                        label4.BackColor = Color.Black;
                    }else
                    if ((km4 > 2) & (onTheWay))
    
    /*...*/

    Классика жанра - использование переменной String в качестве bool. Про ООП автор вообще не слышал, весь код оформлен одной большой портянкой с кучей повторений сброса/установки подобных "флажков".

    ybinzu, 22 Мая 2012

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

    +73

    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
    public static function ParseContainer($s,$be,$en,$cb,$ret_beg=false,$re=false)
    	{
    		if(!is_callable($cb))
    			return$s;
    		$bl=strlen($be);
    		$el=strlen($en);
    		for(;;)
    		{
    			if(false===$bp=strpos($s,$be) or false===$ep=strpos($s,$en,$bp+1+$bl))
    				break;
    			$brp=strrpos(substr($s,0,$ep-$bp+1),$be);
    			if($brp>$bp)
    				$bp=$brp;
    			$ns=substr($s,$bp+($ret_beg ? 0 : $bl),$ep-$bp-($ret_beg ? 0 : $bl)+($re ? $el : 0));
    			$ns=call_user_func($cb,$ns);
    			$s=substr_replace($s,$ns,$bp,$ep-$bp+$el);
    		}
    		return$s;
    	}

    T_ENGINE, 22 Мая 2012

    Комментарии (0)
  7. SQL / Говнокод #10340

    −116

    1. 1
    select cunt(*) from users

    Опечаточка по фрейду :)

    Nemoden, 22 Мая 2012

    Комментарии (30)
  8. Perl / Говнокод #10339

    −122

    1. 1
    2. 2
    3. 3
    4. 4
    5. 5
    6. 6
    my (@data) = $content =~ m#href="/show/\d+.*?">(.*?)</a>.*?(Ep: \d+).*?(at \d{2}:\d{2}).*?</small>#gsi;
    	
    for (my $i; $i < @data;){
    	$data .= $data [$i++].' '.$data [$i++].' '.$data [$i++];
    	$data .= "\n" unless $i == @data;
    }

    Распарсил.

    VictorVonSpok, 21 Мая 2012

    Комментарии (11)
  9. Java / Говнокод #10338

    +77

    1. 1
    2. 2
    3. 3
    4. 4
    5. 5
    if (eventInfo.getQuoteList().size() == 0) {
            lineInfo.getEventList().add(eventInfo);
    } else {
            lineInfo.getEventList().add(eventInfo);
    }

    Тебе никуда не деться от добавления!

    arbuzz, 21 Мая 2012

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

    −117

    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
    For t = 3 To u
     If Cells(t, 204).Text = " " Or Cells(t, 204).Text = "" Then
       If Cells(t + 1, 204).Text = " " Or Cells(t + 1, 204).Text = "" Then
        If Cells(t + 2, 204).Text = " " Or Cells(t + 2, 204).Text = "" Then
         If Cells(t + 3, 204).Text = " " Or Cells(t + 3, 204).Text = "" Then
         If Cells(t + 4, 204).Text = " " Or Cells(t + 4, 204).Text = "" Then
         If Cells(t + 5, 204).Text = " " Or Cells(t + 5, 204).Text = "" Then
         If Cells(t + 6, 204).Text = " " Or Cells(t + 6, 204).Text = "" Then
         If Cells(t + 7, 204).Text = " " Or Cells(t + 7, 204).Text = "" Then
         If Cells(t + 8, 204).Text = " " Or Cells(t + 8, 204).Text = "" Then
         If Cells(t + 9, 204).Text = " " Or Cells(t + 9, 204).Text = "" Then
         If Cells(t + 10, 204).Text = " " Or Cells(t + 10, 204).Text = "" Then
         If Cells(t + 11, 204).Text = " " Or Cells(t + 11, 204).Text = "" Then
         If Cells(t + 12, 204).Text = " " Or Cells(t + 12, 204).Text = "" Then
         If Cells(t + 13, 204).Text = " " Or Cells(t + 13, 204).Text = "" Then
         If Cells(t + 14, 204).Text = " " Or Cells(t + 14, 204).Text = "" Then
         If Cells(t + 15, 204).Text = " " Or Cells(t + 15, 204).Text = "" Then
         If Cells(t + 16, 204).Text = " " Or Cells(t + 16, 204).Text = "" Then
         If Cells(t + 17, 204).Text = " " Or Cells(t + 17, 204).Text = "" Then
         If Cells(t + 18, 204).Text = " " Or Cells(t + 18, 204).Text = "" Then
         If Cells(t + 19, 204).Text = " " Or Cells(t + 19, 204).Text = "" Then
         If Cells(t + 20, 204).Text = " " Or Cells(t + 20, 204).Text = "" Then
         If Cells(t + 21, 204).Text = " " Or Cells(t + 21, 204).Text = "" Then
         If Cells(t + 22, 204).Text = " " Or Cells(t + 22, 204).Text = "" Then
         If Cells(t + 23, 204).Text = " " Or Cells(t + 23, 204).Text = "" Then
         If Cells(t + 24, 204).Text = " " Or Cells(t + 24, 204).Text = "" Then
         If Cells(t + 25, 204).Text = " " Or Cells(t + 25, 204).Text = "" Then
         If Cells(t + 26, 204).Text = " " Or Cells(t + 26, 204).Text = "" Then
         If Cells(t + 27, 204).Text = " " Or Cells(t + 27, 204).Text = "" Then
         If Cells(t + 28, 204).Text = " " Or Cells(t + 28, 204).Text = "" Then
         If Cells(t + 29, 204).Text = " " Or Cells(t + 29, 204).Text = "" Then
         If Cells(t + 30, 204).Text = " " Or Cells(t + 30, 204).Text = "" Then
         If Cells(t + 31, 204).Text = " " Or Cells(t + 31, 204).Text = "" Then
         If Cells(t + 32, 204).Text = " " Or Cells(t + 32, 204).Text = "" Then
         If Cells(t + 33, 204).Text = " " Or Cells(t + 33, 204).Text = "" Then
         If Cells(t + 34, 204).Text = " " Or Cells(t + 34, 204).Text = "" Then
                  GoTo zan4:
              End If
            End If
          End If
        End If
         End If
         End If
            End If
          End If
        End If
         End If
         End If
            End If
          End If
        End If
         End If
         End If
            End If
          End If
        End If
         End If
         End If
            End If
          End If
        End If
         End If
         End If
            End If
          End If
        End If
         End If
         End If
            End If
          End If
        End If
         End If
    Next t
    zan4:

    Кусок реально используемого "проэкта", используется у нас на призводстве.
    И вот-такого штук 10 в коде.

    ноу коментс.

    adli__82, 21 Мая 2012

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