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

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

    +133

    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
    /// <summary>
            /// Подключение к удаленному трек серверу
            /// Повторяет попытки подключения в фоновом режиме.
            /// </summary>
            public void ConnectToTrackServer()
            {
                lock (LockConnToTrack)
                {
                    if (ConnTrackServer == null)
                    {
                        ConnTrackServer = new Thread(new ParameterizedThreadStart(ConnectToTrackServerAsync));
                        ConnTrackServer.Start();
                    }
                    else if (!ConnTrackServer.IsAlive)
                    {
                        ConnTrackServer.Start();
                    }
                }
                //ThreadPool.QueueUserWorkItem(new WaitCallback(ConnectToTrackServerAsync));
            }

    Продолжение к прошлому посту

    HLW, 02 Марта 2013

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

    −162

    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
    /*здесь было много кода*/
    
    DECLARE @Strings TABLE /* in this temporary table we keep all strings, even the names of the elements, since they are 'escaped' in a different way, and may contain, unescaped, brackets denoting objects or lists. These are replaced in the JSON string by tokens representing the string */
        (
         String_ID INT IDENTITY(1, 1),
         StringValue NVARCHAR(MAX)
        )
      SELECT--initialise the characters to convert hex to ascii
        @characters='0123456789abcdefghijklmnopqrstuvwxyz',
      /* firstly we process all strings. This is done because [{} and ] aren't escaped in strings, which complicates an iterative parse. */
        @parent_ID=0;
      WHILE 1=1 --forever until there is nothing more to do
        BEGIN
          SELECT
            @start=PATINDEX('%[^a-zA-Z]["]%', @json collate SQL_Latin1_General_CP850_Bin);--next delimited string
          IF @start=0 BREAK --no more so drop through the WHILE loop
          IF SUBSTRING(@json, @start+1, 1)='"'
            BEGIN --Delimited Name
              SET @start=@Start+1;
              SET @end=PATINDEX('%[^\]["]%', RIGHT(@json, LEN(@json+'|')-@start) collate SQL_Latin1_General_CP850_Bin);
            END
          IF @end=0 --no end delimiter to last string
            BREAK --no more
          SELECT @token=SUBSTRING(@json, @start+1, @end-1)
          --now put in the escaped control characters
          SELECT @token=REPLACE(@token, FROMString, TOString)
          FROM
            (SELECT
              '\"' AS FromString, '"' AS ToString
             UNION ALL SELECT '\\', '\'
             UNION ALL SELECT '\/', '/'
             UNION ALL SELECT '\b', CHAR(08)
             UNION ALL SELECT '\f', CHAR(12)
             UNION ALL SELECT '\n', CHAR(10)
             UNION ALL SELECT '\r', CHAR(13)
             UNION ALL SELECT '\t', CHAR(09)
            ) substitutions
          SELECT @result=0, @escape=1
      --Begin to take out any hex escape codes
          WHILE @escape>0
            BEGIN
              SELECT @index=0,
              --find the next hex escape sequence
              @escape=PATINDEX('%\x[0-9a-f][0-9a-f][0-9a-f][0-9a-f]%', @token collate SQL_Latin1_General_CP850_Bin)
              IF @escape>0 --if there is one
                BEGIN
                  WHILE @index<4 --there are always four digits to a \x sequence  
                    BEGIN
                      SELECT --determine its value
                        @result=@result+POWER(16, @index)
                        *(CHARINDEX(SUBSTRING(@token, @escape+2+3-@index, 1),
                                    @characters)-1), @index=@index+1 ;
            
                    END
                    -- and replace the hex sequence by its unicode value
                  SELECT @token=STUFF(@token, @escape, 6, NCHAR(@result))
                END
            END
          --now store the string away
          INSERT INTO @Strings (StringValue) SELECT @token
          -- and replace the string with a token
          SELECT @JSON=STUFF(@json, @start, @end+1,
                        '@string'+CONVERT(NVARCHAR(5), @@identity))
        END

    парсинг json-строки sql скриптом. полная версия тут : https://www.simple-talk.com/sql/t-sql-programming/consuming-json-strings-in-sql-server/

    mozg_raka, 20 Февраля 2013

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

    +141

    1. 1
    http://www.youloveit.ru/uploads/gallery/main/439/youloveit_ru_pony-arts07.png

    dos_, 15 Февраля 2013

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

    +141

    1. 1
    2. 2
    3. 3
    4. 4
    5. 5
    6. 6
    7. 7
    8. 8
    var declination= function(n, form1, form2, form5){
            n = n % 100;
            var n1 = n % 10;
            if (n > 10 && n < 20) return form5;
            if (n1 > 1 && n1 < 5) return form2;
            if (n1 == 1) return form1;
            return form5;
        }

    хуита, 15 Февраля 2013

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

    +133

    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
    private function init_categories()
    	{
    		// Дерево категорий
    		$tree = new stdClass();
    		$tree->subcategories = array();
    		
    		// Указатели на узлы дерева
    		$pointers = array();
    		$pointers[0] = &$tree;
    		$pointers[0]->path = array();
    		
    		// Выбираем все категории
    		$query = $this->db->placehold("SELECT c.id, c.parent_id, c.name, c.description, c.url, c.meta_title, c.meta_keywords, c.meta_description, c.image, c.visible, c.position
    										FROM __categories c ORDER BY c.parent_id, c.position");
    											
    		// Выбор категорий с подсчетом количества товаров для каждой. Может тормозить при большом количестве товаров.
    		// $query = $this->db->placehold("SELECT c.id, c.parent_id, c.name, c.description, c.url, c.meta_title, c.meta_keywords, c.meta_description, c.image, c.visible, c.position, COUNT(p.id) as products_count
    		//                               FROM __categories c LEFT JOIN __products_categories pc ON pc.category_id=c.id LEFT JOIN __products p ON p.id=pc.product_id AND p.visible GROUP BY c.id ORDER BY c.parent_id, c.position");
    		
    		
    		$this->db->query($query);
    		$categories = $this->db->results();
    				
    		$finish = false;
    		// Не кончаем, пока не кончатся категории, или пока ниодну из оставшихся некуда приткнуть
    		while(!empty($categories)  && !$finish)
    		{
    			$flag = false;
    			// Проходим все выбранные категории
    			foreach($categories as $k=>$category)
    			{
    				if(isset($pointers[$category->parent_id]))
    				{
    					// В дерево категорий (через указатель) добавляем текущую категорию
    					$pointers[$category->id] = $pointers[$category->parent_id]->subcategories[] = $category;
    					
    					// Путь к текущей категории
    					$curr = $pointers[$category->id];
    					$pointers[$category->id]->path = array_merge((array)$pointers[$category->parent_id]->path, array($curr));
    					
    					// Убираем использованную категорию из массива категорий
    					unset($categories[$k]);
    					$flag = true;
    				}
    			}
    			if(!$flag) $finish = true;
    		}
    		
    		// Для каждой категории id всех ее деток узнаем
    		$ids = array_reverse(array_keys($pointers));
    		foreach($ids as $id)
    		{
    			if($id>0)
    			{
    				$pointers[$id]->children[] = $id;
    
    				if(isset($pointers[$pointers[$id]->parent_id]->children))
    					$pointers[$pointers[$id]->parent_id]->children = array_merge($pointers[$id]->children, $pointers[$pointers[$id]->parent_id]->children);
    				else
    					$pointers[$pointers[$id]->parent_id]->children = $pointers[$id]->children;
    					
    				// Добавляем количество товаров к родительской категории, если текущая видима
    				// if(isset($pointers[$pointers[$id]->parent_id]) && $pointers[$id]->visible)
    				//		$pointers[$pointers[$id]->parent_id]->products_count += $pointers[$id]->products_count;
    			}
    		}
    		unset($pointers[0]);
    		unset($ids);
    
    		$this->categories_tree = $tree->subcategories;
    		$this->all_categories = $pointers;	
    	}

    построение дерева категорий в платной cms simpla

    alpex, 15 Февраля 2013

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

    +136

    1. 1
    var defaultMapping = (mappings.ContainsKey((Int32?)null)) ? mappings[(Int32?)null] : null;

    startrack, 07 Февраля 2013

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

    +51

    1. 1
    http://forum.php.su/topic.php?forum=71&topic=8913

    Бывает и такое...

    deep, 31 Января 2013

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

    +130

    1. 01
    2. 02
    3. 03
    4. 04
    5. 05
    6. 06
    7. 07
    8. 08
    9. 09
    10. 10
    11. 11
    public XDocument GetHelpFile(string path)
    {
          try
          {
            return _dataFacade.LoadDocument(path);
          }
          catch
          {
            return null;
          }
    }

    taburetka, 23 Января 2013

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

    −161

    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
    create temp table data (id serial, o1 money(16,2) default 0, o2 money(16,2) default 0,
    o3 money(16,2) default 0, o4 money(16,2) default 0, o5 money(16,2) default 0,
    o6 money(16,2) default 0, o7 money(16,2) default 0, o8 money(16,2) default 0,
    o9 money(16,2) default 0, o10 money(16,2) default 0, o11 money(16,2) default 0,
    o12 money(16,2) default 0, o13 money(16,2) default 0, o14 money(16,2) default 0,
    o15 money(16,2) default 0, o16 money(16,2) default 0, o17 money(16,2) default 0,
    o18 money(16,2) default 0, o19 money(16,2) default 0, o20 money(16,2) default 0,
    o21 money(16,2) default 0, o22 money(16,2) default 0, o23 money(16,2) default 0,
    o24 money(16,2) default 0, o25 money(16,2) default 0, o26 money(16,2) default 0,
    o27 money(16,2) default 0, o28 money(16,2) default 0, o29 money(16,2) default 0,
    o30 money(16,2) default 0, o31 money(16,2) default 0, f1 money(16,2) default 0,
    f2 money(16,2) default 0, f3 money(16,2) default 0, f4 money(16,2) default 0,
    f5 money(16,2) default 0, f6 money(16,2) default 0, f7 money(16,2) default 0,
    f8 money(16,2) default 0, f9 money(16,2) default 0, f10 money(16,2) default 0,
    f11 money(16,2) default 0, f12 money(16,2) default 0, f13 money(16,2) default 0,
    f14 money(16,2) default 0, f15 money(16,2) default 0, f16 money(16,2) default 0,
    f17 money(16,2) default 0, f18 money(16,2) default 0, f19 money(16,2) default 0,
    f20 money(16,2) default 0, f21 money(16,2) default 0, f22 money(16,2) default 0,
    f23 money(16,2) default 0, f24 money(16,2) default 0, f25 money(16,2) default 0,
    f26 money(16,2) default 0, f27 money(16,2) default 0, f28 money(16,2) default 0,
    f29 money(16,2) default 0, f30 money(16,2) default 0, f31 money(16,2) default 0,
    ftot money(16,2) default 0)

    ... must be funny in the rich man's world ...

    bormand, 18 Января 2013

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

    +14

    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
    /*!
     * \brief Checks for a file existence
     */
    inline bool IsFolderExist( const boost::filesystem::path &path )
    {
        return boost::filesystem::exists( path ) && boost::filesystem::is_directory( path );
    }
    
    
    /*!
     * \brief Checks for a folder existence
     */
    inline bool IsFileExist( const boost::filesystem::path &path )
    {
        return boost::filesystem::exists( path ) && boost::filesystem::is_regular_file( path );
    }

    Нашёл у себя в проекте. Кручу верчу - обмануть хочу). Про то, что даже правильные комментарии тут нафиг не нужны - я уже молчу.

    suc-daniil, 17 Января 2013

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