1. C++ / Говнокод #3022

    +61.2

    1. 1
    2. 2
    3. 3
    4. 4
    FILE *f=fopen(name, "wb");
    char *text="<DMB 1.0>\n\n";
    for(int i=0;i<=10;i++){fputc((int)text, f);}
    fclose(f);

    Замечу это c++, так как это чудо находилось в классе.

    hromjo, 16 Апреля 2010

    Комментарии (31)
  2. SQL / Говнокод #3021

    −864.6

    1. 1
    2. 2
    3. 3
    4. 4
    5. 5
    "SELECT null AS counter, t1.* FROM student.select_recomended_candidate_zo(" + ((DataBaseItem)lbSpeciality.SelectedItem).ItemId + ") t1 " +
                                                 "LEFT JOIN (SELECT t3.id, t3.specperiod_id FROM general.select_speciality_extended_alt(" + AppData.PointOfActualityDBFormat + ") t3) lj2 ON lj2.id = " + ((DataBaseItem)lbSpeciality.SelectedItem).ItemId + " " +
                                                 "LEFT JOIN (SELECT DISTINCT id, ex1_val, ex2_val, ex3_val FROM student.select_candidate_dean(" + ((DataBaseItem)lbSpeciality.SelectedItem).ItemId + ") t2) lj1 ON t1.id = lj1.id " +
                                                "WHERE (lj2.specperiod_id = 1 AND lj1.ex1_val IS NOT null AND lj1.ex2_val IS NOT null AND lj1.ex3_val IS NOT null) OR (lj2.specperiod_id > 1 AND lj1.ex1_val IS NOT null) IS true " +
                                                "ORDER BY has_benifit DESC, this_is_special DESC, sum DESC"

    des-1008d, 16 Апреля 2010

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

    +163.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
    $t_total_rows = 100;
    		$t_row_ids = array();
    
    		// Check total profile rows.
    		for($i = 1; $i <= $t_total_rows; $i++)
    		{
    				$result = $database -> database_query("SELECT `profilevalue_$i` FROM `se_profilevalues`");
    
    				if($result != FALSE)
    				{
    						$t_row_ids[] = $i;
    				}
    		}

    Нашел еще один кусок кода :)))
    Оригинальный подход для подсчета полей :))

    Rain, 16 Апреля 2010

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

    +913.2

    1. 1
    if (c != "$"[0])

    Без комментария

    Snake2101, 16 Апреля 2010

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

    +61.2

    1. 1
    2. 2
    3. 3
    4. 4
    5. 5
    6. 6
    7. 7
    8. 8
    9. 9
    unsigned int nRecsSize=0;
    
    nRecsSize+=4;
    nRecsSize+=1;
    nRecsSize+=1;
    nRecsSize+=rec_.ip.length();
    nRecsSize+=6;
    	
    BYTE *pData = new BYTE[nRecsSize];

    Вот так надо высчитывать память под динамический массив

    Snake2101, 16 Апреля 2010

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

    +138.8

    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
    #include <unistd.h>
    #include <assert.h>
    #include <stdlib.h>
    #include <string.h>
    
    // grep ^\s*$ file1 file2 ... | wc -l
    
    int main(int argc, const char **argv)
    {
    	int fd[2];
    	pid_t pid;
    	
    	assert(!pipe(fd));
    	assert((pid = fork()) >= 0);
    	
    	if (!pid)
    	{
    		char **newargv;
    		
    		assert(dup2(fd[1], 1) == 1);
    		assert(!close(fd[0]));
    		assert(!close(fd[1]));
    		assert(newargv = malloc((argc + 2) * sizeof(char *)));
    		newargv[0] = "grep";
    		newargv[1] = "^\\s*$";
    		memcpy(newargv + 2, argv + 1, (argc + 1) * sizeof(char *));
    		assert(execvp("grep", newargv) * 0);
    	}
    	
    	assert((pid = fork()) >= 0);
    	
    	if (!pid)
    	{
    		assert(dup2(fd[0], 0) == 0);
    		assert(!close(fd[0]));
    		assert(!close(fd[1]));
    		assert(execlp("wc", "wc", "-l", NULL) * 0);
    	}
    	
    	assert(!close(fd[0]));
    	assert(!close(fd[1]));
    	
    	while (wait(NULL) != -1);
    	return 0;
    }

    Butjok, 15 Апреля 2010

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

    +159.8

    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
    function AbstractControl_getProperty (propertyName) {
    	var targetElement = this.getTargetPath(propertyName);
    	var result = null;
    	
    	if (this.isTargetAttribute(propertyName)) {
    		eval("result = targetElement." + this.getAttributeName(propertyName));
    	} else {
    		var getter = this.getGetterName(propertyName);
    		var expression = "result = targetElement." + getter + "();";
    		eval(expression);
    	}
    	return result;
    }

    Вот так наши "суровые челябинские" программисты, не имеющие представления об интроспективности javascript-а, повсюду злоупотребляют eval-ом, усложняя отладку и понимание кода.
    По хорошему, вместо первого eval-а должно бы быть:
    result = targetElement[this.getAttributeName(propertyName)];
    а вместо второго:
    result = targetElement[this.getGetterName(propertyName)]();

    Andronix, 15 Апреля 2010

    Комментарии (15)
  8. PHP / Говнокод #3015

    +172.8

    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
    if ($_POST['action']!=""){
        $action=$_POST['action'];
      } elseif ($_GET['action']!=""){
        $action=$_GET['action']; 
      }
      if ($_POST['pid']!=""){
        $pid=$_POST['pid'];
      } elseif ($_GET['pid']!=""){
        $pid=$_GET['pid']; 
      }
      if ($_POST['page']!=""){
        $page=$_POST['page'];
      } elseif ($_GET['page']!=""){
        $page=$_GET['page']; 
      }
      if ($_POST['cid']!=""){
        $cid=$_POST['cid'];
      } elseif ($_GET['cid']!=""){
        $cid=$_GET['cid']; 
      }
      if ($_POST['num']!=""){
        $num=$_POST['num'];
      } elseif ($_GET['num']!=""){
        $num=$_GET['num']; 
      }

    darkpreacher, 15 Апреля 2010

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

    +152.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
    function ShowMsg($text)
    {
        if(session_is_registered('xynta')) $un = base64_decode(strrev($_SESSION['xynta']));
        else $un = "%USERNAME%";
        $text = str_replace("%%USERNAME%%",$un,$text);
        $text = preg_replace("/\[img\](.+?)\[\/img\]/is","<img src=\"\\1\" />",$text);
        $text = preg_replace("/\[bkb\](.+?)\[\/bkb\]/is","<span class=bkb>\\1</span>",$text);
        $text = preg_replace("/\[move\](.+?)\[\/move\]/is","<marquee>\\1</marquee>",$text);
        $text = preg_replace("/\[quote\](.+?)\[\/quote\]/is","<blockquote>\\1</blockquote>",$text);
        $text = preg_replace("/\[center\](.+?)\[\/center\]/is","<center>\\1</center>",$text);
        $text = preg_replace("/\[b\](.+?)\[\/b\]/is","<b>\\1</b>",$text);
        $text = preg_replace("/\[i\](.+?)\[\/i\]/is","<i>\\1</i>",$text);
        $text = preg_replace("/\[u\](.+?)\[\/u\]/is","<u>\\1</u>",$text);
        $text = preg_replace("/\[s\](.+?)\[\/s\]/is","<s>\\1</s>",$text);
        $text = preg_replace("/\[code\](.+?)\[\/code\]/is","<code>\\1</code>",$text);
        $text = preg_replace("/\[effekt\](.+?)\[\/effekt\]/is","<div style='padding: 20px;display:block;'><span id=effekt name=effekt>\\1</span></div>",$text);
        $text = preg_replace("/\[blink\](.+?)\[\/blink\]/is","<span id=blink name=blink>\\1</span>",$text);
        //    $text = preg_replace("/\[flash\](.+?)\[\/flash\]/is","<embed type='application/x-shockwave-flash' width=640 height=480 src=\\1 />",$text);
        $text = preg_replace_callback("/\[mp3\](.+?)\[\/mp3\]/is","mp3_safe_url",$text);
        $text = preg_replace("/\[bg=(.+?)\](.+?)\[\/bg\]/is","<span style='background:\\1'>\\2</span>", $text);
        $text = preg_replace("#\[url\](.+?)\[/url\]#is", "<a href=http://www.dereferer.org/?\\1 target=_blank>\\1</a>", $text);
        if(!strstr($text,"<br")) $text=nl2br($text);
        return $text;
    }

    diio, 15 Апреля 2010

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

    +149.8

    1. 1
    if( preg_match("#list(/$|$)#is", $requestUri) )

    Человек никогда не слышал про квантификаторы в регулярных выражениях.

    anei, 15 Апреля 2010

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