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

    +160

    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
    #include <iostream>
    using namespace std;
    int main(){
    char b,a[1001];
    int i, c=0;
    cin >> b;
    for(i=1; i<=1000; i++)
      cin >> a[i];
    for( i=1; i<=1000; i++)
      if(a[i]=='b') c++;
    
    cout <<c<<" "<<b<<" characters in ";
    for(i=1; i<=1000; i++)
      cout << a[i];
    return 0;
    }  //помогите найти ошибку

    Источник - http://tinyurl.com/26n9df5

    Skiv, 12 Октября 2010

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

    +165

    1. 1
    2. 2
    3. 3
    4. 4
    5. 5
    6. 6
    7. 7
    function xchg(s,o,n)
    {	var r=s.split(o).join(n);
    	return r;
    }
    
    function toHTML(s)
    {return xchg(xchg(xchg(xchg(xchg(xchg(s,'<BR>',''),'<br>',''),'&lt;','<'),'&gt;','>'),'&amp;','&'),'\'\'','\'');}

    Кусок кода из моего скрипта Гостевой книги для Народа, добавляющей туда bb-теги, смайлы и прочие радости (сейчас там, вроде, скрипты уже вырезаются). Писалось лет 6 назад.

    В целом код в скрипте оказался на удивление еще не таким говнокодестым, как я ожидал. Есть еще пара кусочков говнокогда...

    Arigato, 12 Октября 2010

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

    +153

    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
    <script type="text/javascript">
    	// <![CDATA[
    	var tid=1429594;
    
    	var arr;
    	arr = new Array();var k=0;
    
    	var test;
    	function requestThread(pin) {
    		if (document.getElementById('p'+pin)) {
    			$('#t'+pin).html('<font color="#2255EE"><b>'+$('#t'+pin).html()+'</b></font>');
    			$.post('./lbitcomment.php', {u: 'http://site.livejournal.com/1429594.html?format=light&thread='+pin, i: $('#p'+pin).val()}, function (data)
    			{
    				$('#t'+pin).html(data);
    				p=p+1
    				while ((!document.getElementById('t'+arr[p])) && (p<=k)) 
    					p++;
    				if (p<=k) {
    					requestThread(arr[p]);
    				}
    				return;
    			});
    		} else {
    			p=p+1;
    			if (p<=k) 
    				requestThread(arr[p]);
    		}
    	return;
    	}
    
    	p=1;
    	$(document).ready(function(){
    		requestThread(arr[1]);	
    	});
    	
    
    	// ]]>
    	</script>

    Скрипт для разворачивания комментов ЖЖ ( http://www.hex.su/tools/open-thread/ ) добавляет в страницу такой вот код.

    seonull, 11 Октября 2010

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

    +144

    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
    // Devide vector
    Tuple<Complex[], Complex[]> DevideVector(Complex[] vector){
    Complex[] firstPart = new Complex[vector.Length / 2],
    secondPart = new Complex[vector.Length / 2];
    for (int index = 0; index < firstPart.Length; index++) { firstPart[index] = vector[index]; }
    for (int index = 0, offset = firstPart.Length; index < secondPart.Length; index++) { secondPart[index] = vector[index + offset]; }
    return new Tuple<Complex[], Complex[]>(firstPart, secondPart);}
    
    // FFT
    public Complex[] Transform(Complex[] vector){
    inverse = false;
    Complex[] result = Operation(vector);
    result = InverceIndexBits(result);
    for (int index = 0; index < vector.Length; index++) { result[index] /= result.Length; }
    return result;}
    
    // IFFT
    public Complex[] InverseTransform(Complex[] vector){
    inverse = true;
    Complex[] result = Operation(vector);
    result = InverceIndexBits(result);
    return result;}
    }}

    Код из лабы моего одногруппника. Яркий пример того, как НЕ НАДО оформлять код

    KoirN, 11 Октября 2010

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

    +157

    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
    // (c) Template Optimizer
    // (c) Template Compiler
    // skin/news.tpl
    
    /*<?php
    die ('<br /><br />Template Parser: <b>Access locked</b>');
    ?>*/
    
    $value0 = '
    
    ';
    if ( $this->get_tpl_tag ('USER.ACCESS') == '1' )
    {
    	$value0 .= '
    	';
    	$this->set_tpl_tag ('ACTION', 'new_add');
    	$value0 .= '
    	';
    	$this->set_tpl_tag ('SUBMIT', 'Добавить');
    	$value0 .= '
    	';
    	$this->set_tpl_tag ('CAPTION', 'Добавить новость');
    	$value0 .= '
    	' . $this->file_include ('content.tpl') . '
    ';
    }
    $value0 .= '
    
    ';
    $this->open_local (array ('NEW'));
    if ( is_array ($this->get_tpl_tag ('NEWS')) )
    foreach ( $this->get_tpl_tag ('NEWS') as $this->tags['NEW'] )
    {
    	$value0 .= '
    	<table class="news" width="100%">
    		<tr>
    			<th>
    				<h2>' . $this->get_tpl_tag ('NEW.TITLE') . '</h2>
    			</th>
    			<th align="right">
    				<span class="gensmall">' . $this->get_tpl_tag ('NEW.TIME') . ' </span>
    				';
    	if ( $this->get_tpl_tag ('USER.ACCESS') == '1' )
    	{
    		$value0 .= '
    					<a href="admin.php?action=new_edit&new=' . $this->get_tpl_tag ('NEW.ID') . '"><img src="' . $this->root_dir . '/images/rename.gif" alt="Редактировать" title="Редактировать" style="vertical-align: middle; border: none;" /></a>
    					<a href="admin.php?action=new_delete&new=' . $this->get_tpl_tag ('NEW.ID') . '" onclick="return confirm (\'Удалить новость за ' . $this->get_tpl_tag ('NEW.TIME') . '?\');"><img src="' . $this->root_dir . '/images/delete.gif" alt="Удалить" title="Удалить" style="vertical-align: middle; border: none;" />
    				';
    	}
    	$value0 .= '
    			</th>
    		</tr>
    		<tr>
    			<td colspan="2">
    				' . $this->get_tpl_tag ('NEW.BODY') . '
    			</td>
    		</tr>
    	</table>
    ';
    }
    $this->close_local();
    $value0 .= '
    
    ';
    $this->set_tpl_tag ('_ALIGN_', 'LEFT');
    $value0 .= '
    ' . $this->file_include ('pagebar.tpl');

    Вот такой "говнокод" выдает мой шаблонизатор после компилирования шаблона.
    В данном примере это блок новостей.

    Arigato, 11 Октября 2010

    Комментарии (34)
  6. PHP / Говнокод #4341

    +168

    1. 1
    2. 2
    3. 3
    4. 4
    function m($s, $re)
        {
            return preg_match($re, $s);
        }

    Из какого-то движка такая вот функа в файле function.php

    Arigato, 11 Октября 2010

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

    +144

    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
    void addSlash( const char* command, char* sdo )
    {
    	int command_length;
    	char *command_line = command;
    	command_length = strlen(command);
    	
    	while(command_length>0){
    		switch(*command_line){
    		   case '"':
    		           strcpy(sdo+strlen(sdo),"\\");
    		   default:
    		           strcpy(sdo+strlen(sdo), command_line);
    		}
    		command_line++;
    		command_length--;
    	}
    }

    Должно быть добавление слешей перед двойными кавычками.

    absolut, 11 Октября 2010

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

    +154

    1. 1
    2. 2
    3. 3
    String boo =  value[i]/*.ConvertTo<String>()*/;
    std::string boovalue(boo.Value());
    st.bind(1+i, boovalue.c_str());

    hamsta, 11 Октября 2010

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

    +169

    1. 1
    2. 2
    3. 3
    4. 4
    /* создать задачу */
    function add_problem($value) {
    ...
    }

    prof3d, 11 Октября 2010

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

    +1001

    1. 1
    2. 2
    3. 3
    4. 4
    5. 5
    6. 6
    7. 7
    8. 8
    9. 9
    string GetStringHash(string S)
            {
                MD5 md = MD5.Create();
                byte[] B = md.ComputeHash(Encoding.UTF8.GetBytes(S));
    
                return string.Format("{0}{1}{2}{3}{4}{5}{6}{7}{8}{9}{10}{11}{12}{13}{14}{15}",
                    B[0x00], B[0x01], B[0x02], B[0x03], B[0x04], B[0x05], B[0x06], B[0x07],
                    B[0x08], B[0x09], B[0x0A], B[0x0B], B[0x0C], B[0x0D], B[0x0E], B[0x0F]);
            }

    Запостил: 4eburashka, прямо перед выпилом ресурса.

    3.14159265, 11 Октября 2010

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