1. Objective C / Говнокод #17902

    −403

    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
    if (indexPath.row == 0) {
            if (![centerViewController isKindOfClass:[T7DUserInfoViewController class]]) {
                T7DUserInfoViewController *userViewController = [[T7DUserInfoViewController alloc] init];
                [navigationController popViewControllerAnimated:NO];
                [navigationController pushViewController:userViewController animated:NO];
            }
        }
        if (indexPath.row == 1) {
            if (![centerViewController isKindOfClass:[T7DMapViewController class]]) {
                T7DMapViewController *mapViewController = [[T7DMapViewController alloc] init];
                [navigationController popViewControllerAnimated:NO];
                [navigationController pushViewController:mapViewController animated:NO];
            }
        }
        if (indexPath.row == 2) {
            if (![centerViewController isKindOfClass:[T7DOrderListViewController class]]) {
                T7DOrderListViewController *orderListViewController = [[T7DOrderListViewController alloc] init];
                [navigationController popViewControllerAnimated:NO];
                [navigationController pushViewController:orderListViewController animated:NO];
            }
        }
        if (indexPath.row == 3) {
            if (![centerViewController isKindOfClass:[T7DCurrentOrderViewController class]]) {
                T7DCurrentOrderViewController *orderViewController = [[T7DCurrentOrderViewController alloc] init];
                [orderViewController setOrderType:T7DOrderTypeCurrent];
                [orderViewController setOrder:[T7DOrder currentOrder]];
                [navigationController popViewControllerAnimated:NO];
                [navigationController pushViewController:orderViewController animated:NO];
            }
        }
        if (indexPath.row == 4) {
            if (![centerViewController isKindOfClass:[T7DMessagesViewController class]]) {
                T7DMessagesViewController *messagesViewConroller = [[T7DMessagesViewController alloc] init];
                [navigationController popViewControllerAnimated:NO];
                [navigationController pushViewController:messagesViewConroller animated:NO];
            }
        }
        if (indexPath.row == 5) {
            [self logout];
            return;
        }

    Мудаки.

    pr0gl, 31 Марта 2015

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

    +59

    1. 01
    2. 02
    3. 03
    4. 04
    5. 05
    6. 06
    7. 07
    8. 08
    9. 09
    10. 10
    int getObjectsCount() const { ... }
    ...
    void restoreObjects()
    {
        ...
        const unsigned int objectsCount = restoreInt();
    
        assert(objectsCount == objects.getObjectsCount());
        ...
    }

    Ансайнд, туда и обратно

    atsgovno, 31 Марта 2015

    Комментарии (1)
  3. Си / Говнокод #17899

    +137

    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
    for (i = 1; i < argc; i++) {
    		p = argv[i];
    		if ((*p != '-') && (*p != '/'))
    		{
    			printf("Unknown option %s\n", p);
    			return 1;
    		}
    		p++;
    		if (strncmp(p, "pcir=", 5) == 0)	
    		{
    			sscanf(p+5, "%lli", &pci_raddr);
    			opt |= 1;
    		}
    		if (strncmp(p, "pciw=", 5) == 0)
    		{
    			sscanf(p+5, "%lli", &pci_waddr);
    			opt |= 2;
    		}
    		if (strncmp(p, "rwlen=", 6) == 0)
    			sscanf(p+6, "%i", &rwlen);
    		if (strncmp(p, "count=", 6) == 0)
    			sscanf(p+6, "%i", &count);
    		if (strncmp(p, "ch=", 3) == 0)
    			channel = p+3;
    		if (strncmp(p, "poll", 4) == 0)
    			poll = 1;
    		if (strncmp(p, "fpga_read=", 10) == 0)
    		{
    			sscanf(p+10, "%i", &offset);
    			fpga_read_flag = 1;
    		}
    		if (strncmp(p, "fpga_write=", 11) == 0)
    		{
    			sscanf(p+11, "%i", &offset);
    			fpga_write_flag = 1;
    		}
    		if (strncmp(p, "data=", 5) == 0)
    		{
    			sscanf(p+5, "%i", &data);
    			data_valid = 1;
    		}
    
    		if (strncmp(p, "dump_to_file=", 13) == 0)
    		{
    			filename = p+13;
    			dump_to_file = 1;
    		}
    		if (strncmp(p, "loadnios", 8) == 0)
    		{
    			filename = p+8;
    			load_nios = 1;
    		}
    		if (strncmp(p, "DUMP", 4) == 0) // -DUMP
    			dump = 1;
    		if (strncmp(p, "flash_read", 10) == 0) // -flash_read
    		{
    			flash_read_flag = 1;
    		}
    
    		if (strncmp(p, "file_to_flash", 13) == 0) // -file_to_flash
    			file_to_flash = 1;
    		if (strncmp(p, "file=", 5) == 0) // -file
    		{
    			fname = p+5;
    		}
    
    		if (strncmp(p, "base=", 5) == 0) // -base
    		{
    			sscanf(p+5, "%i", &base);
    			basevalid = 1;
    		}
    		if (strncmp(p, "card=", 5) == 0) // -crd
    			sscanf(p+5, "%i", &card);
    		if (strncmp(p, "ver", 3) == 0)
    			ver = 1;
    		if (strncmp(p, "dev=", 4) == 0) // -deм
    			dev = p+4;
    	}

    "А я напишу свой собственный комманд лайн парсер, с хуитой и говном"

    codemonkey, 31 Марта 2015

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

    +157

    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
    var times, source_date,
          date = "20.11.2014";
    
    if (date) {
                times = date.split('.');
    
                source_date = new Date();
                source_date.setFullYear(parseInt(times[2]));
                source_date.setMonth(parseInt(times[1]) - 1);
    
                source_date.setDate(parseInt(times[0]));
    }
    
    return source_date ;

    darkartur, 31 Марта 2015

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

    +166

    1. 1
    2. 2
    3. 3
    4. 4
    5. 5
    6. 6
    7. 7
    8. 8
    9. 9
    public function isRequisitesCorrect()
        {
            switch (true) {
                case $this->isRequisitesSigned() :
                    return true;
                default:
                    return false;
            }
        }

    dimkich, 31 Марта 2015

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

    −117

    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
    def onRefreshReaders( self, event ):
    
    		#try:
    			self.readersListBox.Clear()
    			readers = self.burner.getReaders()
    
    			if isinstance(readers,BaseException):
    				raise BaseException("Can't find burner app!")
    
    			self.readersListBox.AppendItems(  readers)
    			self.readersListBox.SetSelection( 0 )
    		#except OSError as e:
    			#wx.MessageBox("Signer cant be empty!\n", "Error",wx.OK | wx.ICON_ERROR)

    qj,fysqhjn

    Anus, 31 Марта 2015

    Комментарии (10)
  7. C++ / Говнокод #17895

    +58

    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
    #include "stdafx.h"
    #define n 3
    
    void PrintMatrix(vector<vector<float> >imatrix)
    {
    	for (size_t i = 0; i < n; ++i)
    	{
    		cout << endl;
    		for (size_t j = 0; j < n; ++j)
    		{
    			cout.precision(3);
    			cout << " " << imatrix[i][j];
    		}
    	}
    }
    
    void ReverseMatrix(vector<vector<float> >imatrix, float determ)
    {
    	float t = 0;
    	for (size_t i = 0; i < n; i++)
    	{
    		for (size_t j = 0; j < n; j++)
    		{
    			t = imatrix[i][j] * (1 / determ);
    			imatrix[i][j] = t;
    		}
    	}
    	PrintMatrix(imatrix);
    }
    
    void TransposedMatrix(vector<vector<float> >imatrix, float determ)
    {
    	float t = 0;
    	for (size_t i = 0; i < n; i++)
    	{
    		for (size_t j = i; j < n; j++)
    		{
    			t = imatrix[i][j];
    			imatrix[i][j] = imatrix[j][i];
    			imatrix[j][i] = t;
    		}
    	}
    	ReverseMatrix(imatrix, determ);
    }
    
    void MinorMatrix(vector<vector<float> >imatrix, float determ)
    {
    	vector<vector<float> >imatrix2(n);
    	float t = 0.0;
    	for (size_t i = 0; i < n; ++i)
    	{
    		imatrix2[i].resize(n);
    		for (size_t j = 0; j < n; ++j)
    		{
    			if (i == 0)
    			{
    				switch (j){
    				case 0: imatrix2[i][j] = imatrix[i + 1][j + 1] * imatrix[i + 2][j + 2] - imatrix[i + 1][j + 2] * imatrix[i + 2][j + 1]; t = imatrix2[i][j];break;
    				case 1: imatrix2[i][j] = (imatrix[i + 1][j - 1] * imatrix[i + 2][j + 1] - imatrix[i + 2][j - 1] * imatrix[i + 1][j + 1]) * (-1); t = imatrix[i][j]; break;
    				case 2: imatrix2[i][j] = imatrix[i + 1][j - 2] * imatrix[i + 2][j - 1] - imatrix[i + 1][j - 1] * imatrix[i + 2][j - 2];t = imatrix2[i][j];break;
    				}
    			}
    			if (i == 1)
    			{
    				switch (j){
    				case 0: imatrix2[i][j] = (imatrix[i - 1][j + 1] * imatrix[i + 1][j + 2] - imatrix[i - 1][j + 2] * imatrix[i + 1][j + 1]) * (-1);t = imatrix2[i][j];break;
    				case 1:imatrix2[i][j] = imatrix[i - 1][j - 1] * imatrix[i + 1][j + 1] - imatrix[i - 1][j + 1] * imatrix[i + 1][j - 1];t = imatrix2[i][j];break;
    				case 2:imatrix2[i][j] = (imatrix[i - 1][j - 2] * imatrix[i + 1][j - 1] - imatrix[i - 1][j - 1] * imatrix[i + 1][j - 2]) * (-1);t = imatrix2[i][j];break;
    				}
    			}
    			if (i == 2)
    			{
    				switch (j){
    				case 0: imatrix2[i][j] = imatrix[i - 2][j + 1] * imatrix[i - 1][j + 2] - imatrix[i - 1][j + 1] * imatrix[i - 2][j + 2];t = imatrix2[i][j];break;
    				case 1:imatrix2[i][j] = (imatrix[i - 2][j - 1] * imatrix[i - 1][j + 1] - imatrix[i - 1][j - 1] * imatrix[i - 2][j + 1]) * (-1);t = imatrix2[i][j];break;
    				case 2: imatrix2[i][j] = imatrix[i - 2][j - 2] * imatrix[i - 1][j - 1] - imatrix[i - 2][j - 1] * imatrix[i - 1][j - 2];t = imatrix2[i][j];break;
    				}
    			}
    		}
    	}
    	imatrix.clear();
    	TransposedMatrix(imatrix2, determ);
    }
    
    void FindDeterminant(vector<vector<float> >imatrix)
    {
    	float determ = imatrix[0][0] * imatrix[1][1] * imatrix[2][2] + imatrix[2][0] * imatrix[0][1] * imatrix[1][2] + imatrix[1][0] * imatrix[2][1] * imatrix[0][2] - imatrix[2][0] * imatrix[1][1] * imatrix[0][2] - imatrix[0][0] * imatrix[2][1] * imatrix[1][2] - imatrix[1][0] * imatrix[0][1] * imatrix[2][2];
    	if (determ == 0)
    	{
    		cout << "Determinant = 0 ==> Reverse matrix doesn't exist";
    		system("pause");
    		exit(0);
    	}
    	MinorMatrix(imatrix, determ);
    }

    Вот таких студентов учить приходится. От оно как матрицы 3*3 инвертируют.
    Больше лучей ненависти тут:
    https://github.com/PLaGInc/Lab1/issues/3

    Vivid, 31 Марта 2015

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

    +129

    1. 01
    2. 02
    3. 03
    4. 04
    5. 05
    6. 06
    7. 07
    8. 08
    9. 09
    10. 10
    11. 11
    for(const auto & row : table; const auto & element : row) {
        handle(element);
    }
    
    // versus
    
    for(const auto & row : table) {
        for(const auto & element : row) {
            handle(element);
        }
    }

    Всякого ненужного говна в новые крестостандарты насовали, а о простых вещах не подумали. Ну ведь удобней же было бы!
    Но не-ет, нам нужна функциональщина в крестах, ведь нам мало мозгоклюйства с другими языками; а давайте засунем в стандартную библиотеку либкайро, чтобы разработчики стандартных библиотек соревновались, кто быстрее запилит частичную поддержку в 95% случаев ненужной либы полутра операционными системами, куда-ах-тах-тах!
    Забавно, только что узнал, что в vs2013 есть шорткат ^ko, который переключает между заголовком и реализацией. ^ko^ko^ko

    Xom94ok, 30 Марта 2015

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

    +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
    int fpga_read(char *dev, unsigned int base_addr, unsigned int offset, int len, unsigned char *buf)
    {
        unsigned long long pci_raddr;
        int actual;
        FILE    *fi;
    
        fi = fopen(dev, "r");
        if (fi == NULL) {
            printf("Failed to read from FPGA - Error opening device\n");
            return 1;
        }
    
        pci_raddr = (unsigned long long) 2 << 32 | (base_addr + offset);
        setvbuf(fi, NULL, _IONBF, 0);       // disable file buffering
        fseeko(fi, pci_raddr, SEEK_SET);        // go to the address
        actual = fread(buf, 1, len, fi);        // read the data
        fclose(fi);
        if (actual <= 0) {
            printf("Error  %d reading from device (dev %s, base addr 0x%x, offset 0x%x, len %i)\n", errno, dev, base_addr, offset, len);
            return 2;
        }
        return 0;
    }

    По многочисленным просьбам говнокодеров, выделил в отдельный пост.

    codemonkey, 30 Марта 2015

    Комментарии (3)
  10. Си / Говнокод #17892

    +131

    1. 1
    2. 2
    3. 3
    4. 4
    5. 5
    fi = fopen("kokoko.tmp", "rb");
    
            fseek(fi, 0, SEEK_END);
            file_size = ftell(fi);
            fseek(fi, 0, SEEK_SET);

    rewind? system call? Не, не слышали.

    codemonkey, 30 Марта 2015

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