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

    +150

    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
    <?php
    
    function test_menu() {
      $menu['test'] = array(
        'page callback' => 'test_page',
        'access callback' => TRUE,
      );
    
      $menu['test/%user'] = array(
        'page callback' => 'test_view',
        'page arguments' => array(1),
        'access callback' => TRUE,
      );
    
      return $menu;
    }
    
    function test_page() {
      global $user;
      if ($user->uid) {
        menu_set_active_item("test/$user->uid");
        return menu_execute_active_handler();
      }
      else {
        drupal_goto('user/login');
      }
    }
    
    function test_view($account) {
      module_load_include('pages.inc', 'user');
      return user_view($account);
    }

    vectoroc, 25 Марта 2011

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

    +167

    1. 1
    2. 2
    <?php
    $nidPage_storage = 64578; // нид страницы "Магазины и склады" - хранится отдельно, потому что контент-менеджеры удаляют страницу "Магазинов" и нид всё время меняется

    Изначально это это был drupal.

    turdman, 25 Марта 2011

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

    +78

    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
    public Boolean isEqual(RepJoinCondition targetJoin )
    	{
    		if (targetJoin == null) return false;
    
    		Boolean isLeftSideEqual ;
    		Boolean isRightSideEqual ;
    					
    		isLeftSideEqual = ((this.leftJoinFiled.fieldTableName.toUpperCase() == targetJoin.leftJoinFiled.fieldTableName.toUpperCase()) &&
    							(this.leftJoinFiled.fieldName.toUpperCase() == targetJoin.leftJoinFiled.fieldName.toUpperCase()));
    							
    		isRightSideEqual = 	((this.rightJoinFiled.fieldTableName.toUpperCase() == targetJoin.rightJoinFiled.fieldTableName.toUpperCase()) &&
    							(this.rightJoinFiled.fieldName.toUpperCase() == targetJoin.rightJoinFiled.fieldName.toUpperCase()));
    							
    		if (isLeftSideEqual && isRightSideEqual) return true;
    		
    		isLeftSideEqual = ((this.leftJoinFiled.fieldTableName.toUpperCase() == targetJoin.rightJoinFiled.fieldTableName.toUpperCase()) &&
    							(this.leftJoinFiled.fieldName.toUpperCase() == targetJoin.rightJoinFiled.fieldName.toUpperCase()));
    							
    		isRightSideEqual = 	((this.rightJoinFiled.fieldTableName.toUpperCase() == targetJoin.leftJoinFiled.fieldTableName.toUpperCase()) &&
    							(this.rightJoinFiled.fieldName.toUpperCase() == targetJoin.leftJoinFiled.fieldName.toUpperCase())); 					
    		
    		if (isLeftSideEqual && isRightSideEqual) return true;					
    		
    		return false;
    	}

    Весьма сложнная проверка равенства, изпользуется некорректно ==

    vraptor, 25 Марта 2011

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

    +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
    14. 14
    15. 15
    16. 16
    package somepackage;
    
    import  java.net.URL;
    import  javax.xml.namespace.QName;
    import  javax.xml.ws.Service;
                
    public class proxyClass {
        
        URL url = new URL("http://someserver/somepath/output?wsdl");
        QName qname = new QName("http://someserver/", "someservice");
    
        Service service = Service.create(url, qname);
    
        test someVar = service.getPort(test.class);
    
    }

    И почему же Eclipse ругается?

    lyric, 25 Марта 2011

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

    +159

    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
    <?php
    $z=0;
    $ti=0;
    $ti2=0;
    
    $res=array();
    $txt="";
    $res=array();
    if($argc<2)exit(0);
    $fn=$argv[1];
    $pt='/(^|\b|\s)((\w|[а-я]|\d)+(?:\.|\,)?)(\b|\.|,|-)/i';
    if(isset($fn)){
    $fc=file($fn);
    foreach($fc as $nl=>$str){
    preg_match_all($pt,$str,$res,PREG_PATTERN_ORDER);
    foreach($res[0] as $key=>$per){
     # $per=trim($per);
    $sz=iconv_strlen($per);
    $tz=iconv_strlen($per);
    echo "Per $per key $key sz $sz\n";
    
    while($sz>=2){ 
     $eb = substr($per,0,$sz-1);
    echo "eb $eb\n";
    $res=system("cat -b dict.txt | grep ' ".$eb." ' | head -n1 | gawk '{ print $1 }'");
    #echo "$res\n";
    if($res!=""){
    echo "res $res\n";
    $oc=substr($per,$sz-1,$tz); 
    $fd=fopen("$argv[1].txt","a");
    if($fd<0){echo "fopen";exit(0);};
      fseek($fd,SEEK_END,0);
    fwrite($fd,"$res$oc ");
    
    fclose($fd);
    $sz=1;
    sleep(3);
    };
      $sz--;
    };
    if($sz==1){
    
    $fd=fopen("$argv[1].txt","a");
    if($fd<0){echo "fopen";exit(0);};
      fseek($fd,SEEK_END,0);
      fwrite($fd,"$per ");
      fclose($fd);
    };
    
    };
    };
    $str="";
    $res="";
    }
    ?>

    Замена слова кодом из словаря, по номеру слова в словаре.

    AliceGoth, 25 Марта 2011

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

    −106

    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
    # progress bar
    
    width = 60  # width of bar
    com   = 540 # input data
    
    pr = com * 0.01
    i = 0
    j = width
    
    v = 1
    puts
    while pr <= com
    
      print "\r#{v}% [#{"|"*i}#{" "*j}]"
    
      pr += com * 0.01  
    
      i += width * 0.01
      j -= width * 0.01
    
      v += 1  
      
      sleep(0.01)
      
    end
    puts

    Консольный прогресс-бар.

    delmind, 25 Марта 2011

    Комментарии (1)
  7. Си / Говнокод #6085

    +113

    1. 1
    2. 2
    3. 3
    4. 4
    5. 5
    6. 6
    7. 7
    8. 8
    int main(int argv,char *argc[]){
      ...
      if(fork() != 0)goto _EXIT;
      ...
      return 0;
    _EXIT:
      return 0;
    }

    Ну как ???

    Mooncrafter, 24 Марта 2011

    Комментарии (5)
  8. SQL / Говнокод #6084

    −863

    1. 1
    2. 2
    3. 3
    WHERE (p.city_id = 1)
       AND ((COALESCE(b.banket_persons,0)=0) OR (b.banket_persons>=20 AND b.banket_persons<=30))
       AND ((COALESCE(b.banket_per_person,0)=0) OR (b.banket_per_person>=500 AND b.banket_per_person<=1000))

    упорный программер явно не подозревал о существовании "is null" и "between"

    NaCilnic, 24 Марта 2011

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

    +173

    1. 1
    2. 2
    3. 3
    4. 4
    5. 5
    6. 6
    7. 7
    if ($mail->send($mailTo)) { 
    			$aSuccMess[] = "Спасибо. Ваш сообщение отправлено. Администрация сайта рассмотрит его в ближайшее время.";
    			$fname = $fmail = $ftext = "";
    		} else { 
    			$fname = $fmail = $ftext = "";
    			$aSuccMess[] = "Спасибо. Ваш сообщение отправлено. Администрация сайта рассмотрит его в ближайшее время.";
    		}

    Взято с сайта, сделанным моим коллегой)

    sleeper, 24 Марта 2011

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

    +122

    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
    static void Main(string[] args)
    {
        int count = 4096;
        int w = int.MaxValue / count;
        int h = 10;
        int argb = 0;
        Directory.CreateDirectory("test");
        for (int bj = 0; bj < count; ++bj)
        {
            Console.WriteLine("Processing bitmap #{0} of {1}...\t{2,3}%",
                              bj + 1, count, (int)(100f * ((float)(bj + 1) / (float)count)));
            using (Bitmap bmp = new Bitmap(w, h))
            {
                Console.Write("Done   0%");
                using (Graphics gr = Graphics.FromImage(bmp))
                    for (int x = 0; x < w; ++x, argb++)
                    {
                         gr.DrawLine(new Pen(Color.FromArgb(argb)), x, 0, x, h);
                         Console.Write("\b\b\b\b{0,3}%", (int)(100f * ((float)(x + 1) / (float)w)));
                    }
                    Console.Write("\nSaving bitmap...\n{0}", new string('-', 80));
                    bmp.Save(string.Format("test\\#{0}.bmp", bj + 1), ImageFormat.Bmp);
            }
        }
    }

    Если Вам нечего делать и есть лишние 80 гигов на харде...

    FMB, 24 Марта 2011

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