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

    +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
    if(get_magic_quotes_gpc()) {
        deslash($_GET);
        deslash($_POST);
    }
    
    /*
     * function deslash(&$a)
     * убирает слеши из данных извне
     */
    function deslash(&$a) {
        if(defined('DEBUG'))echo '<br/>deslashing: '.print_r($a,true).'<br/>';
        foreach($a as $k=>$v)
            if (is_array($v)) {
                deslash($a[$k]);
            } else {
                if(defined('DEBUG')) echo 'was: '.$k.' => '.$v.'<br/>';
                $a[$k] = stripslashes($v);
                if(defined('DEBUG')) echo 'become: '.$k.' => '.$a[$k].'<br/>';
            }
    }

    Слэши не пройдут!

    RomaShka, 15 Апреля 2011

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

    +118

    1. 1
    2. 2
    object res = DataConnection.ExecuteScalar(sql);
    int count = (int)(long)res;

    Чтокуда?

    Vadimyan, 14 Апреля 2011

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

    +177

    1. 1
    2. 2
    3. 3
    4. 4
    5. 5
    6. 6
    7. 7
    8. 8
    switch ($row['active']) {
                case '1':
                    $st = '<font color="#008000">Вкл.</font></a>';
                    break;
                case '0':
                    $st = '<font color="#FF0000">Выкл.</font>';
                    break;
    }

    Замена if свитчем.

    Мартин, 14 Апреля 2011

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

    +145

    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 class Compare {
    	public static void main(String args[]) {
    		char b1,b2,b3,b4,b5,b6;
    		b1 = 'S';
    		b2 = 'F';
    		b3 = 'U';
    		b4 = 'L';
    		b5 = 'C';
    		b6 = 'E';
    		System.out.println("My word is : " + b1 + b3 + b5 + b5 + b6 + b1 + b1 + b2 + b3 + b4);
    	}
    }

    А теперь пишите сочинение на тему "Почему Akira такой индус" \>_</ xD

    Akira, 14 Апреля 2011

    Комментарии (13)
  5. Си / Говнокод #6361

    +132

    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
    int cont[15];
    bool stop_access = false;
    struct cel container[MAX_SIZE];
    struct termios savetty;
    struct termios tty;
    pthread_t thread[100];
    pthread_mutexattr_t muattr; 
    pthread_mutex_t count_mutex; 
    int icn=0;//Number elements in container
    static int x;
    static int y;
    void* stack;
      pthread_mutex_unlock(&count_mutex); 
      sleep(1);
    };
    return (void*)1;
    };
    
    void* main_thread(void *arg){
       while(true){
       sleep(1);
      char ic=getchar();
        if(ic=='\n'){
          printf("Thread\tnumber elements\n");
          for(int i=0;i<=x;i++)
          pthread_cancel(thread[i]);
          for(int i=0;i<=x;i++){
    	printf("%d ",i);
    	int cn=0;
    	for(int j=0;j<=icn;j++){
    	  if(container[j].thrnm==i){ cn++; };
    	  };
    	  printf("\t%d\n",cn);
    	};
    	printf("container number element %d\n",icn);
    	exit(0);
          };
     };
      
    };
    
    int main(int argc, char * argv[])
    {
      icn=0;
      
    if(argc<2){printf("1 arg n number of threads, 2 argument maximum number element in container");exit(0);};
    x=atoi(argv[1]);
    y=atoi(argv[2]);
    if(x>64){printf("Число потоков должно быть меньше 64\n");exit(0);}
    printf("x %d y %d\n",x,y);
    //mutex initialization
    int ret;
    ret = pthread_mutexattr_init(&muattr);
    
      //switch the keyboard to noncanonical mode
    pid_t pt=tcgetsid(0);
     // char *var=ctermid (NULL);
      printf("pid %d\n",pt);
    tcgetattr (0, &tty);
    savetty = tty;
    tty.c_lflag &= ~(ICANON);
    tty.c_cc[VMIN] = 1;
    tcsetattr (0, TCSAFLUSH, &tty);
    pthread_t mthr;
     pthread_attr_t mattr;
      pthread_attr_init(&mattr);
      pthread_attr_setdetachstate(&mattr,PTHREAD_CREATE_DETACHED);
    int mres = pthread_create(&mthr, &mattr, main_thread, NULL);
      if (mres == 0) {
        printf("Creating main thread\n");
        sleep(0.7);
      } else {
        perror("Creating the main first thread");
      return EXIT_FAILURE;
      }
      
      
    for(int i=0;i<=x;i++){
      int id1, id2, result;
      id1 = 1;
      pthread_attr_t attr;
      pthread_attr_init(&attr);
      // отсоединенный поток - не ждем его возврата
      pthread_attr_setdetachstate(&attr,PTHREAD_CREATE_DETACHED);
      result = pthread_create(&thread[i], &attr, thread_func, &i);
      if (result == 0) {
        printf("Creating thread %d\n",i);
        sleep(1);
      } else {
        perror("Creating the first thread");

    AliceGoth, 14 Апреля 2011

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

    +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
    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
    public static final int TYPE_A_OK = 0;
    public static final int TYPE_R_OPEN = 1;
    public static final int TYPE_R_STOPSID = 2;
    public static final int TYPE_A_STOPSID = 3;
    //....
    public static final int TYPE_R_ALARM = 26;
    HashMap<String, Integer> typesMap = new HashMap<String, Integer>();
    
    //в конструкторе
    
    public Data() {
    typesMap.put("A_OK", TYPE_A_OK);
    typesMap.put("R_OPEN", TYPE_R_OPEN);
    typesMap.put("R_STOPSID", TYPE_R_STOPSID);
    //...
    typesMap.put("R_ALARM", TYPE_R_ALARM);
    //...
    }
    
    
    //в одном из методов
    
    public boolean processPacket(Packet pack) {
    //...
    StringTokenizer strt = new StringTokenizer(body, "\n");
    		try {
    			id = strt.nextToken();
    			sign = strt.nextToken();
    			type = typesMap.get(strt.nextToken());
    			try {
    				commBody = strt.nextToken();
    			} catch (Exception e) {
    				// System.out.println("ERR: " + id + "; " + sign + "; " + type
    				// + "; ");
    			}
    		} catch (Exception e) {
    			System.err.println(sdf.format(Calendar.getInstance().getTime()) +"packet parsing error");
    			outBody += "A_ERR\n" + e.getMessage();
    		}
    
    switch (type) {
    		case TYPE_A_OK:
    			dontsend = true;
    			break;
    		case TYPE_R_OPEN:
    			outBody = processROpen(comm);
    			break;
    		case TYPE_R_CLOSE:
    			outBody = processRClose(comm);
    			break;
    //...
    case TYPE_R_ALARM:
    			outBody = processRAlarm(comm);
    			break;
    default:
    			outBody += "A_ERR";
    			break;
    }
    //...
    if(debug)
    System.err.println(outBody);
    //...
    return true;
    }

    ява она такая. Вот так. Вынужденно-китайский код. Не умеет свич со строками работать... и не хочется с хэшем заморачиваться. А скоро типов будет больше...

    ark, 14 Апреля 2011

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

    +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
    // is_foreign test
    if (firmId && (firmId == 'is_foreign_Y' || firmId == 'is_foreign_N') ) {
    	var is_foreign_value = firmId.substring(firmId.length-1,firmId.length);
    	firmId = 0;
    	if (is_foreign_value && is_foreign_value == 'Y' || is_foreign_value == 'N') {
    		var is_foreign = web.$('is_foreign');
    		is_foreign.value = is_foreign_value;
    		...
    	} else {
    		...
    	}
    } else {
    	var is_foreign = web.$('is_foreign');
    	is_foreign.value = 0;
    }

    Код отформатирован для лучшего понимания, было всё в одну колонку.

    sapegin, 14 Апреля 2011

    Комментарии (0)
  8. C++ / Говнокод #6358

    +161

    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
    bool PipeChannelForPointer::byteReceived( uint8_t byte )
     {
     	received[ byteidx ] = byte;
     	byteidx++;
     	if( byteidx == sizeof(void*) ){
     		byteidx = 0;
     		void *ptr = *((void**)received);
    		ptrReceived( ptr );
    		bool ret = ptrReceived( ptr );
    		if( ret == false )
    			return false;
     	}
    	return true;
     }

    panter_dsd, 14 Апреля 2011

    Комментарии (4)
  9. Ruby / Говнокод #6357

    −97

    1. 1
    hash.to_a.select{|elem| elem[1].map{|st| st.from}.include? state}.map{|elem| elem[1].map{|inner| inner.to}.uniq}.flatten

    e2718, 14 Апреля 2011

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

    +164

    1. 1
    2. 2
    3. 3
    4. 4
    5. 5
    $host = str_replace( "www.", "", getenv( "HTTP_HOST" ) );
    if ( $host != "" )
    {
       exit();
    }

    partizan22, 14 Апреля 2011

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