1. Лучший говнокод

    В номинации:
    За время:
  2. Pascal / Говнокод #6410

    +96

    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
    function OnShape(sh: TShape; X, Y: Integer) : TBrushStyle;
    var r, cx, cy, d2: Integer;
    begin
    r := sh.Width div 2;
    cx := sh.Left + r;
    cy := sh.Top + r;
    d2 := (X - cx) * (X - cx) + (Y - cy) * (Y - cy);
    OnShape := bsClear;
    if d2 < r*r then OnShape := bsSolid;
    end;
    
    procedure TForm1.FormMouseMove(Sender: TObject; Shift: TShiftState; X,
      Y: Integer);
    begin
    Shape1.Brush.Color := clRed;
    Shape1.Brush.Style := OnShape(Shape1, X, Y);
    Shape2.Brush.Color := clLime;
    Shape2.Brush.Style := OnShape(Shape2, X, Y);
    Shape3.Brush.Color := clYellow;
    Shape3.Brush.Style := OnShape(Shape3, X, Y);
    end;

    Откуда бы вы думали это? Правильно, "Занимательное программирование Delphi". Глава 14. Светофор.

    Govnocoder#0xFF, 19 Апреля 2011

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

    +73

    1. 1
    2. 2
    if ((float)TF1.getText()>(float)(TF2.getText()){
    }

    Вот так вот приводят типы:)
    http://www.sql.ru/forum/actualthread.aspx?bid=38&tid=551373&hl=

    javaman, 18 Апреля 2011

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

    +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
    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
    void
    syslog(int pri, const char *fmt, ...)
    {
    	va_list ap;
    
    	va_start(ap, fmt);
    	vsyslog(pri, fmt, ap);
    	va_end(ap);
    }
    ......................................
    void
    vsyslog(int pri, const char *fmt, va_list ap)
    {
    	vsyslog_r(pri, &sdata, fmt, ap);
    }
    ....................................
    void
    vsyslog_r(int pri, struct syslog_data *data, const char *fmt, va_list ap)
    {
    	int cnt;
    	char ch, *p, *t;
    	time_t now;
    	int fd, saved_errno, error;
    #define	TBUF_LEN	2048
    #define	FMT_LEN		1024
    	char *stdp = NULL, tbuf[TBUF_LEN], fmt_cpy[FMT_LEN];
    	int tbuf_left, fmt_left, prlen;
    
    #define	INTERNALLOG	LOG_ERR|LOG_CONS|LOG_PERROR|LOG_PID
    	/* Check for invalid bits. */
    	if (pri & ~(LOG_PRIMASK|LOG_FACMASK)) {
    		if (data == &sdata) {
    			syslog(INTERNALLOG,
    			    "syslog: unknown facility/priority: %x", pri);
    		} else {
    			syslog_r(INTERNALLOG, data,
    			    "syslog_r: unknown facility/priority: %x", pri);
    		}
    		pri &= LOG_PRIMASK|LOG_FACMASK;
    	}
    .......................
    }
    ......................

    Из исходников Bioninc - Android libc.
    В реализации сислога, в случае ошибки, вызывается syslog

    elenbert, 14 Апреля 2011

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

    +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
    <?
    $url = file_get_contents("url страницы");
    $js = "<script";
    $endjs = "</script>";
    $test = 0;
    $i = 1;
     
    while($test == 0)
    {
      $q = strpos($url, $js);
      $q++;
      $y = strpos($url,$endjs);
      $y++;
      $url = substr($url, $q, $y);
      if($url == false)
      {
      $test = 1;
      }else{
      $i++;
      }
     }
     
    echo"<br>Удалено скриптов: " .$i. "<br>";
    $url = htmlspecialchars("$url", ENT_QUOTES);
    echo $url;
    ?>

    программа удаляющую полностью все javascript

    BlackMonolit, 13 Апреля 2011

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

    +165

    1. 01
    2. 02
    3. 03
    4. 04
    5. 05
    6. 06
    7. 07
    8. 08
    9. 09
    10. 10
    function writeln($str) {
        echo $str."\n";
    }
    
    function readln() {
        $handle = fopen ("php://stdin","r");
        $line = fgets($handle);
        fclose($handle);
        return $line;
    }

    Функции для реализации ввода и вывода PHP-CGI в режиме консоли

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

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

    −181

    1. 1
    2. 2
    3. 3
    4. 4
    if str(type(code_text)) == "<type 'str'>":
        code = self.errors[code_text]
    else:
        code = code_text

    Случайно найдено на просторах гуглокода

    winter, 12 Апреля 2011

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

    −130

    1. 1
    echo "Ghbdtn? rfr ltkf&" | sed "s/.*/\L&/;y|f,dult~;pbqrkvyjghcnea[wxioms]'.z&?|абвгдеёжзийклмнопрстуфхцчшщьыъэюя?,|"

    Транслирует английскую раскладку в русскую.

    AliceGoth, 12 Апреля 2011

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

    +160

    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
    <?php
    session_start();
    if(isset($_GET['gc'])){
    $s="";
    $s = rand(0,10).rand(0,10).rand(0,10).rand(0,10).rand(0,10).rand(0,10);
    $ct=mktime();
    $_SESSION['tm']=$ct;
    echo "<a href=\"http://netelis.hmsite.net/cg.php?cn=$s\">http://localhost/cg.php?cn=$s</a>";
      $_SESSION['ccc']=$s;
    } elseif(isset($_GET['cn']) && isset($_SESSION['tm'])){
      $tt=mktime();
      $dt=$tt-$_SESSION['tm'];
      if($dt<=25){
      if(isset($_SESSION['ccc'])){echo "<p align=center><FORM name=cp method=POST action=\"\"><br>"; echo $_SESSION['ccc']."<br>";echo "Enter the text you see<br>";}
      echo "<input name=cpt type=text>";
      echo "<input name=sub type=submit>";
      echo "</FORM></p>";} else {echo "The link was broken";};
    };
    if(isset($_POST['cpt'])){
    if(isset($_SESSION['ccc'])){
    if($_SESSION['ccc']==$_POST['cpt']){
    echo "Captcha is valid";
    
    };
    session_destroy();
    };
    
    };
    ?>

    Проверочный код

    AliceGoth, 09 Апреля 2011

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