1. PHP / Говнокод #23354

    +4

    1. 1
    2. 2
    3. 3
    if (preg_match('/'.preg_quote($subString).'/', $string)) {
        ...
    }

    Проверка, есть ли подстрока в строке.
    Вроде, как минимум несколько лет человек в программировании на PHP.
    Показывает опытность тем, что экранирует спецсимволы в регулярном выражении.
    А можно было использовать простейшую функцию strpos().

    zlsoft, 22 Сентября 2017

    Комментарии (16)
  2. PHP / Говнокод #23353

    +4

    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
    // ...
    if (isset($_GET["download"])) {
    	include "./download.inc.php";
    } elseif (isset($_GET["table"])) {
    	include "./table.inc.php";
    } elseif (isset($_GET["schema"])) {
    	include "./schema.inc.php";
    } elseif (isset($_GET["dump"])) {
    	include "./dump.inc.php";
    } elseif (isset($_GET["privileges"])) {
    	include "./privileges.inc.php";
    } elseif (isset($_GET["sql"])) {
    	include "./sql.inc.php";
    } elseif (isset($_GET["edit"])) {
    	include "./edit.inc.php";
    } elseif (isset($_GET["create"])) {
    	include "./create.inc.php";
    } elseif (isset($_GET["indexes"])) {
    	include "./indexes.inc.php";
    } elseif (isset($_GET["database"])) {
    	include "./database.inc.php";
    } elseif (isset($_GET["scheme"])) {
    	include "./scheme.inc.php";
    } elseif (isset($_GET["call"])) {
    	include "./call.inc.php";
    } elseif (isset($_GET["foreign"])) {
    	include "./foreign.inc.php";
    } elseif (isset($_GET["view"])) {
    	include "./view.inc.php";
    } elseif (isset($_GET["event"])) {
    	include "./event.inc.php";
    } elseif (isset($_GET["procedure"])) {
    	include "./procedure.inc.php";
    } elseif (isset($_GET["sequence"])) {
    	include "./sequence.inc.php";
    } elseif (isset($_GET["type"])) {
    	include "./type.inc.php";
    } elseif (isset($_GET["trigger"])) {
    	include "./trigger.inc.php";
    } elseif (isset($_GET["user"])) {
    	include "./user.inc.php";
    } elseif (isset($_GET["processlist"])) {
    	include "./processlist.inc.php";
    } elseif (isset($_GET["select"])) {
    	include "./select.inc.php";
    } elseif (isset($_GET["variables"])) {
    	include "./variables.inc.php";
    } elseif (isset($_GET["script"])) {
    	include "./script.inc.php";
    } else {
    	include "./db.inc.php";
    }
    // ...

    https://github.com/vrana/adminer/blob/master/adminer/index.php
    p.s хотя сама штука полезная, пару раз выручала

    alex228, 22 Сентября 2017

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

    0

    1. 01
    2. 02
    3. 03
    4. 04
    5. 05
    6. 06
    7. 07
    8. 08
    9. 09
    10. 10
    bool valueToString(std::string_view str, float& value) try {
        const auto end = std::numeric_limits<std::size_t>::max();
        const float parsed = std::stof(str.data(), &end);
        if (end != str.size())
            return false;
        value = parsed;
        return true;
    } catch (...) {
        return false;
    }

    string_view пирформанс! Спойлер: да, там std::stof

    Elvenfighter, 22 Сентября 2017

    Комментарии (7)
  4. SQL / Говнокод #23351

    0

    1. 1
    SELECT * FROM order WHERE coalesce(cancelation_date,\'7777-07-07\'::DATE) >= :tdDate

    iworld, 22 Сентября 2017

    Комментарии (0)
  5. Си / Говнокод #23350

    +4

    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
    96. 96
    97. 97
    98. 98
    99. 99
    #include<stdio.h>
    #include<math.h>
    
    int const n = 50, n1 = 40, m = n / n1;
    double f1(double t, double x, double y, double z);
    double f2(double t, double x, double y, double z);
    double f3(double t, double x, double y, double z);
    
    int main() {
    	int i, k, ll;
    	double k11, k12, k13, k21, k22, k23, k31, k32, k33, k14, k24, k34;
    	double x, y, z, max;
    	double res[12][n1 + 1], h, a, b, t, pi, xn, yn, zn;
    	max = 1000.0; x = 3.0;
    	y = -2.0; z = -3.0;
    	a = 0.0; b = 1.0;
    	h = (b - a) / double(n);
    
    	k = 0; t = a;
    	res[0][0] = t; res[1][0] = x;
    	res[2][0] = y;
    	res[3][0] = z;
    	for (i = 1; i <= n; i++) {
    		k11 = f1(t, x, y, z);
    		k21 = f2(t, x, y, z);
    		k31 = f3(t, x, y, z);
    		k12 = f1(t + h / 2.0, x + h*k11 / 2.0, y + h*k21 / 2.0, z + h*k31 / 2.0);
    		k22 = f2(t + h / 2.0, x + h*k11 / 2.0, y + h*k21 / 2.0, z + h*k31 / 2.0);
    		k32 = f3(t + h / 2.0, x + h*k11 / 2.0, y + h*k21 / 2.0, z + h*k31 / 2.0);
    		k13 = f1(t + h / 2.0, x + h*k12 / 2.0, y + h*k22 / 2.0, z + h*k32 / 2.0);
    		k23 = f2(t + h / 2.0, x + h*k12 / 2.0, y + h*k22 / 2.0, z + h*k32 / 2.0);
    		k33 = f3(t + h / 2.0, x + h*k12 / 2.0, y + h*k22 / 2.0, z + h*k32 / 2.0);
    		k14 = f1(t + h, x + h*k13, y + h*k23, z + h*k33);
    		k24 = f2(t + h, x + h*k13, y + h*k23, z + h*k33);
    		k34 = f3(t + h, x + h*k13, y + h*k23, z + h*k33);
    		x = x + h*(k11 + 2.0*(k12 + k13) + k14) / 6.0;
    		y = y + h*(k21 + 2.0*(k22 + k23) + k24) / 6.0;
    		z = z + h*(k31 + 2.0*(k32 + k33) + k34) / 6.0;
    		t = t + h;
    		if (i%m == 0) {
    			k = k + 1;
    			res[0][k] = t;
    			res[1][k] = x;
    			res[2][k] = y;
    			res[3][k] = z;
    			res[4][k] = exp(t) + exp(2.0*t) + exp(-t);
    			res[5][k] = exp(t) - 3.0*exp(-t);
    			res[6][k] = exp(t) + exp(2.0*t) - 5.0*exp(-t);
    			res[7][k] = res[4][k] - res[1][k];
    			res[8][k] = res[5][k] - res[2][k];
    			res[9][k] = res[6][k] - res[3][k];
    		} if (res[7][k] < 0.0) {
    			res[7][k] = -res[7][k];
    		}
    		else if (res[8][k] < 0.0) {
    			res[8][k] = -res[8][k];
    		}
    		else if (res[9][k] < 0.0) {
    			res[9][k] = -res[9][k];
    		}
    		res[10][k] = res[7][k] + res[8][k] + res[9][k];
    	}
    
    	ll = k;
    	printf("k=%d\n", ll);
    	for (i = 0; i <= ll; i++) {
    		if (res[10][i] < max) max = res[10][i];
    	} for (i = 0; i <= n1; i++) {
    		printf("t=%.16lf\n", res[0][i]);
    		printf("x=%.16lf x(exact)=%.16lf delta=%.16lf\n", res[1][k], res[4][k], res[1][k] - res[4][k]);
    		printf("y=%.16lf y(exact)=%.16lf delta=%.16lf \n", res[2][k], res[5][k], res[2][k] - res[5][k]);
    		printf("z=%.16lf z(exact)=%.16lf delta=%.16lf \n", res[3][k], res[6][k], res[3][k] - res[6][k]);
    	}
    	printf("result:\n");
    	printf("t=%.16lf\n", res[0][n1]);
    	printf("x=%.16lf x(exact)=%.16lf delta=%.16lf\n", res[1][n1], res[4][n1], res[1][n1] - res[4][n1]);
    	printf("y=%.16lf y(exact)=%.16lf delta=%.16lf \n", res[2][n1], res[5][n1], res[2][n1] - res[5][n1]);
    	printf("z=%.16lf z(exact)=%.16lf delta=%.16lf \n", res[3][n1], res[6][n1], res[3][n1] - res[6][n1]);
    	printf("max norma|x|1=%.16lf \n", max / 3.0);
    
    	system("pause");
    
    	return 0;
    }
    
    double f1(double t, double x, double y, double z)
    {
    	return x + z - y;
    }
    
    double f2(double t, double x, double y, double z)
    {
    	return x + y - z;
    }
    
    double f3(double t, double x, double y, double z)
    {
    	return 2.0*x - y;
    }

    Кандидат физико-математических наук сделал методичку по предмету "Моделирование систем". Это он так описал алгоритм решения системы ОДУ методом Рунге-Кутты.

    mazazadah, 22 Сентября 2017

    Комментарии (58)
  6. bash / Говнокод #23349

    0

    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
    Connected to MongoDB!
    GET /api/v1/labels 200 185ms - 17.35kb
    GET /api/v1/labels 200 507ms - 17.35kb
    GET /api/v1/labels 200 168ms - 17.35kb
    GET /api/v1/labels 200 199ms - 17.35kb
    GET /api/v1/labels 200 161ms - 17.35kb
    GET /api/v1/labels 200 142ms - 17.35kb
    GET /api/v1/labels 200 193ms - 17.35kb
    GET /api/v1/labels 200 125ms - 17.35kb
    GET /api/v1/labels 200 10170ms - 17.35kb
    GET /api/v1/labels 200 152ms - 17.35kb
    GET /api/v1/labels 200 151ms - 17.35kb
    GET /api/v1/labels 200 141ms - 17.35kb
    GET /api/v1/labels 200 135ms - 17.35kb
    GET /api/v1/labels 200 122ms - 17.35kb
    GET /api/v1/labels 200 195ms - 17.35kb

    Обожаю MongoDB

    greshnik, 22 Сентября 2017

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

    +2

    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
    // https://github.com/vk-com/kphp-kdb/blob/ce6dead5b3345f4b38487cc9e45d55ced3dd7139/bayes/bayes-data.c#L569
      for (i = j = 0; v[i]; i++) {
        f[j] = i;
        if (v[i + 1] == '#' && (v[i] == '&' || v[i] == '$')) {
          int r = 0, ti = i;
          if (v[i + 2] != 'x') {
            for (i += 2; v[i] != ';' && v[i]; i++) {
              if ('0' <= v[i] && v[i] <= '9') {
                r = r * 10 + v[i] - '0';
              } else {
                break;
              }
            }
          } else {
            for (i += 3; v[i] != ';' && v[i]; i++) {
              if (('0' <= v[i] && v[i] <= '9') ||
                  ('a' <= v[i] && v[i] <= 'f') ||
                  ('A' <= v[i] && v[i] <= 'F')) {
                r = r * 16;
                if (v[i] <= '9') {
                  r += v[i] - '0';
                } else if (v[i] <= 'F') {
                  r += v[i] - 'A' + 10;
                } else {
                  r += v[i] - 'a' + 10;
                }
              } else {
                break;
              }
            }
          }
          if (r == 0) {
            bad[j] = 0;
            pv[j++] = v[i = ti];
          } else {
            bad[j] = 1;
            pv[j++] = r;
            if (v[i] != ';') {
              i--;
            }
          }
        } else if (v[i] == '%' && '0' <= v[i + 1] && v[i + 1] <= '7' &&
                                (('0' <= v[i + 2] && v[i + 2] <= '9') ||
                                 ('a' <= v[i + 2] && v[i + 2] <= 'f') ||
                                 ('A' <= v[i + 2] && v[i + 2] <= 'F'))) {
          int r = (v[i + 1] - '0') * 16;
          if (v[i + 2] <= '9') {
            r += v[i + 2] - '0';
          } else if (v[i + 2] <= 'F') {
            r += v[i + 2] - 'A' + 10;
          } else {
            r += v[i + 2] - 'a' + 10;
          }
          i += 2;
          if (r != ':' && r != '/' && r != '=' && r != '?' && r != '&' && r != '+') {
            bad[j] = 1;
          } else {
            bad[j] = 0;
          }
          pv[j++] = r;
        } else {
          bad[j] = 0;
          pv[j++] = v[i];
        }
      }
      f[j] = i;
      pv[j] = 0;
    
      for (i = 0; i < j; i++) {
        if ('A' <= pv[i] && pv[i] <= 'Z') {
          pv[i] = pv[i] - 'A' + 'a';
          bad[i] += 2;
        }
      }

    Очередной ебаный пиздец из kPHP
    В предыдущих сериях:
    http://govnokod.ru/19842
    http://govnokod.ru/15406

    j123123, 22 Сентября 2017

    Комментарии (20)
  8. C++ / Говнокод #23347

    +2

    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
    96. 96
    97. 97
    98. 98
    string shifarhex(string count)
    {
    
      string take,take2;
    string getch1;
    
    
    	getch1=count;
    
        string sub1 = "0000";//2 to 3		 31
       unsigned int pos1 = getch1.find(sub1,0);
      if(pos1 != string::npos)
      {
       take2="0"; 
      }
         string sub2 = "0001";//2 to 3		 31
       unsigned int pos2 = getch1.find(sub2,0);
      if(pos2 != string::npos)
      {
       take2="1"; 
      }
       string sub3 = "0010";//2 to 3		 31
       unsigned int pos3 = getch1.find(sub3,0);
      if(pos3 != string::npos)
      {
       take2="2"; 
      }
       string sub4 = "0011";//2 to 3		 31
       unsigned int pos4 = getch1.find(sub4,0);
      if(pos4 != string::npos)
      {
       take2="3"; 
      }
       string sub5 = "0100";//2 to 3		 31
       unsigned int pos5 = getch1.find(sub5,0);
      if(pos5 != string::npos)
      {
       take2="4"; 
      }
         string sub6 = "0101";//2 to 3		 31
       unsigned int pos6 = getch1.find(sub6,0);
      if(pos6 != string::npos)
      {
       take2="5"; 
      }
          string sub7 = "0110";//2 to 3		 31
       unsigned int pos7 = getch1.find(sub7,0);
      if(pos7 != string::npos)
      {
       take2="6"; 
      }
          string sub8 = "0111";//2 to 3		 31
       unsigned int pos8 = getch1.find(sub8,0);
      if(pos8 != string::npos)
      {
       take2="7"; 
      }
        string sub9 = "1000";//2 to 3		 31
       unsigned int pos9 = getch1.find(sub9,0);
      if(pos9 != string::npos)
      {
       take2="8"; 
      }
       string sub10 = "1001";//2 to 3		 31
       unsigned int pos10 = getch1.find(sub10,0);
      if(pos10 != string::npos)
      {
       take2="9"; 
      }
    
       string sub11 = "1010";//2 to 3		 31
       unsigned int pos11 = getch1.find(sub11,0);
      if(pos11 != string::npos)
      {
       take2="A"; 
      }
        string sub12 = "1011";//2 to 3		 31
       unsigned int pos12 = getch1.find(sub12,0);
      if(pos12 != string::npos)
      {
       take2="B"; 
    
      }
       string sub13 = "1100";//2 to 3		 31
       unsigned int pos13 = getch1.find(sub13,0);
      if(pos13 != string::npos)
      {
       take2="B"; 
      }
       string sub14 = "1101";//2 to 3		 31
       unsigned int pos14 = getch1.find(sub14,0);
      if(pos14 != string::npos)
      {
       take2="D"; 
      }
        string sub15 = "1110";//2 to 3		 31
       unsigned int pos15 = getch1.find(sub15,0);
    ...

    http://www.sql.ru/forum/1269897/delaem-arhivator
    Вореционное зожатие битов

    j123123, 21 Сентября 2017

    Комментарии (1)
  9. Куча / Говнокод #23345

    +1

    1. 1
    2. 2
    3. 3
    4. 4
    5. 5
    6. 6
    7. 7
    8. 8
    9. 9
    (* /*
    C > /) 2> /dev/null & echo hello world!; exit
    *       This file is correct input for:
    *       sh, cc, pc, f77
    */ main(program)) { puts("hello world!"); /*
    *) program main(output);begin writeln('hello world!')end. {
          write( *, '("hello world!")')
          end
    */ return &program; }

    Bash: https://ideone.com/HKy5RJ
    C: https://ideone.com/KFbJsK
    Pascal (fpc): https://ideone.com/4zcc51

    inkanus-gray, 12 Сентября 2017

    Комментарии (42)
  10. Куча / Говнокод #23344

    +1

    1. 1
    2. 2
    3. 3
    4. 4
    5. 5
    (*a/*/ % #)(PostScript)/Helvetica 40 selectfont 9 400 moveto show%v"f"a0
    true showpage quit%#) 2>/dev/null;echo bash;exit #*/);int main()/*>"eb"v
    %a*0)unless print"perl\n"__END__*/{printf("C\n");/*>>#;"egnu">:#,_@;,,,<
    *)begin writeln(*\output={\setbox0=\box255}\eject\shipout\hbox{\TeX}\end
    *)('pascal');end.{*/return 0;}

    C: https://ideone.com/Ntu3S0
    Pascal (fpc): https://ideone.com/A9qZ0x
    Bash: https://ideone.com/TYr7cu
    Perl: https://ideone.com/fAUhiv

    inkanus-gray, 12 Сентября 2017

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