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

    +168

    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
    <?php
    	function isValidCharacters($str)
    	{
    		$str2 = preg_replace("[^a-zA-Zа-яА-Я[email protected]]","",$str);
    		if ($str != $str2) return FALSE;
    		return TRUE;
    	}
    	$nik=preg_replace("[^a-zA-Zа-яА-Я[email protected]]","",$_POST['nik']);
    	$pass=preg_replace("[^a-zA-Zа-яА-Я[email protected]]","",$_POST['pass']);
    	if (!isValidCharacters($nik) || !isValidCharacters($pass))
    	{
    		$_SESSION['auth']="error";
    		$_SESSION['error_mes']="Неверный логин или пароль";
    		header('Location: ./index.php');
    		exit();
    	}
    
    //дальше проверка на совпадение логина\пароля, ничего интересного.
    ?>

    Строка 10, после 8-9, типа "А вдруг?!"

    mr.The, 14 Сентября 2011

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

    +160

    1. 1
    2. 2
    3. 3
    4. 4
    5. 5
    6. 6
    7. 7
    8. 8
    function Hehe ($s) {
        $str = $s;
        $str = preg_replace ("/\\\/","", $str);
        $str = preg_replace ("/'/","&#39", $str);
        $str = preg_replace ("/\n/","<br>", $str);
        $str = preg_replace ("/\r/","", $str);
        return $str;
    }

    Название функции оригинальное. Лежала в модуле ~5k строк.

    Enjoy, 14 Сентября 2011

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

    +161

    1. 1
    2. 2
    3. 3
    4. 4
    5. 5
    $name = $data->fields["name"];             
    $name = str_replace("\n","",$name);
    $name = str_replace("\r","",$name);
    $name = str_replace("\\","\\\\",$name);
    $name = preg_replace("/'/","&#39",str_replace("\n","",str_replace("\"",""",$name)));

    2, 3 и 4 строчки похожи на серию ударов по мозгу, а последняя на кровавое комбо :)

    Enjoy, 14 Сентября 2011

    Комментарии (22)
  4. Java / Говнокод #7861

    +93

    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
    <%if(myaccount.getCountry().equals( "AF" )){%> <font color="grey"><label for="country">Afghanistan</label></font>
        	<%}else if(myaccount.getCountry().equals( "AL" )){%> <font color="grey"><label for="country">Albania</label></font>
        	<%}else if(myaccount.getCountry().equals( "DZ" )){%> <font color="grey"><label for="country">Algeria</label></font>
        	<%}else if(myaccount.getCountry().equals( "AS" )){%> <font color="grey"><label for="country">American Samoa</label></font>
        	<%}else if(myaccount.getCountry().equals( "AD" )){%> <font color="grey"><label for="country">Andorra</label></font>
        	<%}else if(myaccount.getCountry().equals( "AO" )){%> <font color="grey"><label for="country">Angola</label></font>
        	<%}else if(myaccount.getCountry().equals( "AI" )){%> <font color="grey"><label for="country">Anguilla</label></font>
        	<%}else if(myaccount.getCountry().equals( "AQ" )){%> <font color="grey"><label for="country">Antarctica</label></font>
        	<%}else if(myaccount.getCountry().equals( "AG" )){%> <font color="grey"><label for="country">Antigua and Barbuda</label></font>
        	<%}else if(myaccount.getCountry().equals( "AR" )){%> <font color="grey"><label for="country">Argentina</label></font>
        	<%}else if(myaccount.getCountry().equals( "AM" )){%> <font color="grey"><label for="country">Armenia</label></font>
        	<%}else if(myaccount.getCountry().equals( "AW" )){%> <font color="grey"><label for="country">Aruba</label></font>
        	<%}else if(myaccount.getCountry().equals( "AU" )){%> <font color="grey"><label for="country">Australia</label></font>
        	<%}else if(myaccount.getCountry().equals( "AT" )){%> <font color="grey"><label for="country">Austria</label></font>
        	<%}else if(myaccount.getCountry().equals( "AZ" )){%> <font color="grey"><label for="country">Azerbaijan</label></font>
        	<%}else if(myaccount.getCountry().equals( "BS" )){%> <font color="grey"><label for="country">Bahamas</label></font>
            <%}else if ...

    Индусская проверка принадлежности аккаунта к определённой стране...

    P.S. Всё не влезло - стран у нас много =)

    vetal, 14 Сентября 2011

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

    +40

    1. 1
    2. 2
    3. 3
    4. 4
    function del_reiting_type($typeid){
    	global $typeid;
    .....
    }

    как-то так...

    brainstorm, 14 Сентября 2011

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

    +168

    1. 01
    2. 02
    3. 03
    4. 04
    5. 05
    6. 06
    7. 07
    8. 08
    9. 09
    10. 10
    11. 11
    foreach ($_POST as $k=>$v)
            if (!is_array($v))
                    $_POST[$k] = htmlspecialchars($v);
            else
                    foreach ($v as $kk=>$vv)
                            if (!is_array($vv))
                                    $_POST[$k][$kk] = htmlspecialchars($vv);
                            else
                                    foreach ($vv as $kkk=>$vvv)
                                            if (!is_array($vvv))
                                                    $_POST[$k][$kk][$kkk] = htmlspecialchars($vvv);

    atarix12, 14 Сентября 2011

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

    +162

    1. 1
    2. 2
    3. 3
    4. 4
    5. 5
    void IniRead(UnicodeString Name, int n)
    {
    	TStringList* lst=new TStringList;
    	Ini->WriteString("CardNames","Card"+(UnicodeString)n,Name);
    }

    чувак создал переменную lst просто так, для теплоты душевной. ну хотелось ему чтоб создался stringlist!

    phys-tech, 14 Сентября 2011

    Комментарии (45)
  8. Ruby / Говнокод #7857

    −96

    1. 1
    2. 2
    3. 3
    4. 4
    5. 5
    6. 6
    <%products = Array.new
      count = Product.count(:conditions => "novelty = 'true'")
      while products.size < 10 do
        products << Product.find(:first, :conditions => "novelty = 'true'",:offset => rand(count))
        products.uniq!
      end-%>

    при количестве новинок меньше 10 получаем бесконечный цикл. счастье в продакшене, там sql запросы не пишутся в лог)

    malleus, 13 Сентября 2011

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

    +157

    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
    <?
    /**
     * @author i3ookMAn
     * @copyright 2011
     */
    
    $H = "&#072;";
    $e = "&#101;";
    $l = "&#108;";
    $o = "&#111;";
    $k = "&#044;";
    $w = "&#087;";
    $r = "&#114;";
    $d = "&#100;";
    $v = "&#033;";
    
    
    $kolat = "$H$e$l$l$o$k $w$o$r$l$d$v";
    
    $init = htmlentities($kolat);
    
    
    function unperekoder($string)
    {
    
        $string = preg_replace('~&#x([0-9a-f]+);~ei', 'chr(hexdec("\\1"))', $string);
        $string = preg_replace('~&#([0-9]+);~e', 'chr("\\1")', $string);
    
        $lolwto = get_html_translation_table(HTML_ENTITIES);
        $lolwto = array_flip($lolwto);
        return strtr($string, $lolwto);
    }
    
    $exit = unperekoder($init);
    
    echo $exit;
    
    ?>

    Выводит "Hello, World!" :D

    i3ookMAn, 13 Сентября 2011

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

    +964

    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
    using System;
    using System.Reflection;
    using System.Reflection.Emit;
    
    namespace DynUnloop
    { // Суммирование в цикле
      class SumLooping
      { public int Summ(int valMax)
        { int result = 0;
          for (int i = 0; i <= valMax; i++)
            result += i;
          return result;
        }
      }
    
      // Плоское суммирование
      class SumFlat
      { interface ISumCode
        { int ComputeSumm(int valMax);
        }
        void WriteCode(int valMax)
        { AssemblyName assemblyName = new AssemblyName();
          assemblyName.Name = "SumFlatAssembly";
    
          AssemblyBuilder assemblyBuilder = 
            AppDomain.CurrentDomain.DefineDynamicAssembly(
            assemblyName, AssemblyBuilderAccess.Run);
    
          ModuleBuilder moduleBuilder = 
            assemblyBuilder.DefineDynamicModule("SumFlatModule");
    
          TypeBuilder typeBuilder = 
            moduleBuilder.DefineType("SumFlatClass"
                        , TypeAttributes.Public);
    
          typeBuilder.AddInterfaceImplementation(typeof(ISumCode));
    
          /// Задаём возвращаемое зачение и параметр
          Type[] paramTypes = { typeof(int) };
          Type   returnType = typeof(int);
    
          MethodBuilder methodBuilder = 
            typeBuilder.DefineMethod("ComputeSumm"
              , MethodAttributes.Public 
              | MethodAttributes.Virtual
              , returnType, paramTypes);
    
          ILGenerator il = methodBuilder.GetILGenerator();
    
          // Генерируем плоский код.
          il.Emit(OpCodes.Ldc_I4, 0);
          for (int i = 1; i <= valMax; i++)
          { il.Emit(OpCodes.Ldc_I4, i);
            il.Emit(OpCodes.Add);
          }
          il.Emit(OpCodes.Ret);
    
          // Перекрываем метод ComputeSumm и создаём тип SumFlatClass.
          MethodInfo methodInfo = 
                     typeof(ISumCode).GetMethod("ComputeSumm");
          typeBuilder.DefineMethodOverride(methodBuilder, methodInfo);
          typeBuilder.CreateType();
    
          /// Код готов, создаём объект и берем его интерфейс.
          code = (ISumCode)assemblyBuilder.CreateInstance("SumFlatClass");
        }
    
        public int Summ(int val)
        { if (this.code == null)
            WriteCode(val);
          return this.code.ComputeSumm(val);
        }
    
        ISumCode code;
      }

    Оригинальный стиль кода и комментарии сохранёны. (с), или как там.
    В коде - разворачивание цикла в "плоский" IL код, который, как доказывается должен выигрывать по производительности.

    Elvenfighter, 13 Сентября 2011

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