1. C# / Говнокод #1600

    +139

    1. 1
    dgridPFF1.Rows[1].Cells[1].Value = UtilHelper.Number2String(Convert.ToDouble(UtilHelper.StringToInvariantCulture(dgridPFF1.Rows[0].Cells[1].Value), UtilHelper.getCultureInfo()) / Convert.ToDouble(UtilHelper.StringToInvariantCulture(dgridPFF2.Rows[0].Cells[0].Value),UtilHelper.getCultureInfo()), 2); // String.Format(UtilHelper.getCultureInfo(),UtilHelper.NUMBERIC_FORMAT_2,Convert.ToDouble(dgridPFF1.Rows[0].Cells[1].Value) / Convert.ToDouble(dgridPFF2.Rows[0].Cells[0].Value, UtilHelper.getCultureInfo()));

    Виетнамский jungle code :)

    bugotrep, 16 Августа 2009

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

    +138.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
    public static void loadDataToDataGridView(DataGridView objDataGridView, List<object> objResultSet, IList objects)
            {
                if (objDataGridView == null || objResultSet == null) return;
    
                objDataGridView.Rows.Clear();
                for (int i = 0; i < objResultSet.Count; i++)
                {
                    for (int columnIndex = 0; columnIndex < ((List<object>)objResultSet[i]).Count; columnIndex++)
                    {
                        if (columnIndex == 0)
                        {
                            objDataGridView.Rows.Add();
                        }
                        objDataGridView.Rows[i].Cells[columnIndex].Value = ((List<object>)objResultSet[i])[columnIndex];
                    }
                    if (objects != null)
                    {
                        objDataGridView.Rows[i].Tag = objects[i];
                    }
                }
            }
    
            public static void loadDataToDataGridView(DataGridView objDataGridView, List<object> objResultSet)
            {
                loadDataToDataGridView(objDataGridView, objResultSet, null);
            }
    ...
    use of this code:
    ...
                List<object> values = new List<object>();
                List<object> value = new List<object>();
                if (_objPriceFormationFormula.RateVsEuro == 0)
                {
                    value.Add(UtilHelper.Number2String(1.00,2));// String.Format(UtilHelper.getCultureInfo(),UtilHelper.NUMBERIC_FORMAT_2,1.00));//1.00
                }
                else 
                {
                    value.Add(UtilHelper.Number2String(_objPriceFormationFormula.RateVsEuro,2));// String.Format(UtilHelper.getCultureInfo(),UtilHelper.NUMBERIC_FORMAT_2,_objPriceFormationFormula.RateVsEuro));
                }
                
                values.Add(value);
                UtilHelper.loadDataToDataGridView(this.dgridPFF2, values);

    Instead of databind :)

    bugotrep, 16 Августа 2009

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

    +139

    1. 01
    2. 02
    3. 03
    4. 04
    5. 05
    6. 06
    7. 07
    8. 08
    9. 09
    10. 10
    public bool IsEmpty()
            {
                int x = 0;
                x += EntityType.Length == 0 ? 1 : 0;
                x += EntityTypeName.Length == 0 ? 1 : 0;
                x += EntityDisplayName.Length == 0 ? 1 : 0;
                x += EntityId == Guid.Empty ? 1 : 0;
    
                return x == 0 ? false : true;
            }

    Аритметичный if :)

    bugotrep, 16 Августа 2009

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

    +155

    1. 1
    return i == -1 ? true : false;

    Ну это, если true, так true, а иначе false, чисто чтобы всем было понятно...

    victorsmirnov, 16 Августа 2009

    Комментарии (21)
  5. Си / Говнокод #1596

    +136

    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
    #include <stdio.h>
    #include <pthread.h>
    #include <unistd.h>
    #include <math.h>
    #include <stdlib.h>
    
    struct thread_arg
    {
    	int a;
    	int b;
    	int c;
    	double d;
    };
    	
    
    void *ret_x1(void *arg)
    {
    		
    	struct thread_arg targ = *(struct thread_arg *)arg;
    	double x1;
    	x1 = (-targ.b + sqrt(targ.d)) / (2*targ.a);
    
    	fprintf(stderr, "x1 = %f\n", x1);
    
    	return NULL;
    }
    
    void *ret_x2(void *arg)
    {
    	struct thread_arg targ = *(struct thread_arg*)arg;
    	double x2;
    	x2 = (-targ.b - sqrt(targ.d)) / (2*targ.a);
    
    	
    
    	fprintf(stderr, "x2 = %f\n", x2);
    	
    	return NULL;
    }
    
    int main(void)
    {
    	pthread_t thread1, thread2;
    	struct thread_arg args;
    
    	fprintf(stderr, "Enter a, b and c\n");
    	scanf("%d %d %d", &args.a, &args.b, &args.c);
    	
    	args.d = args.b*args.b - 4*args.a*args.c;
    
    	if(args.d < 0)
    	{
    		fprintf(stderr,"There is no roots\n");
    		return 0;
    	}
    	else
    	{
    		if(pthread_create(&thread1, NULL, &ret_x1, &args) != 0)
    		{
    			fprintf(stderr, "Error1\n");
    			return 1;
    		}
    		if(pthread_create(&thread2, NULL, &ret_x2, &args) != 0)
    		{
    			fprintf(stderr, "Error2\n");
    			return 1;
    		}
    		pthread_join(thread1, NULL);
    		pthread_join(thread2, NULL);
    
    	}
    	return 0;
    		
    }

    Многопоточное решение квадратного уравнения...

    zitzy, 16 Августа 2009

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

    +137

    1. 1
    2. 2
    3. 3
    4. 4
    5. 5
    6. 6
    if (messages[i].description != "")
                                if (messages[i].description.StartsWith("<![CDATA["))
                                {
                                    messages[i].description = messages[i].description.Substring(9);
                                    messages[i].description = messages[i].description.Substring(0, messages[i].description.Length - 3);
                                }

    для строк типа <![CDATA[******]!>
    Возникает устойчивое ощущение говнокода. Как нормально написать? :)

    ikovalyov, 16 Августа 2009

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

    +133.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
    46. 46
    47. 47
    48. 48
    49. 49
    50. 50
    51. 51
    52. 52
    53. 53
    54. 54
    55. 55
    public static XmlNode FindNodeXPath(XmlNode root, string xPath)
            {
                string[] paths = xPath.Split(new char[] { '/' });
                XmlNode node = root;
                for (int i = 0; i < paths.Length; i++)
                {
                    XmlNode childNode = null;
                    for (int j = 0; j < node.ChildNodes.Count; j++)
                    {
                        if (node.ChildNodes[j].Name == paths[i])
                        {
                            childNode = node.ChildNodes[j];
                            node = childNode;
                            break;
                        }
                    }
                    if (childNode == null)
                    {
                        return null;
                    }
                }
                return node;
            }
    
            public static XmlNode FindNodeXPath(XmlNode root, string nodeName, string xPath)
            {
                XmlNode node = FindNodeXPath(root, xPath);
                if (node != null)
                {
                    for (int i = 0; i < node.ChildNodes.Count; i++)
                    {
                        if (node.ChildNodes[i].Name == nodeName)
                        {
                            node = node.ChildNodes[i];
                        }
                    }
                }
                return node;
            }
    
            public static void UpdateBaseAddress(string url, string fileConfig)
            {
                // Create config file to create 
                XmlDocument xmlDom = new XmlDocument();
                xmlDom.Load(fileConfig);
                XmlNode root = xmlDom.DocumentElement;
                // Get XML node 
                XmlNode xmlNode = FindNodeXPath(root, "endpoint", "system.serviceModel/services/service");
                xmlNode.Attributes["address"].Value = url;
    
                xmlNode = FindNodeXPath(root, "add", "system.serviceModel/services/service/host/baseAddresses");
                xmlNode.Attributes["baseAddress"].Value = url;
    
                xmlDom.Save(fileConfig);
            }

    Виетнамский XPath эквивалент :)

    bugotrep, 15 Августа 2009

    Комментарии (2)
  8. 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)
  9. Куча / Говнокод #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)
  10. Куча / Говнокод #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)