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

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

    +132

    1. 001
    2. 002
    3. 003
    4. 004
    5. 005
    6. 006
    7. 007
    8. 008
    9. 009
    10. 010
    11. 011
    12. 012
    13. 013
    14. 014
    15. 015
    16. 016
    17. 017
    18. 018
    19. 019
    20. 020
    21. 021
    22. 022
    23. 023
    24. 024
    25. 025
    26. 026
    27. 027
    28. 028
    29. 029
    30. 030
    31. 031
    32. 032
    33. 033
    34. 034
    35. 035
    36. 036
    37. 037
    38. 038
    39. 039
    40. 040
    41. 041
    42. 042
    43. 043
    44. 044
    45. 045
    46. 046
    47. 047
    48. 048
    49. 049
    50. 050
    51. 051
    52. 052
    53. 053
    54. 054
    55. 055
    56. 056
    57. 057
    58. 058
    59. 059
    60. 060
    61. 061
    62. 062
    63. 063
    64. 064
    65. 065
    66. 066
    67. 067
    68. 068
    69. 069
    70. 070
    71. 071
    72. 072
    73. 073
    74. 074
    75. 075
    76. 076
    77. 077
    78. 078
    79. 079
    80. 080
    81. 081
    82. 082
    83. 083
    84. 084
    85. 085
    86. 086
    87. 087
    88. 088
    89. 089
    90. 090
    91. 091
    92. 092
    93. 093
    94. 094
    95. 095
    96. 096
    97. 097
    98. 098
    99. 099
    100. 100
    static volatile int rotatelog=0;
    
    void daemonize();
    void *receive_thread(void *ptr);
    void *write_thread(void *ptr);
    void sighup_hdl(int signal);
    
    FILE *hfl_log;
    
    int main(){
      daemonize();
    
      hfl_log=fopen(HM_LOGFILE, "a");
      setlinebuf(hfl_log);
    
      signal(SIGHUP,sighup_hdl);
    
      receive_thread(NULL);
    
      return 0;
    }
    
    void daemonize(){
      int devnullfd = -1;
      umask(~0700);
      devnullfd = open("/dev/null", 0);
      dup2(devnullfd, STDIN_FILENO);
      dup2(devnullfd, STDOUT_FILENO);
      close(devnullfd);
      switch(fork()) {
        case -1:
          perror("fork");
          exit(1);
          break;
        case 0:
          break;
        default:
          exit(0);
          break;
      }
    }
    
    void *receive_thread(void *ptr){
      int udpsock, i;
      struct _peventmsg *pmsg;
      struct sockaddr_in serv;
      socklen_t servlen;
      ssize_t len;
      time_t tm;
      char sign1[SHA_DIGEST_LENGTH], sign2[SHA_DIGEST_LENGTH];
      udpsock=socket(PF_INET, SOCK_DGRAM, IPPROTO_UDP);
      if (udpsock==-1)
        return NULL;
      i=32*1024*1024;
      setsockopt(udpsock, SOL_SOCKET, SO_RCVBUFFORCE, (void*)&i, sizeof(i));
      memset(&serv, 0, sizeof(serv));
      serv.sin_family = AF_INET;
      serv.sin_port = htons(TSPORT);
      serv.sin_addr.s_addr = inet_addr(TSIP);
      if (bind(udpsock, (struct sockaddr *)&serv, sizeof(struct sockaddr_in))){
        close(udpsock);
        return NULL;
      }
      while (1){
        if (rotatelog){
          rotatelog=0;
          //fflush(hfl_log); fclose() should be enough
          fclose(hfl_log);
          hfl_log=fopen(HM_LOGFILE, "a");
          //do we really tail -f that much on this log that we need it line buffered? It requires 1 write per incoming packet
          setlinebuf(hfl_log);
        }
        pmsg=(struct _peventmsg *)malloc(sizeof(struct _peventmsg));
        servlen=sizeof(serv);
        len=recvfrom(udpsock, &pmsg->msg, sizeof(pmsg->msg), 0, (struct sockaddr *)&serv, &servlen);
        if (len!=sizeof(pmsg->msg)){
          free(pmsg);
          continue;
        }
        time(&tm);
        if (pmsg->msg.tm+20<tm || pmsg->msg.tm-20>tm){
          free(pmsg);
          continue;
        }
        memcpy(sign1, pmsg->msg.sign, sizeof(sign1));
        memset(pmsg->msg.sign, 0, sizeof(pmsg->msg.sign));
        strcpy(pmsg->msg.sign, SECRET);
        SHA1((unsigned char *)&pmsg->msg, sizeof(pmsg->msg), (unsigned char *)sign2);
        if (memcmp(sign1, sign2, sizeof(sign1))){
          free(pmsg);
          continue;
        }
        strcpy(pmsg->ip, inet_ntoa(serv.sin_addr));
        fprintf(hfl_log, "%ld %s %lu %u %u %u %u %s\n", 
                          le64toh(pmsg->msg.tm), pmsg->msg.ip, le64toh(pmsg->msg.bytessent), le32toh(pmsg->msg.seconds), 
                          le32toh(pmsg->msg.ttype), le32toh(pmsg->msg.tcpi_total_retrans), le32toh(pmsg->msg.tcpi_snd_mss), pmsg->ip);
    
        free(pmsg);
      }
    }

    Traffic analysis tool: http://vasil.ludost.net/blog/?p=3029

    core-ix, 29 Марта 2013

    Комментарии (11)
  3. C# / Говнокод #12747

    +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
    /*FuckingMagic*/
    public static T[] GetT<T>(int _RepeatCount, Func<IExpression, T[]> _GetT, IExpression[] _Expressions) {
    	T[] __outbytes;
    	T[][] __tmp_bytes;
    	int __offset = 0, __tmp_sz = 0, __i = 0, __j = 0, __ex_l = _Expressions.Length;
    	__ex_l = _Expressions.Length;
    	__tmp_bytes = new T[__ex_l * _RepeatCount][];
    	for ( __j = 0; __j < _RepeatCount; __j++ )
    		for ( __i = 0; __i < __ex_l; __i++ )
    			__tmp_bytes[__j * __ex_l + __i] = _GetT(_Expressions[__i]);
    	__j = __tmp_bytes.Length;
    	for ( __i = 0; __i < __j; __tmp_sz += __tmp_bytes[__i].Length, __i++ ) ;
    	__outbytes = new T[__tmp_sz];
    	for ( __i = 0; __i < __j; __i++ ) {
    		__tmp_sz = __tmp_bytes[__i].Length;
    		Array.Copy(__tmp_bytes[__i], 0, __outbytes, __offset, __tmp_sz);
    		__tmp_bytes[__i] = null;
    		__offset += __tmp_sz;
    	}
    	return __outbytes;
    }

    С тех пор я всегда пишу код трезвым.

    kasthack, 14 Марта 2013

    Комментарии (11)
  4. Куча / Говнокод #12697

    +125

    1. 1
    2. 2
    $ find . -type f -name '*.asp' -exec grep -nHi 'select \*' {} \; | wc -l
    2160

    teh drama :(

    wvxvw, 06 Марта 2013

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

    +71

    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
    private static final int IDX_OBJECT = 0;
    private static final String PARTY_ACCOUNT_BALANCE_QUERIES = "Select party.id from Party party WHERE party.TaxID='615100175';Select account.id from PaymentAccount account, Party party WHERE party.TaxID='615100175';Select balance.id from PaymentBalance balance WHERE balance.BalanceType='10000';";
    private static final int queryAmount = 3;
    public void createPaymentAccountUpdate() {
    	String[] QUERY = new String[queryAmount];
    	int startIndex = 0, endIndex=0;
    	IRecordset [] rs=null;
    
    	for (int i = 0; i < queryAmount; i++) {
    		endIndex = PARTY_ACCOUNT_BALANCE_QUERIES.indexOf(';', startIndex);
    		QUERY[i] = PARTY_ACCOUNT_BALANCE_QUERIES.substring(startIndex, endIndex);
    		startIndex = endIndex + 1;
    	} 
    	for (int i = 0; i < queryAmount; i++) {
    		rs[i] = s_mgr.newQuery().execute(QUERY[i].toString());
    	}
    	if (rs[0].moveNext()) {
    		IParty party = (IParty)rs[0].valueFromIndex(IDX_OBJECT);
    		if (rs[1].moveNext()) {
    			IPaymentAccount pa = (IPaymentAccount) rs[1].valueFromIndex(IDX_OBJECT);
    			pa.setParty(party);
    		}
    		if (rs[2].moveNext()) {
    			IPaymentBalance pb = (IPaymentBalance) rs[2].valueFromIndex(IDX_OBJECT);
    			pa.setBalance(pb);
    		}            
    		pa.setComment("Test account update created"); 
    		pa.Save();
    	}
    }

    Лучше уж никаких тестов, чем такие

    askell, 14 Февраля 2013

    Комментарии (11)
  6. C++ / Говнокод #12585

    +9

    1. 1
    2. 2
    3. 3
    4. 4
    5. 5
    6. 6
    y=fopen(lex,"w+");
    fclose(y);
    FILE *r=fopen(result,"w+");
    fclose(r);
    FILE *k=fopen("pryklad.obj","w+");
    fclose(k);

    Abbath, 13 Февраля 2013

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

    +121

    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
    91. 91
    #Creates an array with the frequencies from C2 to C5, 37 notes in all
    for j from 1 to 37
    	if j = 1 
    	notes [j] = 65.41 # лёгкие пути не нужны
    	endif
    	if j = 2
    	notes [j] = 69.30
    	endif
    # ...дальше понятно...
    endfor
    
    # <...>
    
    #Determining whether or not the scale contains C
    #This determines how many notes of the 37 possible must be included.
    noCList [1] = 3 # опа, а вот тут уже научились числовые индексы использовать
    noCList [2] = 5
    noCList [3] = 7
    noCList [4] = 10
    noCList [5] = 12
    noC = 0
    for n from 1 to 5
    	if 'starter' = noCList['n']
    		noC = 1
    	endif
    endfor
    #If there is a C...
    if noC = 0
    #The for loop mathematically selects the scale notes to use
    for m from 1 to 22
    	if 'm' = 1
    		noteind = 'starter'
    	endif
    	if 'm' = 2
    		noteind = 'starter' + 2
    		if 'noteind' > 37
    			noteind = 'noteind' - 36
    		endif
    	endif
    # ...ага-ага...
    	scalenotes ['m'] = notes['noteind']
    endfor
    #If there is not a C...
    else
    for m from 1 to 21
    	if 'm' = 1
    		noteind = 'starter'
    	endif
    	if 'm' = 2
    		noteind = 'starter' + 2
    		if 'noteind' > 37
    			noteind = 'noteind' - 36
    		endif
    	endif
    # ...так точно...
    	scalenotes ['m'] = notes['noteind']
    endfor
    endif
    
    # <...>
    
    #Add new pitch information
    #For each point, we move the freq to the closest scale note
    for q from 1 to 'numPoints'
    	#The original freq of pitch
    	currentfreq = pitches['q']
    	#A starting threhold for difference between original and a musical note
    	diff = 50
    	#If there is C in the scale, making 22 possible notes to tune to...
    	if 'noC' = 0
    	#For loop finds the lowest difference between original pitch and a musical note
    	for c from 1 to 22
    		diff2 = abs('currentfreq' - scalenotes['c'])
    		if 'diff2' < 'diff'
    			diff = 'diff2'
    			noteindex = 'c'
    		endif
    	endfor
    	#Otherwise if there is not a C...
    	else
    	for c from 1 to 21
    		diff2 = abs('currentfreq' - scalenotes['c'])
    		if 'diff2' < 'diff'
    			diff = 'diff2'
    			noteindex = 'c'
    		endif
    	endfor
    	endif
    	#Add point at the original time with the new pitch
    	Add point... times['q'] scalenotes['noteindex']
    endfor

    http://schyzm.wordpress.com/2012/12/05/fun-with-praat-a-script-for-auto-tune/
    Скрипт питч-коррекции для речевого анализатора Praat на встроенном языке сценариев. Не знаю, это афтар так жжот или язык располагает к черезжопию, но что-то тут воняет однозначно.

    telnet, 17 Января 2013

    Комментарии (11)
  8. Куча / Говнокод #12403

    +136

    1. 1
    http://f.cl.ly/items/1B362r0E3T0z3E3v3A1f/Screen%20Shot%202013-01-10%20at%2011.01.45.png

    Это надо видеть.

    ArtFeel, 10 Января 2013

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

    +69

    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
    //А теперь я научу вас как правильно определять тип картинки
    $type = '';
    		
    # JPEG:
    $src = @imagecreatefromjpeg("./js/ajax_drag_drop_upload/php/files/".$f);
    if ($src !== false)
    {
    	$type = 'jpg';
    }
    else {
    	# GIF:
    	$src = @imagecreatefromgif("./js/ajax_drag_drop_upload/php/files/".$f);
    	if ($src !== false)
    	{
    		$type = 'gif';
    	}
    	else {
    		# PNG:
    		$src = @imagecreatefrompng("./js/ajax_drag_drop_upload/php/files/".$f);
    		if ($src !== false)
    		{
    			$type = 'png';
    		}
    	}	
            // А что делать с BMP? Та ну нафиг, BMP - это миф...
    }
    // Вот и все. Теперь вы знаете с каким типом картинки работаете
    // Ну а здесь уже можете писать ваш говнокод

    Очень эпичный code snippet. Посмотрите как автор ловко владеет возможностями языка PHP. В закладки!

    SunnyMagadan, 10 Января 2013

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

    +73

    1. 1
    2. 2
    3. 3
    4. 4
    5. 5
    6. 6
    7. 7
    8. 8
    9. 9
    if (jsonValues.toString().contains("acctContext") == true) {
        try {
            objectRelMethod = impl.provisionDevice(
    	jsonValues.getString("acctContext"),
    	jsonValues.getString("persoIdentityRequest"));
         }catch(JSONException e){
    	objectRelMethod = impl.provisionDevice(null, null);
         }
    }

    и туда же... и это называется гордым словом "мидл"...

    myzone, 21 Декабря 2012

    Комментарии (11)
  11. Java / Говнокод #12324

    +70

    1. 1
    2. 2
    3. 3
    4. 4
    5. 5
    6. 6
    7. 7
    if (!formules.isEmpty()) {
        for (String tag : formules) {
        .....
        // и вот здесь шедевр:
        }
        // а здесь ничего нет
    }

    Не гоняем цикл вхолостую

    alopen, 21 Декабря 2012

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