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

    +131

    1. 1
    2. 2
    3. 3
    4. 4
    5. 5
    data М = М { unМ :: String }
    instance Show М where
        show = map succ . unМ
    
    main = print $ М"ФТИ"

    Синтетический баян...

    kirgo2, 01 Ноября 2011

    Комментарии (9)
  2. Java / Говнокод #8378

    +75

    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
    int i128 = 0, i256 =0, i384=0, i512=0, i640=0, i786=0, i896=0, i1024=0, i1152=0, i1280=0, i1408=0, i1536=0;
            for (int index: data) {
                if (index>max) max = index;
                if (min>index) min = index;
                if (0<=index & index<128) i128++;
                else if (128<=index & index<256) i256++;
                else if (256<=index & index<384) i384++;
                else if (384<=index & index<512) i512++;
                else if (512<=index & index<640) i640++;
                else if (640<=index & index<786) i786++;
                else if (786<=index & index<896) i896++;
                else if (896<=index & index<1024) i1024++;
                else if (1024<=index & index<1152) i1152++;
                else if (1152<=index & index<1280) i1280++;
                else if (1280<=index & index<1408) i1408++;
                else if (1408<=index & index<1536) i1536++;

    Считаем количество попаданий index в различные диапазоны значений.

    betastat, 01 Ноября 2011

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

    +164

    1. 01
    2. 02
    3. 03
    4. 04
    5. 05
    6. 06
    7. 07
    8. 08
    9. 09
    10. 10
    if (
    	$arItem["DEPTH_LEVEL"]==$previousLevel
    	&&$arItem["IS_PARENT"]
    	&&$arItem["DEPTH_LEVEL"]>3
    	||$arItem["DEPTH_LEVEL"]<$previousLevel
    	&&$arItem["IS_PARENT"]
    	&&$arItem["DEPTH_LEVEL"]==3
    	&&$previousLevel-$arItem["DEPTH_LEVEL"]==1
    ) 
    .....

    Paranoid mode deteсted! Внимание! (Г)Код был в строку, для удобства чтения отформатировал.

    ProfBiss, 01 Ноября 2011

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

    −116

    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
    // было
    
    -(BOOL)textFieldShouldReturn:(UITextField *)textField {
        
        if (textField == firstName) {
            [lastName becomeFirstResponder];
        }
        
        else if (textField == lastName) {
            [zip becomeFirstResponder];
        } 
        
        else if (textField == emailAdr) {
            [confirmEmailAdr becomeFirstResponder];
        }    
        else if (textField == confirmEmailAdr) {
            [zip becomeFirstResponder];
        }
        else if (textField == zip) {
            [street becomeFirstResponder];
        }
        else if (textField == street) {
            [city becomeFirstResponder];
        }
        else if (textField == city) {
            [telephonNumber becomeFirstResponder];
        }
        else if (textField == telephonNumber) {
            [wachtwoord becomeFirstResponder];
        }
      
        else{
            [textField resignFirstResponder];
        }
        
        
        return YES;
    }
    
    // решил заменить на ( при условии что все текстфилды протаганы от 1 до N):
    
    -(BOOL)textFieldShouldReturn:(UITextField *)textField {
    
        int tag = textField.tag;
        
        UITextField* tf = (UITextField*)[self.scrollView viewWithTag:tag+1];
        
        if ( tf ) 
            [tf becomeFirstResponder];
        else 
            [textField resignFirstResponder];
        
        return YES;
    }

    lime, 01 Ноября 2011

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

    +80

    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
    @Deprecated
        private byte getLoByte(int i) {
            byte ret = 0x00;
            String hex = Integer.toHexString(i);
            int length = hex.length();
            if (length == 1) {
                ret = Integer.valueOf(hex.substring(length - 1), 16).byteValue();
            } else if (length >= 2) {
                ret = Integer.valueOf(hex.substring(length - 2), 16).byteValue();
            }
            return ret;
        }
    
        @Deprecated
        private byte getHiByte(int i) {
            String hex = Integer.toHexString(i);
            byte ret = 0x00;
            int length = hex.length();
            if (length > 3) {
                ret = Integer.valueOf(hex.substring(length - 4, length - 2), 16).byteValue();
            } else if (length == 3) {
                ret = Integer.valueOf(hex.substring(length - 3, length - 2), 16).byteValue();
            }
            return ret;
        }

    Вытаскивание старшего и младшего байтов числа из последних одного или двух байтов

    as1an, 01 Ноября 2011

    Комментарии (15)
  6. 1C / Говнокод #8374

    −102

    1. 1
    2. 2
    Сегодня мы отказались от 1С.
    Сегодня, когда день апплодировал стоя.

    А в штанах остались желтые бумажки. В назидание?

    alexoy, 31 Октября 2011

    Комментарии (3)
  7. ActionScript / Говнокод #8373

    −128

    1. 1
    2. 2
    3. 3
    4. 4
    if (players.indexOf(String(Game.uid)) == 0)
    	players.shift();
    else
    	players.pop();

    KirAmp, 31 Октября 2011

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

    +171

    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
    <?if($USER_ID$='1')?><font color="#FF0000"><b>$NAME$</b></font><?else?> 
      <?if($USER_ID$='2')?><font color="#FFFF00"><b>$NAME$</b></font><?else?> 
      <?if($USER_ID$='3')?><font color="#FFFF00"><b>$NAME$</b></font><?else?> 
      <?if($USER_ID$='4')?><font color="#FFFF00"><b>$NAME$</b></font><?else?> 
      <?if($USER_ID$='5')?><font color="#FFFF00"><b>$NAME$</b></font><?else?> 
      <?if($USER_ID$='6')?><font color="#FFFF00"><b>$NAME$</b></font><?else?> 
      <?if($USER_ID$='7')?><font color="#FFFF00"><b>$NAME$</b></font><?else?> 
      <?if($USER_ID$='8')?><font color="#00BFFF"><b>$NAME$</b></font><?else?> 
      <?if($USER_ID$='9')?><font color="#30EFFF"><b>$NAME$</b></font><?else?> 
      <?if($USER_ID$='10')?><font color="#FFFF00"><b>$NAME$</b></font><?else?> 
      <?if($USER_ID$='11')?><font color="#FFFF00"><b>$NAME$</b></font><?else?> 
      <?if($USER_ID$='12')?><font color="#FFFF00"><b>$NAME$</b></font><?else?> 
      <?if($USER_ID$='13')?><font color="#FFFF00"><b>$NAME$</b></font><?else?> 
      <?if($USER_ID$='14')?><font color="#FFFF00"><b>$NAME$</b></font><?else?> 
      <?if($USER_ID$='15')?><font color="#FFFF00"><b>$NAME$</b></font><?else?> 
      <?if($USER_ID$='16')?><font color="#FFFF00"><b>$NAME$</b></font><?else?> 
      <?if($USER_ID$='17')?><font color="#FFFF00"><b>$NAME$</b></font><?else?> 
      <?if($USER_ID$='18')?><font color="#FFFF00"><b>$NAME$</b></font><?else?> 
      <?if($USER_ID$='19')?><font color="#FFFF00"><b>$NAME$</b></font><?else?> 
      <?if($USER_ID$='20')?><font color="#FFFF00"><b>$NAME$</b></font><?else?> 
      <?if($USER_ID$='21')?><font color="#FFFF00"><b>$NAME$</b></font><?else?> 
      <?if($USER_ID$='22')?><font color="#FFFF00"><b>$NAME$</b></font><?else?> 
      <?if($USER_ID$='23')?><font color="#9B0000"><b>$NAME$</b></font><?else?> 
      <?if($USER_ID$='24')?><font color="#FFFF00"><b>$NAME$</b></font><?else?> 
      <?if($USER_ID$='25')?><font color="#FF0000"><b>$NAME$</b></font><?else?> 
      <?if($USER_ID$='26')?><font color="#FFFF00"><b>$NAME$</b></font><?else?> 
      <?if($USER_ID$='27')?><font color="#9B0000"><b>$NAME$</b></font><?else?> 
      <?if($USER_ID$='28')?><font color="#FFFF00"><b>$NAME$</b></font><?else?> 
      <?if($USER_ID$='29')?><font color="#30EFFF"><b>$NAME$</b></font><?else?> 
      <?if($USER_ID$='30')?><font color="#FFFF00"><b>$NAME$</b></font><?else?> 
      <?if($USER_ID$='31')?><font color="#FFFF00"><b>$NAME$</b></font><?else?> 
      <?if($USER_ID$='32')?><font color="#FFFF00"><b>$NAME$</b></font><?else?> 
      <?if($USER_ID$='33')?><font color="#FFFF00"><b>$NAME$</b></font><?else?> 
      <?if($USER_ID$='34')?><font color="#FF0000"><b>$NAME$</b></font><?else?><b>$NAME$</b>  
      <?endif?><?endif?><?endif?><?endif?><?endif?><?endif?><?endif?><?endif?><?endif?><?endif?><?endif?><?endif?><?endif?><?endif?><?endif?><?end if?><?endif?><?endif?><?endif?><?endif?><?endif?><?endif?><?endif?><?endif?><?endif?><?endif?><?endif?><?endif?><?endif?><?endif?><?endif?>< ?endif?><?endif?><?endif?>

    Вообще то тут переменные uCoz, но это не важно.
    Автор: http://1759741350.unet.com/

    olegsuv, 31 Октября 2011

    Комментарии (38)
  9. Си / Говнокод #8371

    +133

    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
    /* ... */
    /**************************************************************************************
      cpu_information () parse /proc/cpuinfo to get information about CPU 
     **************************************************************************************/
    int cpu_information (data* user_data, int pos)
    {
      FILE *cpufp/* /proc/cpuinfo */ /*, *sysfs_max_cpu_freq_fp  /sys/devices/system/cpu/cpu%d/cpufreq/cpuinfo_max_freq */;
       
      char* ch = (char*)malloc (MAXLEN);
      char* line = (char*)malloc (MAXLEN);
      char* buf = (char*)malloc (MAXLEN);
      
      GtkTreeIter iter[2];
      // int y = 0;
      if ((cpufp = fopen(CPU_INFORMATION_FILE, "r")) == NULL)
        printf ("%s\n", "Error opening /proc/cpuinfo");
    
      while (fgets (ch, MAXLEN, cpufp) != NULL) 
      {
        if (!strncmp (ch, "processor", 9)) 
        {
          sscanf (ch, "%*s %*s %s", line);
          strcpy (buf, "CPU");
          gtk_tree_store_insert_with_values (user_data->InformationTreeStore, &iter[0],NULL, pos, 0, buf, 1, line, -1);
        } else if (!strncmp(ch, "vendor_id", 9))
        {
          sscanf(ch,"%*s %*s %s", line);
          strcpy (buf, "Processor type:");
          gtk_tree_store_insert_with_values (user_data->InformationTreeStore, &iter[1],&iter[0], pos, 0, buf, 1, line, -1); 
        } else if (!strncmp(ch, "model name", 10))
        {
          strcpy(buf, "Model name");
          ch[strlen(ch)-1] = '\0'; //delete '\n' symbol from the end of string
          gtk_tree_store_insert_with_values (user_data->InformationTreeStore, &iter[1],&iter[0], pos, 0, buf, 1, &ch[13], -1);
        } else if (!strncmp(ch, "cpu MHz", 7))
        {
          int curr_cpu_freq;
          sscanf(ch, "%*s %*s %*s %d\n", &curr_cpu_freq);
          sprintf(line, "%d", curr_cpu_freq);
          strcpy (buf, "Current Processor Speed in MHz");
          gtk_tree_store_insert_with_values (user_data->InformationTreeStore, &iter[1],&iter[0], pos, 0, buf, 1, line,-1);
          /*
    	 Begin parsing /sys/devices/system/cpu/cpu%d/cpufreq/cpuinfo_max_freq 
    	 
          sprintf (sysfs_max_cpu_freq_path, SYSFS_CPU_MAX_FREQ_FORMAT_STRING, y);
          if ((sysfs_max_cpu_freq_fp = fopen (sysfs_max_cpu_freq_path, "r")) == NULL) {
        	  printf("%s %s\n", "Error opening",  sysfs_max_cpu_freq_path);
          }
          while (fgets (line, MAXLEN, sysfs_max_cpu_freq_fp) != NULL)
          {
    	sscanf (line, "%d", &max_cpu_freq);
    	sprintf (line, "%d", max_cpu_freq/1000);
    	strcpy (buf, "Max Processor Speed in MHz");
    	gtk_tree_store_insert_with_values (user_data->InformationTreeStore, &iter[2],&iter[1], pos, 0, buf, 1, line,-1);
          }
          y++;
          
    	 End parsing 
           
          fclose (sysfs_max_cpu_freq_fp);*/
        }  else if (!strncmp(ch, "cache size", 10))
        {
          sscanf(ch, "%*s %*s %*s %s", line);
          strcpy (buf, "Processor cache size");
          strcat (line, " KB");
          gtk_tree_store_insert_with_values (user_data->InformationTreeStore, &iter[1],&iter[0], pos, 0, buf, 1, line, -1);
    
        } else if (!strncmp(ch, "bogomips", 8)) 
        {
          sscanf(ch, "%*s %*s %s", line);
          strcpy (buf, "Processor speed in Bogomips");
          gtk_tree_store_insert_with_values (user_data->InformationTreeStore, &iter[1],&iter[0], pos, 0, buf, 1, line, -1);
          cpu_temperature (user_data,&iter[0], pos); //get CPU temperature.
        }
        pos++;
      }
    
      free (buf);
      free (line);
      free (ch);
      //free (sysfs_max_cpu_freq_path);
      fclose (cpufp);
      return 0;
    }
    /* ... */

    По просьбам трудящихся http://govnokod.ru/7979#comment116436

    По коду:
    1) хорошо бы проверять, что попытался выделить;
    2) ошибка произошла успешно — начинаем парсить...;
    3) для решения таких задач стоит обратить своё внимание на, например, PyGTK.

    P.S. Если уж совсем не в мочь и к строкам так тянет,
    то допилите под себя LiteC, у Г.Шилдта есть что подсмотреть.

    sayidandrtfm, 31 Октября 2011

    Комментарии (20)
  10. JavaScript / Говнокод #8370

    +163

    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
    function moveIcon(ui,top) {
    
        ob = ui["draggable"][0]["id"];
        level = getIconsPlace(ob, top);
        left = ((level-1) * step) + icon_down;
    
        pos = getLeftPX(ob);
        
        pos_level = 0;
        
        // check icon position
        if(pos < 58) {
            pos_level = 0;
        } else if(pos > 58 && pos < 83) {
            pos_level = 1;
        } else if(pos > 83 && pos < 108) {
            pos_level = 2;
        } else if(pos > 108 && pos < 133) {
            pos_level = 3;
        } else if(pos > 133 && pos < 158) {
            pos_level = 4;
        } else if(pos > 158) {
            pos_level = 5;
        } 
            
        pos_left = ((pos_level) * step) + icon_down;
        left = ((level-1) * step) + icon_down;
        if(left > pos_left) {
            left = pos_left;
        }
    
        $("#" + ui["draggable"][0]["id"]).css("left", left + "px");
        $("#" + ui["draggable"][0]["id"]).css("top", top + "px");
        
        changePosition();
        getResult();
    }

    Я думаю здесь без комментариев

    unkwua, 31 Октября 2011

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