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

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

    +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
    switch (field.type) {
        case 'checkbox':
        case 'notification':	
            if (field.type == 'notification') {
                fieldData.element.addClass('field-notification');
                $('<span class="notification-button" data-action="notification">').text('Принять').appendTo(body).on(
                    'click', function () {
    		    _class.wrapper.removeClass('notification');
    		    _class.notification.wrapper.removeClass('notification-active');
    		    _class.fields[index - 1].changeStatus();
    		    $Mediator.fire({
                            name: 'active:filter',
    			target: _class.fields[0].filter
    		    });
                });
            }
        break;
    }

    Вдруг SWITCH не сработал)

    JudiCortes, 21 Мая 2019

    Комментарии (39)
  3. Python / Говнокод #25621

    +2

    1. 1
    2. 2
    3. 3
    4. 4
    def test_wash_table_column_name(self):
        testcase_ok = "Programmer"
        testcase_injection = "' OR ''='"
        self.assertEqual(dbquery.real_escape_string(testcase_ok), testcase_ok)

    real_escape_string, 19 Мая 2019

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

    +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
    char *real_escape_string(const byte *src, int size)
    {
        char *escaped;
        char *pos;
    
        if (memchr(src, '\0', size - 1) || memchr(src, '\n', size) || memchr(src, '\r', size)) {
    	fprintf(stderr, "cannot handle this string\n");
    	return NULL;
        }
    
        pos = escaped = malloc(sizeof(char) * (size * 2 + 1));
    
        if (escaped == NULL) {
    	fprintf(stderr, "malloc failed: %m\n");
    	return NULL;
        }
    
        for (int i = 0; i < size; ++i) {
    	if (!isalnum(src[i])) {
    	    *escaped++ = '\\';
    	}
    	*escaped++ = src[i];
        }
    
        *escaped = '\0';
    
        return pos;
    }

    real_escape_string, 19 Мая 2019

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

    +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
    #include "stdio.h"
    #include "conio.h"
    #define infinity 999
    
    namespace belugina
    {
    void dij(int n,int v,int cost[10][10],int dist[])
    {
     int i,u,count,w,flag[10],min;
     for(i=1;i<=n;i++)
      flag[i]=0,dist[i]=cost[v][i];
     count=2;
     while(count<=n)
     {
      min=99;
      for(w=1;w<=n;w++)
       if(dist[w]<min && !flag[w])
        min=dist[w],u=w;
      flag[u]=1;
      count++;
      for(w=1;w<=n;w++)
       if((dist[u]+cost[u][w]<dist[w]) && !flag[w])
        dist[w]=dist[u]+cost[u][w];
     }
    }
    }

    Я разгадала знак бесконечности.
    #define infinity 999

    dethless, 19 Мая 2019

    Комментарии (12)
  6. Си / Говнокод #25613

    +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
    bool End_Range (FILE * f){
      int tmp;
      tmp = fgetc(f);
      tmp = fgetc(f);
      if (tmp != '\'') fseek(f,-2,1);
      else fseek(f,1,1);
      return tmp == '\'' ? true : false;
    }
    
    void Natural_Merging_Sort (char *name){
      int s1, s2, a1, a2, mark;  FILE *f, *f1, *f2;  s1 = s2 = 1;
      while ( s1 > 0 && s2 > 0 ){
       	 mark = 1; s1 = 0; s2 = 0;
        	 f = fopen(name,"r"); f1 = fopen("nmsort_1","w"); 
    		 f2 = fopen("nmsort_2","w"); fscanf(f,"%d",&a1);
       	 if ( !feof(f) ) fprintf(f1,"%d ",a1);
       	 if ( !feof(f) ) fscanf(f,"%d",&a2);
        	 while ( !feof(f) ){
         		 if ( a2 < a1 ) {switch (mark) {
              				case 1:{fprintf(f1,"' "); mark = 2; s1++; break;}
             				case 2:{fprintf(f2,"' "); mark = 1; s2++; break;}
            		  }}
    if ( mark == 1 ) { fprintf(f1,"%d ",a2); s1++; }
          	else { fprintf(f2,"%d ",a2); s2++;}
          	a1 = a2; fscanf(f,"%d",&a2);
        	}
        if ( s2 > 0 && mark == 2 ) { fprintf(f2,"'");}
        if ( s1 > 0 && mark == 1 ) { fprintf(f1,"'");}
        fclose(f2); fclose(f1); fclose(f);
        cout << endl;
        Print_File(name);
        Print_File("nmsort_1");
        Print_File("nmsort_2");
        cout << endl;
      f = fopen(name,"w");  f1 = fopen("nmsort_1","r");
        f2 = fopen("nmsort_2","r");
        if ( !feof(f1) ) fscanf(f1,"%d",&a1);
        if ( !feof(f2) ) fscanf(f2,"%d",&a2);
        bool file1, file2;
        while ( !feof(f1) && !feof(f2) ){	file1 = file2 = false;
          	while ( !file1 && !file2 ) {
            		if ( a1 <= a2 ) { fprintf(f,"%d ",a1); 
    				  file1 = End_Range(f1); fscanf(f1,"%d",&a1);	}
            else { fprintf(f,"%d ",a2); file2 = End_Range(f2);
              fscanf(f2,"%d",&a2);	}
          } 
    while ( !file1 ) {		fprintf(f,"%d ",a1);
            file1 = End_Range(f1);  fscanf(f1,"%d",&a1);	}
     while ( !file2 ) {	fprintf(f,"%d ",a2);  
    				file2 = End_Range(f2); fscanf(f2,"%d",&a2);	}
        }	file1 = file2 = false;
        while ( !file1 && !feof(f1) ) {	fprintf(f,"%d ",a1);
          		file1 = End_Range(f1); fscanf(f1,"%d",&a1);	}
        while ( !file2 && !feof(f2) ) {	fprintf(f,"%d ",a2);
          		file2 = End_Range(f2); fscanf(f2,"%d",&a2);	}
        fclose(f2); fclose(f1); fclose(f);
      }	 remove("nmsort_1");  remove("nmsort_2");
    }

    Потеряли пульт от телевизора? Найди его бинарным поиском!!!

    dethless, 19 Мая 2019

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

    +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
    /* ... */
      if  (kindmusic64[7].checked == true)
      {
        var number = Math.floor(Math.random() * 41);
        switch(number)
        {
          case 0: redradio[0].checked = true; greenradio[0].checked = true; blueradio[1].checked = true;  break;
          case 1: redradio[0].checked = true; greenradio[1].checked = true; blueradio[0].checked = true;  break;
          case 2: redradio[0].checked = true; greenradio[1].checked = true; blueradio[1].checked = true;  break;
          case 3: redradio[1].checked = true; greenradio[0].checked = true; blueradio[0].checked = true;  break;
          case 4: redradio[1].checked = true; greenradio[0].checked = true; blueradio[1].checked = true;  break;
          case 5: redradio[1].checked = true; greenradio[1].checked = true; blueradio[0].checked = true;  break;
          case 6: redradio[1].checked = true; greenradio[1].checked = true; blueradio[2].checked = true;  break;
          case 7: redradio[1].checked = true; greenradio[2].checked = true; blueradio[1].checked = true;  break;
          case 8: redradio[1].checked = true; greenradio[2].checked = true; blueradio[2].checked = true;  break;
          case 9: redradio[2].checked = true; greenradio[1].checked = true; blueradio[1].checked = true;  break;
          case 10: redradio[2].checked = true; greenradio[1].checked = true; blueradio[2].checked = true;  break;
          case 11: redradio[2].checked = true; greenradio[2].checked = true; blueradio[1].checked = true;  break;
          case 12: redradio[2].checked = true; greenradio[2].checked = true; blueradio[3].checked = true;  break;
          case 13: redradio[2].checked = true; greenradio[3].checked = true; blueradio[2].checked = true;  break;
          case 14: redradio[2].checked = true; greenradio[3].checked = true; blueradio[3].checked = true;  break;
          case 15: redradio[3].checked = true; greenradio[2].checked = true; blueradio[2].checked = true;  break;
          case 16: redradio[3].checked = true; greenradio[2].checked = true; blueradio[3].checked = true;  break;
          case 17: redradio[3].checked = true; greenradio[3].checked = true; blueradio[2].checked = true;  break;
          case 18: redradio[0].checked = true; greenradio[0].checked = true; blueradio[2].checked = true;  break;
          case 19: redradio[0].checked = true; greenradio[2].checked = true; blueradio[0].checked = true;  break;
          case 20: redradio[0].checked = true; greenradio[2].checked = true; blueradio[1].checked = true;  break;
          case 21: redradio[1].checked = true; greenradio[0].checked = true; blueradio[2].checked = true;  break;
          case 22: redradio[1].checked = true; greenradio[1].checked = true; blueradio[3].checked = true;  break;
          case 23: redradio[1].checked = true; greenradio[3].checked = true; blueradio[1].checked = true;  break;
          case 24: redradio[1].checked = true; greenradio[3].checked = true; blueradio[2].checked = true;  break;
          case 25: redradio[2].checked = true; greenradio[0].checked = true; blueradio[0].checked = true;  break;
          case 26: redradio[2].checked = true; greenradio[1].checked = true; blueradio[0].checked = true;  break;
          case 27: redradio[2].checked = true; greenradio[1].checked = true; blueradio[3].checked = true;  break;
          case 28: redradio[3].checked = true; greenradio[1].checked = true; blueradio[1].checked = true;  break;
          case 29: redradio[3].checked = true; greenradio[2].checked = true; blueradio[1].checked = true;  break;
          case 30: redradio[0].checked = true; greenradio[0].checked = true; blueradio[0].checked = true;  break;
          case 31: redradio[1].checked = true; greenradio[1].checked = true; blueradio[1].checked = true;  break;
          case 32: redradio[2].checked = true; greenradio[2].checked = true; blueradio[2].checked = true;  break;
          case 33: redradio[3].checked = true; greenradio[3].checked = true; blueradio[3].checked = true;  break;
          case 34: redradio[0].checked = true; greenradio[3].checked = true; blueradio[2].checked = true;  break;
          case 35: redradio[0].checked = true; greenradio[2].checked = true; blueradio[2].checked = true;  break;
          case 36: redradio[1].checked = true; greenradio[3].checked = true; blueradio[3].checked = true;  break;
          case 37: redradio[2].checked = true; greenradio[0].checked = true; blueradio[2].checked = true;  break;
          case 38: redradio[3].checked = true; greenradio[1].checked = true; blueradio[3].checked = true;  break;
          case 39: redradio[2].checked = true; greenradio[2].checked = true; blueradio[0].checked = true;  break;
          case 40: redradio[3].checked = true; greenradio[3].checked = true; blueradio[1].checked = true;  break;
          case 41: redradio[2].checked = true; greenradio[0].checked = true; blueradio[3].checked = true;  break;
          case 42: redradio[0].checked = true; greenradio[1].checked = true; blueradio[2].checked = true;  break;
          case 43: redradio[1].checked = true; greenradio[2].checked = true; blueradio[3].checked = true;  break;
          case 44: redradio[0].checked = true; greenradio[3].checked = true; blueradio[1].checked = true;  break;
          case 45: redradio[1].checked = true; greenradio[0].checked = true; blueradio[3].checked = true;  break;
          case 46: redradio[1].checked = true; greenradio[2].checked = true; blueradio[0].checked = true;  break;
          case 47: redradio[2].checked = true; greenradio[3].checked = true; blueradio[1].checked = true;  break;
          case 48: redradio[2].checked = true; greenradio[0].checked = true; blueradio[1].checked = true;  break;
          case 49: redradio[3].checked = true; greenradio[1].checked = true; blueradio[2].checked = true;  break;
          case 48: redradio[3].checked = true; greenradio[1].checked = true; blueradio[0].checked = true;  break;
          case 49: redradio[3].checked = true; greenradio[2].checked = true; blueradio[0].checked = true;  break;
    /* ... */

    https://olgusha.ru/javascript/colors.htm, да ещё написано, что попробуйте протестировать способность вашего компьютера сочинять музыку и выбирать случайным образом цвета.

    unicorn, 18 Мая 2019

    Комментарии (21)
  8. Си / Говнокод #25599

    +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
    #include <conio.h>
    
    static unsigned char bigArray[256] = {['0'] = 0, ['1'] = 1, ['2'] = 2, ['3'] = 3,
                                          ['4'] = 4, ['5'] = 5, ['6'] = 6, ['7'] = 7,
                                          ['8'] = 8, ['9'] = 9, ['A'] = 10, ['B'] = 11,
                                          ['C'] = 12, ['D'] = 13, ['E'] = 14, ['F'] = 15 };
    void StringToByte(const char src[], unsigned char dst[]) 
    {
    	int q, u = 0;
    	for (q = 0; src[q]; q+=2) 
    	{
    		dst[u] = bigArray[src[q]] << 4;
    		if (!src[q+1]) 
    			return;
    		dst[u++] |= bigArray[src[q+1]];
    	}
    }
    
    int main()
    {
    	char string[] = "112255ACBF";
    	unsigned char bytes[5];
    	StringToByte(string, bytes);
    	int i;
    	for (i = 0; i!=sizeof(bytes); i++)
    		printf("%x ", (int)bytes[i]);
    	return 0;
    }

    Ебическая С-ла.

    Psionic, 13 Мая 2019

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

    +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
    function check($str)
        {
            $str = htmlentities($str, ENT_QUOTES, 'UTF-8');
            $str = str_replace("'", "'", $str);
            $str = str_replace("rn", "<br/>", $str);
            $str = strtr($str, array(chr("0") => "", chr("1") => "", chr("2") => "", chr("3") => "", chr("4") => "", chr("5") => "", chr("6") => "", chr("7") => "", chr("8") => "", chr("9") => "", chr("10") => "", chr("11") => "", chr("12") => "", chr
            ("13") => "", chr("14") => "", chr("15") => "", chr("16") => "", chr("17") => "", chr("18") => "", chr("19") => "", chr("20") => "", chr("21") => "", chr("22") => "", chr("23") => "", chr("24") => "", chr("25") => "", chr("26") => "", chr("27") =>
            "", chr("28") => "", chr("29") => "", chr("30") => "", chr("31") => ""));
            $str = str_replace('\', "\", $str);
            $str = str_replace("|", "I", $str);
            $str = str_replace("||", "I", $str);
            $str = str_replace("/\$/", "$", $str);
            $str = str_replace("[l]http://", "[l]", $str);
            $str = str_replace("[l] http://", "[l]", $str);
            $str = mysql_real_escape_string($str);
            return $str;
        }

    Функция check от моего предыдущего поста

    eskrano, 27 Апреля 2019

    Комментарии (17)
  10. PHP / Говнокод #25570

    +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
    <?php
        define('_SECUR_GAMES', 1);
        $rootpath = '../';
        require_once '../includes/start.php';
        require_once '../includes/function.php';
        require_once '../includes/header.php';
    if($level >0 AND $fr_id!=0)
    {
    $header='alliance';
    mysql_query("UPDATE `mesto` SET `place` = '".check(htmlspecialchars(stripslashes(addslashes(strip_tags(mysql_real_escape_string(trim($header)))))))."' WHERE `uid`=".check(htmlspecialchars(stripslashes(addslashes(strip_tags(mysql_real_escape_string(trim($use_id)))))))."");
    }
    $fr=check(htmlspecialchars(stripslashes(addslashes(strip_tags(mysql_real_escape_string(trim($_GET['f'])))))));
    $q = mysql_query("SELECT * FROM `fractions` WHERE `id`='".check(htmlspecialchars(stripslashes(addslashes(strip_tags(mysql_real_escape_string(trim($fr)))))))."'");
    $f = mysql_fetch_array($q);
    $ucount = mysql_result(mysql_query("SELECT COUNT(*) FROM `fractions_users` WHERE `uid`='".check(htmlspecialchars(stripslashes(addslashes(strip_tags(mysql_real_escape_string(trim($use_id)))))))."' AND `fid`='".check(htmlspecialchars(stripslashes(addslashes(strip_tags(mysql_real_escape_string(trim($f['id'])))))))."';"), 0);
    $fadm = mysql_result(mysql_query("SELECT COUNT(*) FROM `fractions_users` WHERE `uid`='".check(htmlspecialchars(stripslashes(addslashes(strip_tags(mysql_real_escape_string(trim($use_id)))))))."' AND `fid`='".check(htmlspecialchars(stripslashes(addslashes(strip_tags(mysql_real_escape_string(trim($f['id'])))))))."' AND `adm`=1;"), 0);
        if($game==0 OR $level==0 OR $ban==1){
               echo "<title>Доступ закрыт!!!</title>";

    @since 2019

    eskrano, 25 Апреля 2019

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

    +2

    1. 01
    2. 02
    3. 03
    4. 04
    5. 05
    6. 06
    7. 07
    8. 08
    9. 09
    10. 10
    11. 11
    Функция ПолучитьСтавкуНДС(СуммаСНДС, НДС)
    	Если НДС = 0  Тогда
    		Возврат Перечисления.СтавкиНДС.БезНДС;
    	ИначеЕсли СуммаСНДС = 0 Тогда //некорректные данные
    		Возврат Перечисления.СтавкиНДС.БезНДС;
    	ИначеЕсли НДС / СуммаСНДС <= 0.152+0.0152 и НДС / СуммаСНДС >= 0.152-0.0152 Тогда
    		Возврат Перечисления.СтавкиНДС.НДС18;
    	ИначеЕсли НДС / СуммаСНДС <= 0.091+0.0091 и НДС / СуммаСНДС >= 0.091-0.0091 Тогда
    		Возврат Перечисления.СтавкиНДС.НДС10;
    	КонецЕсли;
    КонецФункции

    Костыль костыльный

    sandvich, 24 Апреля 2019

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