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

    +151

    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
    <?php
    
    function test_menu() {
    //  $menu['test'] = array(
    //    'page callback' => 'test_page',
    //    'access callback' => TRUE,
    //  );
    
      $menu['test/%user_uid_optional'] = array(
        'page callback' => 'test_view',
        'page arguments' => array(1),
        'access callback' => 'test_access',
        'access arguments' => array(1),
      );
    
      $menu['test/%user/view'] = array(
        'title' => 'View',
        'type' => MENU_DEFAULT_LOCAL_TASK,
        'weight' => -10,
      );
    
      $menu['test/%user/edit'] = array(
        'title' => 'Edit',
        'page callback' => 'test_edit',
        'page arguments' => array(1),
        'access callback' => 'test_access',
        'access arguments' => array(1),
        'type' => MENU_LOCAL_TASK,
      );
    
      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);
    }
    
    function test_edit($account) {
      module_load_include('pages.inc', 'user');
      return user_edit($account);
    }
    
    function test_access($account) {
      dpm($account);
      return TRUE;
    }

    vectoroc, 25 Марта 2011

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

    +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
    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
    <?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,
      );
    
      $menu['test/%user/view'] = array(
        'title' => 'View',
        'type' => MENU_DEFAULT_LOCAL_TASK,
        'weight' => -10,
      );
    
      $menu['test/%user/edit'] = array(
        'title' => 'Edit',
        'page callback' => 'test_edit',
        'page arguments' => array(1),
        'access callback' => TRUE,
        'type' => MENU_LOCAL_TASK,
      );
    
      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);
    }
    
    function test_edit($account) {
      module_load_include('pages.inc', 'user');
      return user_edit($account);
    }

    vectoroc, 25 Марта 2011

    Комментарии (0)
  3. 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)
  4. PHP / Говнокод #6090

    +167

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

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

    turdman, 25 Марта 2011

    Комментарии (10)
  5. 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)
  6. 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)
  7. 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)
  8. 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)
  9. Си / Говнокод #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)
  10. 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)