1. Си / Говнокод #11431

    +141

    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
    92. 92
    93. 93
    94. 94
    95. 95
    char **fpwd=(char**)malloc(160);
    int lstat(const char *path, struct stat *buf);
    int process_dir(const char *dir,struct stat *st1,ino_t cit);
    char *cdir=".";
    ino_t ci=0;
    struct stat cstat;
    int errors = 0;
    char *myname;
    int cnt=0;
    int main(int argc,char **argv){
      myname=argv[0];
      cdir=(char*)malloc(512);
      if(cdir==NULL){
        perror("Not sufficient memory");
        errors++;
        return -1;
      }
       memset(cdir,'\0',512);
      strcat(cdir,cdir);
      strcat(cdir,".");
      if(fpwd==NULL){
        fprintf(stderr, "%s: out of memory: %s\n",
      			myname, strerror(errno));
      		errors++;
     		return 0;
     }
    for(int i=0;i<=160;i++){
      *(fpwd+i)=(char*)malloc(1600);
     if(*(fpwd+i)==NULL){perror("Not sufficient memory");
     errors++;
     return -1;
     }
    }
    while(ci!=2){
      if(lstat(".",&cstat)==-1){
        fprintf(stderr, "%s: can't find file:%s %s\n",
     			myname, cdir, strerror(errno));
        errors++;
    	return -1;
      };
      ci=cstat.st_ino;
      if(process_dir("..",&cstat,ci)==-1){
            fprintf(stderr, "%s: can't process dir:%s %s\n",
     			myname, cdir, strerror(errno));
        errors++;
    	return -1;
      };
      int fd=open("..",O_RDONLY);
      if(fd<0){
       perror("open");
       errors++;return -1;
      }
        if(fchdir(fd)==-1){
          fprintf(stderr, "%s: can't chdir:%s\n",
     			myname, strerror(errno));
        errors++;return -1;
        };
        strcat(cdir,"/..");
    }
     for(int i=cnt-1;i>=0;i--){
        printf("/%s",fpwd[i]);
      }
      printf("\n");return 0;
    }
    int process_dir(const char *dir,struct stat *st1,ino_t cit/*,char **fpwd*/){
        DIR *dp;
        struct dirent *ent;
        struct stat *dstat;
        if ((dp = opendir(dir)) == NULL) {
    		fprintf(stderr, "%s: cannot open for reading: %s\n", dir, strerror(errno));errors++;return -1;
    	}
        if(lstat(dir,dstat)==-1){
    	    fprintf(stderr, "%s: can't find file:%s %s\n",
     			myname, cdir, strerror(errno));
    			errors++;
    	return -1;
          }
    	while ((ent = readdir(dp)) != NULL){
    	  if(ent->d_ino==cit && strcmp(ent->d_name,".")!=0 && strcmp(ent->d_name,"..")!=0){
    	    strcat(fpwd[cnt++],ent->d_name);
    	     if (closedir(dp) != 0) {
    		fprintf(stderr, "%s: closedir: %s\n", dir, strerror(errno));
    		errors++;
    		return 1;
    	      }
    	    return 0;
    	  }
    	}
    	if (closedir(dp) != 0) {
    		fprintf(stderr, "%s: closedir: %s\n", dir, strerror(errno));
    		errors++;
    		return 1;
    	}
    	return 0;
    }

    AliceGoth, 17 Июля 2012

    Комментарии (0)
  2. Куча / Говнокод #11429

    +124

    1. 1
    2. 2
    3. 3
    4. 4
    5. 5
    6. 6
    [2012-07-17 15:01:19] emulator-5554 disconnected! Cancelling 'android.app.NativeActivity activity launch'!
    [2012-07-17 15:38:41] emulator-5554 disconnected! Cancelling 'android.app.NativeActivity activity launch'!
    [2012-07-17 15:53:21] emulator-5554 disconnected! Cancelling 'android.app.NativeActivity activity launch'!
    [2012-07-17 16:12:18] emulator-5554 disconnected! Cancelling 'android.app.NativeActivity activity launch'!
    [2012-07-17 16:25:06] emulator-5554 disconnected! Cancelling 'android.app.NativeActivity activity launch'!
    [2012-07-17 16:40:48] emulator-5554 disconnected! Cancelling 'android.app.NativeActivity activity launch'!

    http://startandroid.ru/uroki/vse-uroki-spiskom/12-urok-3-sozdanie-avd-pervoe-prilozhenie-struktura-android-proekta.html

    Если не получилось запустить и Eclipse вывел в консоль подобное сообщение: "emulator-5554 disconnected! Cancelling 'ru.startandroid.develop.OurFirstProject .MainAct activity launch'!" - то закройте эмулятор, и попробуйте снова. Если снова не получилось. перезапустите Eclipse. Если опять нет - ребутнитесь. Если и сейчас не работает, удалите AVD и создайте новый. В итоге должно заработать, пусть и не с первой попытки.

    Главное - после запуска приложения (CTRL+F11) старайтесь совершать как можно меньше движений на компе. Я заметил четкую тенденцию - если во время запуска переключаться между различными окнами, то эмулятор запускается криво. А если просто посидеть и подождать минутку - то все ок. Ну и надо чтоб при этом не было включено какое-нить кодирование видео или прочие, нагружающие систему процедуры.

    Если не получилось, попробуйте ещё раз...
    Если снова не получилось, попробуйте ещё раз...
    Если снова не получилось, попробуйте ещё раз...
    Если снова не получилось, попробуйте ещё раз...
    Если снова не получилось, попробуйте ещё раз...
    Если снова не получилось, попробуйте ещё раз...

    TarasB, 17 Июля 2012

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

    +64

    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
    /**
       * Analyzes the supplied result to see if it was thrown
       * because the access token is no longer valid.  If that is
       * the case, then we destroy the session.
       *
       * @param $result array A record storing the error message returned
       *                      by a failed API call.
       */
      protected function throwAPIException($result) {
        $e = new FacebookApiException($result);
        switch ($e->getType()) {
          // OAuth 2.0 Draft 00 style
          case 'OAuthException':
            // OAuth 2.0 Draft 10 style
          case 'invalid_token':
            // REST server errors are just Exceptions
          case 'Exception':
            $message = $e->getMessage();
            if ((strpos($message, 'Error validating access token') !== false) ||
                (strpos($message, 'Invalid OAuth access token') !== false) ||
                (strpos($message, 'An active access token must be used') !== false)
            ) {
              $this->destroySession();
            }
            break;
        }
    
        throw $e;
      }

    Я даже не зняю, что хуже, определение типа исключения по тексту ошибки, или использование одного и того же исключения, для всех ситуаций.

    ЗЫ: Это SDK от facebook.

    korchasa, 17 Июля 2012

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

    +81

    1. 1
    2. 2
    3. 3
    4. 4
    5. 5
    int i=0;
            for (;i<5;
                 printf("%d",i);
                 i++;
                 );

    ZevsVU, 17 Июля 2012

    Комментарии (27)
  5. C++ / Говнокод #11426

    +30

    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
    InputMapping* GetInputMapping(unsigned int index)
        {
            InputMapping* inputMapping = NULL;
    
            switch (index)
            {
                // Movement
            case 0:
                return &m_LeftStickMapping[InputBindings::StickDirUp];
            case 1:
                return &m_LeftStickMapping[InputBindings::StickDirDown];
            case 2:
                return &m_LeftStickMapping[InputBindings::StickDirLeft];
            case 3:
                return &m_LeftStickMapping[InputBindings::StickDirRight];
    
                // Actions
            case 4:
                return &m_ButtonMappings[Pad::ShoulderRight1];
            case 5:
                return &m_ButtonMappings[Pad::Button2];
            case 6:
                return &m_ButtonMappings[Pad::Button4];
            case 7:
                return &m_ButtonMappings[Pad::Button3];
            case 8:
                return &m_ButtonMappings[Pad::Button1];
    
                // Weapons
            case 9:
                return &m_ButtonMappings[Pad::PadLeft];
            case 10:
                return &m_ButtonMappings[Pad::PadUp];
            case 11:
                return &m_ButtonMappings[Pad::PadRight];
            case 12:
                return &m_ButtonMappings[Pad::PadDown];
            case 13:    // weapon wheel
                return &m_ButtonMappings[Pad::ShoulderRight2];
    
                // Camera
            case 14:
                return &m_RightStickMapping[InputBindings::StickDirUp];
            case 15:
                return &m_RightStickMapping[InputBindings::StickDirDown];
            case 16:
                return &m_RightStickMapping[InputBindings::StickDirLeft];
            case 17:
                return &m_RightStickMapping[InputBindings::StickDirRight];
            case 18:
                return &m_ButtonMappings[Pad::ShoulderLeft1];
            case 19:
                return &m_ButtonMappings[Pad::ShoulderLeft2];
            case 20:
                return &m_ButtonMappings[Pad::StickRight];
    
                // Menus
            case 21:
                return &m_ButtonMappings[Pad::Select];
            case 22:
                return &m_ButtonMappings[Pad::Start];
    
                // First-person camera
            case 23:
                return &m_ButtonMappings[Pad::StickLeft];
            default:
                return NULL;
            }
            return NULL;
        }

    Массивы? Не, не слышал.

    bazhenovc, 17 Июля 2012

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

    +20

    1. 1
    2. 2
    3. 3
    4. 4
    5. 5
    6. 6
    7. 7
    8. 8
    9. 9
    void File::open(string file, bool readAccess, bool writeAccess, bool append)
    {
    	Close();
    	(string&)Name=file;
    	const char* const modes[2][2][2]={{{null, "rb"}, {"wb", "w+b"}}, {{null, null}, {"ab", "a+b"}}};
    	if(modes[append][writeAccess][readAccess]==null) return InternalError("Создание файла с неверными параметрами!");
    	handle=fopen(Name.CStr(), modes[append][writeAccess][readAccess]);
    	if(handle==null) throw NotFoundException(string::Format("Файл <^> не найден!")(file));
    }

    Скорее всего, этот код вам покажется странным, поэтому я его выкладываю. Хотя я его говнокодом не считаю и он мне даже нравится.

    gammaker, 16 Июля 2012

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

    +156

    1. 1
    2. 2
    3. 3
    4. 4
    5. 5
    6. 6
    7. 7
    var empty = true;
                _.each(records, function (val, key) {
                    if (records.hasOwnProperty(key)) {
                        empty = false;
                    }
    
                });

    изза того что в прототипы стандартных Object и Array напихали всяких методов типа .max .each приходится так проверять объект на пустоту)

    nur, 16 Июля 2012

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

    +121

    1. 1
    (reverse (butlast ...))

    Родное :)

    wvxvw, 16 Июля 2012

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

    +72

    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
    function valid_gender($str){
    	switch($str){
    		case "male":
    		return "male";
    		break;
    
    		case "female":
    		return "female";
    		break;
    
    		default:
    		return "male";
    		break;
    	}
    }

    Ультимативная проверка переменной на половую принадлежность. Also return'ам нынче доверия нет!

    swiftfooth, 16 Июля 2012

    Комментарии (41)
  10. VisualBasic / Говнокод #11421

    −98

    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
    Private Sub Command2_Click()
    Cls
    For x = 1 To Text2 + 1
    For y = 1 To Text2 + 1
    A(x, y) = Round(Rnd(1))
    If A(x, y) = 0 Then A(x, y) = -1
    Next
    Next
    For x = 2 To Text2
    For y = 2 To Text2
    PSet (1200 + x * 15, 200 + y * 15), A(x, y)
    Next
    Next
    End Sub
    
    Private Sub Command3_Click()
    Cls
    For x = 1 To Text2 + 1
    For y = 1 To Text2 + 1
    A(x, y) = 1
    Next
    Next
    A(Text20, Text21) = -1
    A(Text22, Text23) = -1
    A(Text24, Text25) = -1
    A(Text26, Text27) = -1
    For x = 2 To Text2
    For y = 2 To Text2
    PSet (1200 + x * 15, 200 + y * 15), A(x, y)
    Next
    Next
    End Sub
    
    Private Sub Form_Load()
    
    For x = 1 To Text2 + 1
    For y = 1 To Text2 + 1
    A(x, y) = Round(Rnd(1))
    If A(x, y) = 0 Then A(x, y) = -1
    Next
    Next
    
    
    
    'For x = 1 To Text2 + 1
    'For y = 1 To Text2 + 1
    'A(x, y) = 1
    'Next
    'Next
    'A(10, 10) = -1
    
    
    
    End Sub
    
    Private Sub Command1_Click()
    Cls
    
    For k = 1 To Text1
    
    For x = 1 To Text2 + 1
    A(x, 1) = A(x, Text2)
    A(x, Text2 + 1) = A(x, 2)
    Next
    
    For y = 1 To Text2 + 1
    A(1, y) = A(Text2, y)
    A(Text2 + 1, y) = A(2, y)
    Next
    
    
    
    For x = 2 To Text2
    For y = 2 To Text2
    
    xp = A(x - 1, y - 1) + A(x, y - 1) + A(x + 1, y - 1) + A(x - 1, y) + A(x + 1, y) + A(x - 1, y + 1) + A(x, y + 1) + A(x + 1, y + 1)
    Select Case xp
    Case -8
    B(x, y) = Text3
    Case -7
    B(x, y) = Text4
    Case -6
    B(x, y) = Text5
    Case -5
    B(x, y) = Text6
    Case -4
    B(x, y) = Text7
    Case -3
    B(x, y) = Text8
    Case -2
    B(x, y) = Text9
    Case -1
    B(x, y) = Text10
    Case 0
    B(x, y) = Text11
    Case 1
    B(x, y) = Text12
    Case 2
    B(x, y) = Text13
    Case 3

    Жестокий, безумный мозг пятнадцатилетнего пацана родил клеточный автомат. Нашел свои исходники десятилетней давности.
    А ведь я себя тогда считал крутым программистом... стыдно вспоминать.

    xcont, 16 Июля 2012

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