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

    +57

    1. 1
    if (!this) return;

    Actine, 05 Сентября 2014

    Комментарии (25)
  2. JavaScript / Говнокод #16651

    +154

    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
    // Цитата №1: массив регулярных выражений из введённых пользователем строк
    var strings = what.filter(function(e){ return e.replace(/s+/g,'').length; }).map(function(e){ var re = new RegExp(e, 'g' + (ignoreCase ? 'i' : '')); return re; });
    
    // Цитата №2: проверяется наличие введённых строк в тексте и выводит результаты
    function processText(pid, cid, text){
      if(strings.every(function(re){
        return re.test(text);
      })){
      
        // совпало
        // тут выводится информация о совпадении для поста/комментария
        // кроме вывода в консоль побочных эффектов нет
        ....
        
      }
    }
    
    // Цитата №3: запуск поиска
    posts.forEach(function(post){
      processText(post.id, null, post.author.name + ' ' + post.text);
      processText(post.id, null, post.author.name + ' ' + post.description);
      post.comments.forEach(function(comment){
        processText(post.id, comment.id, comment.author.name + ' ' + comment.text);
      });
    });

    Цитаты из скрипта поиска по ГК.
    Казалось бы, write-only питушня, работает - не трогать. Но, прочитав, http://govnokod.ru/16577#comment246821, решил поискать упоминания доктора по званию. Открываю найденный пост X, а там не все упоминания найдены. Меняю список постов, в которых искать - для X меняется список найденных комментариев.
    Откуда такая питушня? processText почти чистая, strings, posts не меняется. Может, вывод на консоль как-то влияет?

    Все волосы на жопе вырвал пока нашел в чем ошибка.
    Внимание, вопрос. В чем гавно?
    (c) ursus

    1024--, 05 Сентября 2014

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

    +155

    1. 01
    2. 02
    3. 03
    4. 04
    5. 05
    6. 06
    7. 07
    8. 08
    9. 09
    10. 10
    11. 11
    12. 12
    // Отладочная информация
    if(1)
    {
    	print "<!--\r\n";
    	$time_end = microtime(true);
    	$exec_time = $time_end-$time_start;
      
      	if(function_exists('memory_get_peak_usage'))
    		print "memory peak usage: ".memory_get_peak_usage()." bytes\r\n";  
    	print "page generation time: ".$exec_time." seconds\r\n";  
    	print "-->";
    }

    Simpla CMS, красавцы! :D

    volter9, 05 Сентября 2014

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

    +135

    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
    public string ExportToFile(string filename, string filepath, DataSet dsInput)
     {
         string sFlag = "Error";
         System.IO.StreamWriter sw = new StreamWriter("");
         try
         {
             if (filename.Trim() != "" && filepath != "" && dsInput.Tables[0].Rows.Count != 0)
             {
                    sw = new System.IO.StreamWriter(filepath + filename + ".xls");
                     int iCol = dsInput.Tables[0].Columns.Count;
                     for (int i = 0; i < iCol; i++)
                     {
                         sw.Write(dsInput.Tables[0].Columns[i]);
                         if (i < iCol - 1)
                         { sw.Write("\t"); }
                     sw.Write(sw.NewLine);
                     foreach (DataRow dr in dsInput.Tables[0].Rows)
                     {
                         for (int i = 0; i < iCol; i++)
                         {
                             if (!Convert.IsDBNull(dr[i]))
                             {
                                 sw.Write(dr[i].ToString());
                             }
                             if (i < iCol - 1)
                             { sw.Write("\t"); }
                         }
                         sw.Write(sw.NewLine);
                     }
                     sw.Close();
                     sFlag = "Success";
                 }
             }
             return sFlag;
         }
         catch (Exception)
         {
             return sFlag;
         }
     }

    С какого-то китайского сайта:
    http://www.datazx.cn/Forums/en-US/2d129cdc-2705-4035-90e2-063c4c399ae5/action?threadDisplayName=wpf-datagrid-remove-whitespace-from-string-on-clipboard-copy&forum=wpf
    Нафиг эксепшены, лучше вернем строку "Error"! Ну или "Success", если этот чудо-код еще и не грохнется.

    yamamoto, 05 Сентября 2014

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

    +158

    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
    <?php
    include 'config.php';
    $title = "Форум - $maintitle";
    $topic = $_GET['topic'];
    $board = $_GET['board'];
    $main = $_GET['main'];
    include 'core/funcs.php';
    include 'core/pdoconnect.php';
    include 'te/heads.php';
    echo '
     <div class="clear"></div>
        <!-- Content Section -->
        <div id="content_sec">
        	<!-- Column 1 -->
            <div class="col1">
            	<!-- Featured Playlist -->
            	<div class="featured_playlist">
                	<h3 class="heading">',$title,'</h3>
    
    				';
    
    if (isset($topic)){
    echo '<table>
      <tbody>
      <tr><th> Тема</th><th>Автор</th><th>Посл.обн.</th>
      </tr>';
    
    }
    if ($board > 0){
    echo '<table>
      <tbody>
      <tr><th> Тема</th><th>Автор</th><th>Посл.обн.</th>
      </tr>';
    $prepare = $db->prepare("SELECT * from `forum` where `board_id` = :bo_id order by `last_update` DESC");
    $prepare->bindParam(":bo_id", $board, PDO::PARAM_INT);
    $prepare -> execute();
    //print_r($prepare->errorinfo());
    if ($prepare->rowCount() == 0){
    echo '<p class = "error-box">В этом разделе еще не создано ни одной темы!</p>';
    }else{
    while($bo = $prepare->fetch(PDO::FETCH_BOTH)){
    echo '<tr><td><a href="forum-topic',$bo['id'],' "> ',$bo['title'],' </a></td><td> ',$bo['author'],'</td><td> ',$bo['last_author'],'</td></tr>';
    }
      }
    }
    if (isset($_GET['main'])){
    $i = 1;
    echo '
    <table>
      <tbody>
         <tr>
            <th>Основной</th><th>Новое</th>
         </tr>
    	 <tr><td><a href = "forum-board',$i++,' ">Работа сайта</a></td><td>',$last['0'],'</td></tr> 
    	 <tr><td><a href = "forum-board',$i++,' ">Пожелания и предложения</a></td><td>',$last['1'],'</td>
    	 <tr><th>Общение</th><th>Новое</th></tr>
    	 <tr><td><a href = "forum-board',$i++,' ">Общение</a></td><td>',$last['2'],'</td></tr>
    	 <tr><th>Работа</th><th>Новое</th></tr>
    	 <tr><td><a href = "forum-board',$i++,' ">Оффтоп</td><td>$last['3']</td></tr>
    	 <tr><td><a href = "forum-board',$i++,' ">Студенты</td><td>$last['4']</td></tr>
    	 <tr><td><a href = "forum-board',$i++,' ">Преподаватели</td><td>$last['5']</td></tr>
    	 <tr><td><a href = "forum-board',$i++,' ">Помощь</td><td>$last['6']</td></tr>
    	 <tr><td><a href = "forum-board',$i++,' ">Литература</td><td>$last['7']</td></tr>
    	 ';
    
    	 }
    
    
    echo '</tbody></table></div></div>';
    include 'te/foot.php';
    
    ?>

    В общем, добрался до исходников сайта нашего инста.
    Сам сайт имеет всего несколько частей - форум, лента новостей и ЛК.

    Это скрипт "форума".

    К слову, написано преподавателем со стажем работы 6 лет, как сам он нам доказывал и доказывает - часто фрилансит и все довольны. Чет не верится.

    И этот человек учит других...

    RSLab, 05 Сентября 2014

    Комментарии (11)
  6. Java / Говнокод #16647

    +64

    1. 1
    2. 2
    3. 3
    4. 4
    int r = 5;
        if (r ==5) {
            throw new Exception(); 
        }

    air_raptor, 05 Сентября 2014

    Комментарии (20)
  7. Java / Говнокод #16646

    +73

    1. 1
    Class <? extends Object> currentClass = Class.forName( clazz )

    Продолжаем разговор...

    sakkath, 05 Сентября 2014

    Комментарии (3)
  8. JavaScript / Говнокод #16645

    +156

    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
    Generator.prototype.update = function () {
    	var	t = this.timer++,
    		d = this.delay,
    		s = this.samples,
    		m = this.minDistance,
    		w = this.width,
    		h = this.height,
    		g = this.global,
    		c = this.cid,
    		ttl = this.ttl--,
    		l = s.length,
    		rand = Math.random,
    		floor = Math.floor,
    		x,
    		y,
    		r,
    		i,
    		j,
    		d2,
    		n;
    
    	if (ttl > 0) {
    		while (t > d) {
    			r = s[floor(rand() * l)].copy();
    
    			if (m) {
    				i = 1000;
    				while (i--) {
    					x = rand() * w - w * 0.5;
    					y = rand() * h - h * 0.5;
    
    					for (j in this) if (j instanceof Entity) {
    						n = this[i];
    						d2 = (x - n.x) * (x - n.x) + (y - n.y) * (y - n.y);
    
    						if (d2 * d2 > m) {
    							i = 0;
    						}
    					}
    				}
    			} else {
    				x = rand() * w - w * 0.5;
    				y = rand() * h - h * 0.5;
    			}
    
    			r.x = x;
    			r.y = y;
    
    			if (!g) {
    				r.parent = this;
    			}
    
    			this[c] = r;
    			this.cid = c += 1;
    			this.time = t -= d;
    		}
    	} else {
    		delete this.update;
    	}
    };

    асм-диалект яваскрипта

    prezident, 04 Сентября 2014

    Комментарии (7)
  9. Java / Говнокод #16644

    +75

    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
    db.insertInto(VISIBILITY_CONSTRAINT,
        VISIBILITY_CONSTRAINT.UUID,
        VISIBILITY_CONSTRAINT.VERSION,
        VISIBILITY_CONSTRAINT.FIRST_NAME_HIDDEN,
        VISIBILITY_CONSTRAINT.MIDDLE_NAME_HIDDEN,
        VISIBILITY_CONSTRAINT.LAST_NAME_HIDDEN,
        VISIBILITY_CONSTRAINT.BIRTHDAY_HIDDEN,
        VISIBILITY_CONSTRAINT.GENDER_HIDDEN,
        VISIBILITY_CONSTRAINT.EMAIL_HIDDEN,
        VISIBILITY_CONSTRAINT.COUNTRY_HIDDEN,
        VISIBILITY_CONSTRAINT.REGION_HIDDEN,
        VISIBILITY_CONSTRAINT.CITY_HIDDEN,
        VISIBILITY_CONSTRAINT.STREET_HIDDEN,
        VISIBILITY_CONSTRAINT.ZIP_CODE_HIDDEN,
        VISIBILITY_CONSTRAINT.PHONE_NUMBER_HIDDEN,
        VISIBILITY_CONSTRAINT.HOME_PAGE_HIDDEN,
        VISIBILITY_CONSTRAINT.HOBBIES_HIDDEN
    ).values(
        visibilityConstraintId,
        UInteger.valueOf(0),
        0.byteValue(),
        0.byteValue(),
        0.byteValue(),
        0.byteValue(),
        0.byteValue(),
        0.byteValue(),
        0.byteValue(),
        0.byteValue(),
        0.byteValue(),
        0.byteValue(),
        0.byteValue(),
        '0', // shit happens
        0.byteValue(),
        0.byteValue()
    ).execute()

    Пока писал тесты к говнопроекту, нашел PHONE_NUMBER_HIDDEN VARCHAR(64) NOT NULL. Hibernate по умолчанию ставил туда null. Там еще много всего, но остальное сюда не уместится.

    scriptin, 04 Сентября 2014

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

    +134

    1. 1
    2. 2
    if (paramList[i].GetType().Equals(typeof(String)))
    ...

    musuk, 04 Сентября 2014

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