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

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

    +163

    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
    function shab()
    {
      global $title;                            
      global $description;
      global $keywords;
      global $content;                                         
      global $patch;
      global $page_names;
      global $pn;
      global $id;
      include_once $patch.'/head.php'; // почему-то вспомнился логотип башоргру cat /dev/ass > /dev/head
      echo $title.'</title>'."\n";
      echo '<meta name="description" content="'.$description.'">'."\n";
      echo '<meta name="keywords" content="'.$keywords.'">'."\n";
      include_once $patch.'/shapka.php'; // wtf!?
      echo $content."<br>\n";
      if(in_array($pn,$page_names))
      {                                   
          include $patch.'/form.php';
      }
      $ua=mysql_real_escape_string(trim($_SERVER['HTTP_USER_AGENT']));
      $ip=mysql_real_escape_string(trim($_SERVER['REMOTE_ADDR'])); // вебкил не пройдет
      mysql_query("update content set views=views+1 where id='$id'");
      mysql_query("insert into views_content set id='$id', ip='$ip', t=NOW() + INTERVAL 1 HOUR, d=NOW() + INTERVAL 1 HOUR, ua='$ua'");
      $q=mysql_query("select views,t,d from content where id='$id'");
      while($r=mysql_fetch_array($q))
      {
         echo '<br><span style="font-color:#808080; font-size:8pt; float:right;">Просмотров: '.$r['views'].'<br>
         '.$r['d'].'<font color="#ca3200"> / </font>'.$r['t']."<br>\n"; //d и t это дата и время кто не понял :D	
      } 
      echo '<a style="font-color:#ca3200; font-size:10pt;" href="index.php">все статьи</a></span>';
      include_once $patch.'/footer.php';
    }

    это вам не смарти, тут всё просто и понятно, а главное быстро. shab() и дело в шляпе.

    GoodTalkBot, 11 Мая 2011

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

    +152

    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
    QString generateGuid( const std::string &tDeviceSerial,
            const std::string &nDatetime, const std::string &licnum,
            const char *violation )
    {
        std::ostringstream s;
        s << tDeviceSerial;
        s << nDatetime;
        s << licnum;
        s << violation;
        
        QCryptographicHash hash( QCryptographicHash::Md5 );
        hash.addData( QByteArray( s.str().c_str() ) );
        QByteArray result = hash.result();
        return convToHex( (unsigned char*)result.data(), result.size() );
    }

    Оно, конечно, работает. Но разобраться в таком коде....

    panter_dsd, 11 Мая 2011

    Комментарии (16)
  4. Java / Говнокод #6577

    +68

    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
    public class Zayac {
    	public static void main(String args[]) {
        String ears="(\\_/)";
        String face="(-_-)";
        String hands="(> <)";
        String legs="(\")(\")";
        System.out.println(ears);
        System.out.println(face);
        System.out.println(hands);
        System.out.println(legs+'\n');
    	System.out.println('\t'+ears);
    	System.out.println('\t'+face);
    	System.out.println('\t'+hands);
        System.out.println('\t'+legs);
        System.out.println("\t"+"\t"+ears);
    	System.out.println("\t"+"\t"+face);
    	System.out.println("\t"+"\t"+hands);
        System.out.println("\t"+"\t"+legs);
    	}
    }

    Дело было вечером - делать было нечего.

    Akira, 06 Мая 2011

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

    +163

    1. 1
    2. 2
    3. 3
    function paging($pageNum,$rowsPerPage)
    {
    	GLOBAL $_GET, $_POST, $_SESSION;

    На всякий случай. Чтоб точно глобальные были. А то всякое бывает ...

    _tL, 06 Мая 2011

    Комментарии (16)
  6. Ruby / Говнокод #6568

    −105

    1. 1
    2. 2
    3. 3
    4. 4
    5. 5
    6. 6
    7. 7
    def index
        list
        render :action => 'list'
      end
    
      def list
      end

    intale, 06 Мая 2011

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

    +169

    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
    bool NSFileExists(const char * FileName)
    {
      struct _stat fStats;
      return (_stat(FileName, &fStats) == 0);
    }
    
    #if 0
    bool NSFileExists(const char * FileName)
    {
      WIN32_FIND_DATA fd;
      HANDLE hFF;
      bool bExist(true);
      hFF = FindFirstFile(FileName, &fd);
      if (hFF == INVALID_HANDLE_VALUE) bExist = false;
      else FindClose(hFF);
      return bExist;
    }
    #endif
    
    #if 0
    bool NSFileExists(const char * FileName)
    {
      HANDLE hFile = ::CreateFile(FileName, 0, 0, 0, OPEN_EXISTING, 0, 0);
      if (hFile != INVALID_HANDLE_VALUE)
      {
        CloseHandle(hFile);
        return true;
      }
      return false;
    }
    #endif

    Эволюция!
    Без комментариев...

    JeremyW, 21 Апреля 2011

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

    +179

    1. 1
    2. 2
    3. 3
    // Count rows in news table
    $rows = $db -> query('SELECT * FROM news');
    $count = count($rows)

    Увидел в одном самопальном движке.

    Shitafaka, 14 Апреля 2011

    Комментарии (16)
  9. C# / Говнокод #6224

    +980

    1. 1
    2. 2
    3. 3
    4. 4
    if (ch=='k' && ch!='t')
    {
         something
    }

    Найдено в довольно серьезном проекте.

    timurets, 05 Апреля 2011

    Комментарии (16)
  10. bash / Говнокод #6222

    −131

    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
    #!/bin/bash
    
    ######################################################################################
    #
    #	Write a bash script that obtains active processes for the current user, 
    #	breaks them into chains and prints all unique chains containing 3 or more 
    #	PIDs in the following format:
    #		PID1:PID2:PID3:…:PIDn
    #		PID:PID:PID:…:PID
    #		…
    #	So that each next PID is a parent of the previous PID, the first PID in 
    #	each chain does not have children and the last PID in each chain 
    #	does not have parent.
    #
    ######################################################################################
    
    TEMPFILE="/tmp/$0$$"				# file needs to save the process list
    						# it's really needed to divide columns
    						# generated 'ps'
    						
    # parameters:
    # 	-H 	- sorts the list as process forest (it lets to find connection between child and parent faster)
    #	-o	- sets the output format
    #	"%p %P" - thow columns in output: PID and PPID
    #	-u	- sets username
    #	`whoami` - get the current user name
    ps -H -o "%p %P" -u `whoami` > $TEMPFILE
    PIDLIST=(`awk '/[0-9]/ {print $1}' $TEMPFILE`)	# make an array using the first column
    PPIDLIST=(`awk '/[0-9]/ {print $2}' $TEMPFILE`)	# 	and the second
    
    SIZE=${#PIDLIST[*]}
    K=0
    # bypassing the forest using stack which emulates LINKS array. K is the pointer to stack's top
    for (( i=0; i<$SIZE; i++ ))
    do
        if [[ $K = 0 || ${PPIDLIST[$i]} = ${LINKS[$K-1]} ]]	# new tree or new edge in the tree.
        then
            LINKS[$K]=${PIDLIST[$i]}		# push PID to stack
            K=`expr $K + 1`
        else 					# the chain is complete.
    	if [[ $K > 2 ]]				# enough size to print the chain
    	then				# reversed formatted output the chain
    	    echo ${LINKS[*]} | awk '{ printf $NF; for (i = NF-1; i > 0; --i) printf ":"$i}'
    	    echo
    	fi
            until [[ $K == 0 || ${PPIDLIST[$i]} == ${LINKS[$K-1]} ]]
            do 					# deleting elements from stack until find a
        						#	parent or tree is end
        	    unset LINKS[$K-1]
        	    K=`expr $K - 1`
            done
    	LINKS[$K]=${PIDLIST[$i]}		# push PID to stack
    	K=`expr $K + 1`
        fi
    done
    
    rm -rf $TEMPFILE				# removing temp file

    cahekm, 05 Апреля 2011

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

    +172

    1. 1
    2. 2
    3. 3
    4. 4
    5. 5
    6. 6
    7. 7
    8. 8
    //Взятые из разных файлов варианты обращений к файлу конфигураций характеризуют о гибкости подхода к разработке приложения
    require_once '../../../config.php';
    require_once("../config.php");
    require_once("../../../../config.php");
    require_once(dirname(dirname(__FILE__)) . '/config.php');
    require('../config.php');
    require_once(dirname(__FILE__) . '/../../config.php');
    require_once(dirname(dirname(dirname(dirname(__FILE__)))) . '/config.php'); //included from messagelib (how to fix?)

    Предлагаю обратить внимание на http://moodle.org/ -- это Система Управления Обучением.

    Продукт поражает своей архитектурой. Предлагаю взглянуть одним глазком.

    sectus, 28 Марта 2011

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