1. Куча / Говнокод #7652

    +144

    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
    # /* [  <!-- */ include  <stdio.h> /*   \
      #{\
    `""""true \\#{"\n#"};           \
      \
    if [ -n "$ZSH_VERSION" ]; then           \
      \
      echo exec  echo I\'m a zsh script.; \
      \
    elif [ -n "$BASH_VERSION" ]; then        \
      \
      echo exec  echo I\'m a bash script.; \
    else  \
      echo exec  echo  I\'m  a sh  script.;    \
    fi`;  #\
    BEGIN{print"I'm a ", 0 ? "Ruby"  :"Perl",  " program.\n";  exit; } 
      #\
    %q~            
      
    set dummy =0; puts [list "I'm"  "a"  "tcl"  "script."]; exit   
      
    all: ; @echo "I'm a Makefile."          \
      #*/
    /*: */ enum {a, b};            \
      \
    static int c99(void) {         
      
    #ifndef __cplusplus /* bah */        
      
    unused1: if ((enum {b, a})0)          \
      (void)0;
    #endif           
      
    unused2:  return a;     \
    }  \
    static int trigraphs(void) {         \
      \
      return sizeof  "??!"  ==  2;    \
    }  \
    char X;               \
      \
    int main(void) {             \
      \
      struct X  {        \
      \
         char  a[2];    \
      };\
      if (sizeof(X)  !=  1) {       \
      \
    printf("I'm a C++ program (trigraphs %sabled).\n",         \
      \
       trigraphs()  ? "en"  : "dis");\
      \
    }else if (1//**/2
     
     
    )unused3 : { ; \
        printf("I'm a C program (C%s, trigraphs %sabled).\n", \
            c99() ? "89 with // comments" : "99", \
            trigraphs() ? "en" : "dis"); \
      } else { \
        printf("I'm a C program (C89, trigraphs %sabled).\n", \
            trigraphs() ? "en" : "dis"); \
      } \
      return 0; \
    } /*
    # \
    > main :: IO () -- -- \
    > main = putStr "I'm a Literate Haskell program.\n"
    # \
    ]>++++++++[<+++++++++>-]<+.>>++++[<++++++++++>-]<-.[-]>++++++++++ \
    [<+++++++++++>-]<-.>>++++[<++++++++>-]<.>>++++++++++[<++++++++++> \
    -]<- - -.<.>+.->>++++++++++[<+++++++++++>-]<++++.<.>>>++++++++++[ \
    <++++++++++>-]<+++++.<<<<+.->>>>- - -.<+++.- - -<++.- ->>>>>+++++ \
    +++++[<+++++++++++>-]<- - -.<<<<<.<+++.>>>.<<<-.- ->>>>+.<.<.<<.> \
    ++++++++++++++.[-]++++++++++"""`
    # \
    print "I'm a Python program."; """[-][--><html><head>
    <!--:--><title>I'm a HTML page</title></head><body>
    <!--:--><h1>I'm a <marquee><blink>horrible HTML</blink></marquee> page</h1>
    <!--:--><script language="JavaScript">
    <!--: # \
    setTimeout( // \
      function () { // \
       document.body.innerHTML = "<h1>I'm a javascript-generated HTML page</h1>"; // \
      }, 10000); // \
    //-->
    </script><!--: \
    </body></html><!-- } # \
    say "I'm a Perl6 program", try { " ($?PUGS_VERSION)" } // "", "."; # """ # */
    #define FOO ]-->~

    Может боян, конечно, но этот код реально компилится и работает на 15 разных языках программирования без изменений.
    Работает в C(x2), C++, Haskell, Ruby, Python, Perl(x2), HTML, tcl, bash, zsh, make, bash и brainfuck.

    auf1r2, 25 Августа 2011

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

    +147

    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
    $prim = mysql_result($result,$i,"prim");
    $gruz = mysql_result($result,$i,"gruz");
    $kuzov = mysql_result($result,$i,"kuzov");
    $o_strana = mysql_result($result,$i,"o_strana");
    $o_gorod = mysql_result($result,$i,"o_gorod");
    $k_strana = mysql_result($result,$i,"k_strana");
    $k_gorod = mysql_result($result,$i,"k_gorod");
    $stavka = mysql_result($result,$i,"stavka");
    $data = mysql_result($result,$i,"data");
    $m3 = mysql_result($result,$i,"m3");
    $ves = mysql_result($result,$i,"ves");
    $valuta = mysql_result($result,$i,"valuta");
    $firstname = mysql_result($result,$i,"firstname");
    $lastname = mysql_result($result,$i,"lastname");
    $middlename = mysql_result($result,$i,"middlename");
    $phone = mysql_result($result,$i,"phone");
    $cb_icq = mysql_result($result,$i,"cb_icq");
    $cb_skype = mysql_result($result,$i,"cb_skype");
    $cb_company = mysql_result($result,$i,"cb_company");
    $cb_org = mysql_result($result,$i,"cb_org");
    $cb_profession = mysql_result($result,$i,"cb_profession");

    пробуем сервер баз данных на выносливость...

    Sulik78, 25 Августа 2011

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

    +64

    1. 1
    2. 2
    3. 3
    4. 4
    boolean i = true;
      while (i){
       out.println("\n");
      }

    Нашлось в недрах работающей программы

    red_octopus, 25 Августа 2011

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

    +146

    1. 1
    2. 2
    3. 3
    4. 4
    #if LINUX_VERSION_CODE < KERNEL_VERSION(2,6,27)
     kill_proc(1,SIGTERM,1);
     #else
    ...

    Оригинальный способ проверить версию ядра линукса...
    Где-то в сырцах реалтековского драйвера для GPIO...

    Necromant, 25 Августа 2011

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

    +164

    1. 1
    2. 2
    3. 3
    FrmCabinetFound *frm = new FrmCabinetFound(index.data(Qt::UserRole).toInt());
        ((QMdiArea*)this->parent()->parent()->parent())->addSubWindow(frm);
        frm->show();

    des-1008d, 25 Августа 2011

    Комментарии (4)
  6. Pascal / Говнокод #7647

    +100

    1. 1
    2. 2
    3. 3
    4. 4
    case
       0: FilterList.Add('RCHECK = '+''''+'+'+'''');
       1: FilterList.Add('RCHECK = '+''''+'-'+'''');
    ...

    Автор кода жжот. Код реально работает. Но прочитать такое даже автор по прошествии года не сможет.

    Можно было проще
    0:FilterList.Add('RCHECK = ''+''');

    siqel, 25 Августа 2011

    Комментарии (7)
  7. JavaScript / Говнокод #7646

    +147

    1. 1
    var that = this;

    просто и со вкусом

    rk4n, 25 Августа 2011

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

    −104

    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
    def entities(model, params = {})
            @entities                 ||= {}
            @entities[model]    ||= []
    
            if @entities[model].blank? or parameters_changed?(model, params)
              @entities[model]  = []
              include           = params[:include]  || nil
              group             = params[:group]    || nil
              order             = params[:order]    || nil
              page              = params[:page]     || nil
              entity_ids        = []
              model_role        = nil
              model_class       = model.to_s.classify.constantize
    
              if self.has_role_for?(model_class)
                self.roles_for(model_class).uniq.each do |role|
                  if role.authorizable_id.blank?
                    raise "Authorization problem! Found more than one #{model_class} model permission!" unless model_role.blank?
                    model_role = role.name
                    next
                  end
    
                  if !role.authorizable_id.blank? && MerchantRole::MERCHANT_ROLES.include?(role.name)
                    entity_ids << role.authorizable.id
                  end
                end
    
                if entity_ids.blank? and MerchantRole::MERCHANT_ROLES.include?(model_role)
                  #WARNING! RECURSION! EVIL!
                  if MerchantRole.has_entity_parent?(model)
                    parent_model    = MerchantRole.entity_parent(model)
                    parent_entities = self.entities(parent_model)
                    unless parent_entities.blank?
                      _params = {
                        :conditions => conditions_and_parameters(params, nil, ["`#{model.to_s}`.`#{parent_model.to_s.singularize}_id` IN (?)", parent_entities.map(&:id)]),
                        :include => include,
                        :order => order,
                        :group => group
                      }
                      _params.merge!(:page => page) if params.keys.include?(:page)
                      if block_given?
                        (self.is_reseller? ? self.reseller.send(model) : model_class).each(_params) do |o|
                          yield o
                        end
                      else
                        @entities[model] = (self.is_reseller? ? self.reseller.send(model) : model_class).send(params.keys.include?(:page) ? :paginate : :find, :all, _params)
                      end
                    end
                  else
                    _params = {
                      :conditions => conditions_and_parameters(params, nil),
                      :include => include,
                      :order => order,
                      :group => group
                    }
                    _params.merge!(:page => page) if params.keys.include?(:page)
       
                    if block_given?    #Find only merchants associated with the reseller or all merchants if we are no reseller.
                      (self.is_reseller? ? self.reseller.send(model) : model_class).each(_params) do |o|
                        yield o
                      end
                    else
                      @entities[model] = (self.is_reseller? ? self.reseller.send(model) : model_class).send(params.keys.include?(:page) ? :paginate : :find, :all, _params)
                    end
                  end
                else
                  _params = { :conditions => conditions_and_parameters(params, nil, ["`#{model.to_s}`.`id` IN (?)", entity_ids]),
                                       :include => include,
                                       :order => order,
                                       :group => group }
                   _params.merge!(:page => page) if params.keys.include?(:page)
                   if block_given?
                     model_class.each(_params) do |o|
                       yield o
                     end
                   else
                     @entities[model] = model_class.send(params.keys.include?(:page) ? :paginate : :find, :all, _params)
                   end
                 end
               end
            end
         entities[@model]
       end

    This method does the following (you guessed it, right?):

    #Fetch entities for which we have a read permission.
    #This is now it should work:
    #1. : If we don't have any role on the model, we won't get anything.
    #2a.: Check roles we have for whole model. If no role for whole model we can only fetch instances we have assigned.
    #2b.: Check all instances we have a role for and store them.
    #3a.: We have roles for instances -> Goto(#7)
    #3b.: We have no instance roles but have a role for the whole model.
    #4. : Check recusively if we have roles fro a parent model (channels -> merchants).
    #5a.: If we have a parent role and got parent entities returned we only fetch instances belonging to the parent entities.
    #6a.: If we have a parent role and got no entities back, then we won't get anything since we are not supposed to.
    #7. : Get all instances based on our reseller or globally for the system.

    emilpetkov, 25 Августа 2011

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

    +174

    1. 1
    2. 2
    3. 3
    4. 4
    5. 5
    if ($_SESSION['free'] <= 0) {
         if ($_SESSION['free'] > 0) {
              $_SESSION['free'] --;
         }
    }

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

    webenter, 25 Августа 2011

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

    +76

    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
    if (s.contains("-"))
                    {
                        String[] sa = s.split("-", 2);
                        for (Long i = Long.parseLong(sa[0].trim()); i<=Long.parseLong(sa[1].trim()); i++)
                        {
                            departmentsQueue.add(i);
                        }
                    }
                    else
                    {
                        Long id = Long.parseLong(s.trim());
                        departmentsQueue.add(id);
                    }

    Отличный цикл! Кстати, я бы тут ещё и s.contains() убрал

    konsoletyper, 25 Августа 2011

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