1. PHP / Говнокод #1593

    +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
    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
    function strum($text, $simb)
    {
    if(mb_strlen($text, 'UTF-8') > $simb){
    
    }
    if(mb_strlen($text, 'UTF-8') > $simb)
      {
    	$start = 0;
    	for($i = 0; $i <= (ceil(mb_strlen($text, 'UTF-8') / $simb)); $i++)
    	{
    
    		$tmp = mb_strpos($text, '. ', $start + $simb, 'UTF-8');
    		if(is_numeric($tmp))
    		{
    			$num[] = $tmp;
    
    		}
    		$tmp = mb_strpos($text, '! ', $start  + $simb, 'UTF-8');
    				if(is_numeric($tmp))
    		{
    			$num[] = $tmp;
    
    		}
    		$tmp = mb_strpos($text, '? ', $start  + $simb, 'UTF-8');
    				if(is_numeric($tmp))
    		{
    			$num[] = $tmp;
    
    		}
    		if($num != '')
    		{
    		$end = min($num) + 1;
    		}
    		if($end <= $start)
    		{
    			$end = mb_strlen($text, 'UTF-8');
    		}
    		$str = mb_substr($text, $start, $end, 'UTF-8');
    		$string[] = mb_substr($str, 0, ($end - $start), 'UTF-8');
    
    	$start = $end;
    	unset($num);
    	unset($str);
    	unset($tmp);
    	if($end == mb_strlen($text, 'UTF-8'))
    		{
    			break;
    		}
    	}
      }
      else
      {
      $string[] = $text;
      }
      return $string;
    
    }

    Функция для умной разбивки

    Arrim, 15 Августа 2009

    Комментарии (1)
  2. Куча / Говнокод #1592

    +144.8

    1. 1
    2. 2
    3. 3
    4. 4
    5. 5
    6. 6
    7. 7
    8. 8
    rem = 1;/*
    @cls
    @cscript %~s0 //E:JScript //Nologo
    @exit /b
    */
    
    str = WScript.StdIn.ReadLine();
    WScript.StdOut.Write(1+2+3);

    Файл сохранять в *.BAT
    Это мой первый полиглот полиглот BAT и JScript.
    Про полиглоты на вики: http://en.wikipedia.org/wiki/Polyglot_(computing)

    k06a, 15 Августа 2009

    Комментарии (6)
  3. Куча / Говнокод #1591

    +57.7

    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
    73. 73
    74. 74
    75. 75
    76. 76
    77. 77
    78. 78
    @echo off
    cls
    pushd "%~d0%~p0"
    echo Current DIR: "%CD%"
    if "%~1" == "talk_widget" goto talker
    
    
    rem ////////////////////
    :auth
    echo Enter chat filename to connect ("abc" for example):
    set /p chat=^>
    echo Enter your nick:
    set /p nick=^>
    start call %0 talk_widget %chat% %nick%
    
    rem ////////////////////
    :listener
    cls
    call title "| Chat: %chat% | User: %nick% |"
    if exist %chat%_history type %chat%_history
    
    :list_go
    ping 127.0.0.1 -n 1 -w 20 > nul
    set oldtext=%text%
    set /p text=<%chat%
    if not "%text%" == "%oldtext%" echo %text%
    goto list_go
    rem ////////////////////
    
    
    rem ////////////////////
    rem // %2 - chat name //
    rem // %3 - user nick //
    rem ////////////////////
    :talker
    set chat=%~2
    set nick=%~3
    cls
    call title "| Chat: %chat% | User: %nick% |"
    call ::cs_in
    echo (%TIME% %nick% connected)>%chat%
    call ::cs_out
    echo (%TIME% %nick% connected)>>%chat%_history
    
    :talkloop
    cls
    echo Dear %nick%, type message to send:
    set /p msg=^>
    rem call ::cs_in
    echo [%TIME% %nick%]: %msg%>%chat%
    rem call ::cs_out
    echo [%TIME% %nick%]: %msg%>>%chat%_history
    goto talkloop
    rem ////////////////////
    
    
    rem ////////////////////
    :cs_in
    if exist "%chat%_cs" ping 127.0.0.1 -n 1 -w 50 > nul
    set cs_value=%RANDOM%
    
    :cs_in_loop
    echo %cs_value%>%chat%_cs
    set /p ret=<%chat%_cs
    if "%ret%" == "%cs_value%" exit /b
    ping 127.0.0.1 -n 1 -w 10 > nul
    goto :cs_in_loop
    rem ////////////////////
    
    
    rem ////////////////////
    :cs_out
    del %chat%_cs
    exit /b
    rem ////////////////////
    
    
    rem =========================================================

    Чат на BAT. Сколько угодно народу.
    Выложите батник в сетевую папку и оттуда запускайте с разных ПК.
    Статья с тонкостями: http://k06a.blogspot.com/2009/06/blog-post_27.html

    k06a, 15 Августа 2009

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

    +6.9

    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
    #ifndef SOCHET_H
    #define SOCHET_H
    
    // Сдвигает самую младшую единицу в сторону младшего разряда
    #define shiftLast1Right(x) ( (x-1)^((x^(x-1)) >> 2) )
    
    // Дописывает 1 после самой младшей единицы
    #define add1AfterLast1(x) ( x | ((x^(x-1))+1) >> 2 )
    
    template<class T>
    class Sochet
    {
    public:
    	T value;
    
    	//////////////////////////////////////////////////////////////////////////
    
    	Sochet():value(0) { }
    	Sochet(int n, int k) {
    		firstTurn(n, k);
    	}
    	~Sochet() {
    		value = 0;
    	}
    
    	//////////////////////////////////////////////////////////////////////////
    
    	// Первая комбинация
    	// В первоначальной ситуации все К единиц располагаются в старших битах
    	void firstTurn(int n, int k) {
    		value = ( ( T(1) << k ) - 1 ) << (n - k);
    	}
    
    	// Нахождение следующей комбинации
    	// Возвращает false в случае последней комбинации
    	bool nextTurn()
    	{
    		// Отлов последней комбинации
    		if (value & (value+1) == 0)
    			return false;
    		
    		// Условие по младшему биту: 1 или 0
    		if (value & 1)
    		{
    			value >>= 1;
    			nextTurn();
    			value = add1AfterLast1(value << 1);
    		} else
    			value = shiftLast1Right(value);
    		
    		return true;
    	}
    }
    
    #endif // SOCHET_H

    Шаблон перебора всех сочетаний/выборок в много разрядных числах.
    Пример перебираемых чисел для N=5, K=3:
    11100
    11010
    11001
    10110
    10101
    10011
    01110
    01101
    01011
    00111

    // Код выглядит сочно(особенно дефайны), зато всё работает максимально быстро.
    // Статья про этот алгоритм: http://k06a.blogspot.com/2009/04/blog-post_08.html

    k06a, 15 Августа 2009

    Комментарии (9)
  5. Pascal / Говнокод #1589

    +86.2

    1. 1
    2. 2
    3. 3
    4. 4
    5. 5
    with (VirNode^) do
    begin
      VirNode^.ImageIndex := vir.iNum;
      VirNode^.Txt := vir.sAttr[1] + ' - ' + vir.sAttr[3];
    end;

    сначала было без with а потом забыл убрать "VirNode^." :)

    Joe, 15 Августа 2009

    Комментарии (10)
  6. JavaScript / Говнокод #1588

    +148.7

    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
    // Any fool can write code that a computer can understand. Good programmers write code that humans can understand. (C) Martin Fowler.
    function changeLogo() {
    	var pane = document.getElementById("pane");
    	if(pane != null) {
    		pane.height = 240;
    		pane.width = document.body.clientWidth;
    	} else {
    		alert("it's sad, so sad...");
    	}
    	var logo = document.getElementById("logoJpg");
    	if(logo != null) {
    		logo.height = 50;
    		logo.width = document.body.clientWidth * 0.23;
    	} else {
    		alert(" ...it's a sad, sad situation, and it's getting more and more absurd");
    	}
    }

    Код совсем ничего, но камменты рулят

    domavoy, 15 Августа 2009

    Комментарии (4)
  7. Куча / Говнокод #1587

    +54.7

    1. 1
    2. 2
    3. 3
    4. 4
    5. 5
    6. 6
    <div style="padding: 2px;"> 
        <div class="go_left">
            <font color="#777777">Account balance:</font> <span id="js_total_hours" style="margin: 0px; padding: 0px;">2</span> hours
        </div> 
        <div class="clear"></div> 
    </div>

    go_left - стиль с float: left
    clear - стиль с clear: both
    как минимум спрашивается зачем давать флоэт лефт единстенному элементу в диве.

    nonexistent, 15 Августа 2009

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

    +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
    <?php
    $thelist = array();
    $dir = './upload/ftp/';
    if ($handle = opendir($dir)) {
    	while (false !== ($file = readdir($handle))) {
    		if ($file != "." && $file != ".." && $file !="index.php" && $file !=".ftpquota") {
    			$file = $file;
    			$thelist[] = array('file' => $file, 'filemtime' => filemtime($file), 'filesize' => filesize($file));
    		}
    	}
    
    	closedir($handle);
    }
    ?>
    <?php
    for($i = 0; $i < count($thelist); $i++) {
    	?><a href="sitename/<?=$thelist[$i]['file']?>"><?=$thelist[$i]['file']?></a><?php
    }
    ?>

    scrat, 14 Августа 2009

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

    +12.1

    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
    73. 73
    74. 74
    75. 75
    76. 76
    77. 77
    78. 78
    79. 79
    DateTime get_date(const char * _sz_date, bool _b_trunc_year)
    {
    	DateTime _obj_dt;
    
    	// "01/02/2003" - format of the data
    
    	string _str_date = _sz_date;
    
     	//--------------
    
    	string _str_month;
    	string _str_year;
    
    	int _n_day;
    	int _n_month;
    	int _n_year;
    
     	///--------------
    
    	bool _b_1 = false;
    	bool _b_2 = false;
    
    	size_t _n_pos_1 = 0;
    	size_t _n_pos_2 = 0;
    
    	///--------------
    
    	for (size_t _un_num = 0; _un_num < _str_date.size(); _un_num++)
    	{
    		if(_str_date[_un_num] == '/')
    		{
    			///-----------------
    			if(!_b_1)
    			{
    				_b_1 		= true;
    				_n_pos_1 	= _un_num;
    
            			continue;
    			}
    			///-----------------
    			if(_b_1 && !_b_2)
    			{
    				_b_2 		= true;
    				_n_pos_2 	= _un_num;
    			}
    			///-----------------
    		}
    	}
    
     	///--------------
    
    	if(!_b_1 || !_b_2)
    	{
    		return _obj_dt;
    	}
    
     	///--------------
    
    	_str_month = _str_date.substr( _n_pos_1 + 1, ( _n_pos_2 - _n_pos_1 ) - 1 );
    
     	_str_year  = _str_date.substr( _n_pos_2 + 1, ( _str_date.size() - 1 ) -  _n_pos_2 );
    
     	if(_b_trunc_year)
    	{
        		if(_str_year.size() >=4)
       			{
          			_str_year = _str_year.substr(2,2);
        		}
     	}
    
    	sscanf(_str_month.c_str(), "%d", &_n_month);
    	sscanf(_str_year .c_str(), "%d", &_n_year);
    
    	_n_day = 1;
    
    	_obj_dt = DateTime(_n_year,_n_month,_n_day);
    
    	return _obj_dt;
    }

    Парсим дату формата mm/dd/yyyy. Не все так просто в этой жизни.

    lamer, 14 Августа 2009

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

    +5

    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
    //...
      string m_str_datum, m_str_zeit;
      m_str_datum.assign(m_str_data , 22 ,  6 ); 
      m_str_zeit.assign(m_str_data , 28 ,  6 );
      m_str_datum = remove_spaces(m_str_datum) ;
      m_str_zeit  = remove_spaces(m_str_zeit);  
    
      string _str_year;
      string _str_month;
      string _str_day;
    
      int _n_year;
      int _n_month;
      int _n_day;
    
      _n_year  = 0;
      _n_month = 0;
      _n_day   = 0;
    
      _str_day.assign(m_str_datum,0,2);
      _str_month.assign(m_str_datum,2,2);
      _str_year.assign(m_str_datum,4,2);
    
      sscanf( _str_day.c_str()  , "%d", &_n_day   );
      sscanf( _str_month.c_str(), "%d", &_n_month );
      sscanf( _str_year.c_str() , "%d", &_n_year  );
      if (_n_year > 0 && _n_year < 50)
    	_n_year += 2000;
      else if (_n_year >= 50 && _n_year < 100)
    	_n_year += 1900;
    
      //...
      string _str_hours;
      string _str_minutes;
      string _str_seconds;
     
      int _n_hours;
      int _n_minutes;
      int _n_seconds;
    
      _n_hours   = 0;
      _n_minutes = 0;
      _n_seconds = 0;
    
      _str_hours.assign(m_str_zeit,0,2);
      _str_minutes.assign(m_str_zeit,2,2);
      _str_seconds.assign(m_str_zeit,4,2);
    
      sscanf( _str_hours.c_str()   , "%d", &_n_hours    );
      sscanf( _str_minutes.c_str() , "%d", &_n_minutes  );
      sscanf( _str_seconds.c_str() , "%d", &_n_seconds  );
    
      DateTime _obj_start_time;
    
      try {
    	_obj_start_time = DateTime(_n_year,  _n_month,   _n_day, _n_hours, _n_minutes, _n_seconds);
      }
    //...

    Парсим дату ddmmyyhhnnss не по-детски. Код функции которая обрабатывает несколько сотен тысяч строк.

    lamer, 14 Августа 2009

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