1. Список говнокодов пользователя laMer007

    Всего: 74

  2. C++ / Говнокод #20371

    0

    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
    SoftwareCommon::params::IParamLoader::TypeDb SettingsProxy::getTypeDb() const
    	{
    		try
    		{
    			auto type = Locator::Services::Locator->Resolve<ISettings^>()->Type;
    			switch (type)
    			{
    			case decltype(type)::Firebird: return IParamLoader::Firebird;
    			case decltype(type)::MSSQL: return IParamLoader::MSSQL;
    			default:
    				throw std::runtime_error("Unsupported db type");
    			}
    		}
    		catch (Exception ^ex)
    		{
    			throw std::runtime_error(marshal_1251(ex->ToString()));
    		}
    	}

    laMer007, 13 Июля 2016

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

    +2

    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
    #include <iostream>
    #include <stdexcept>
    
    using namespace std;
    
    class Exception : std::runtime_error
    {
    public:
        Exception( std::string const & what ) : std::runtime_error(what)
        {
        }
    };
    
    int main( )
    {
        try
        {
            throw Exception("Exception");
        }
        catch ( std::exception const & e )
        {
            std::cerr << e.what() << std::endl;
        }
        catch(...)
        {
            std::cerr << "..." << std::endl;
        }
        return 0;
    }

    laMer007, 08 Июля 2016

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

    +2

    1. 1
    https://whydoesitsuck.com/cpp-sucks-for-a-reason/

    laMer007, 01 Июля 2016

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

    +2

    1. 1
    https://m.reddit.com/r/cpp/comments/4pmlpz/what_the_iso_c_committee_added_to_the_c17_working/

    Мне остаётся только спросить:

    laMer007, 26 Июня 2016

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

    +5

    1. 1
    2. 2
    3. 3
    Тут недавно оказия вышла. В одном чатике, где были несколько программистов и математик, задали вопрос:
    
    В каком порядке наследование верное целые числа -> рациональные или наоборот?

    laMer007, 22 Июня 2016

    Комментарии (92)
  7. SQL / Говнокод #20211

    −41

    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
    80. 80
    81. 81
    82. 82
    83. 83
    84. 84
    85. 85
    86. 86
    87. 87
    88. 88
    create procedure [dbo].[GetXML] (
    	@ExternalId		varchar(255)
    )	
    as
    begin
    	declare @Contained int = 2;
    	declare @Sent int = 3;
    	declare @ResultAdmissionSubmissionNO int = 76;
    	declare @dcStateSent int = 7;
    	declare @dcStateInProgress int = 1;
    	declare @dcStateFinishedWithError int = 2;
    	declare @dcStateFinished int = 3;
    
    with ExternalIdMain as (
    select 
    	ExternalId as ExternalId,
    	dc.DocCircId as GroupId,
    	dc.DocCircId as DocCircId
    	from 
    	[dbo].[gate_DocCirculations] as gdc
    	inner join [dbo].[DocCirculations] as dc on dc.DocCircId = gdc.DocCircId and not exists 
    		(select TOP 1 1 from [dbo].[DocCircConnection] as dcci where dcci.Parent = dc.DocCircId or dcci.Child = dc.DocCircId )
    	where ExternalId = @ExternalId and 
    		dc.StateId in (@dcStateSent, @dcStateInProgress, @dcStateFinishedWithError, @dcStateFinished)
    	union all
    select 
    	ExternalId as ExternalId,
    	dcc0.Parent as GroupId,
    	dcc0.Child as DocCircId
    	from 
    	--dcc0.Child is leaf
    	[dbo].[DocCircConnection] as dcc0 
    	inner join [dbo].[DocCircConnection] as dcc1 on dcc0.Parent = dcc1.Child and dcc0.ConnectionType = @Contained and dcc1.ConnectionType = @Sent
    	inner join [dbo].[gate_DocCirculations] as gdc on dcc1.Parent = gdc.DocCircId
    	where ExternalId = @ExternalId
    ),
    ExternalIdStates as (
    	select 
    		eim.ExternalId as ExternalId,
    		eim.GroupId as GroupId, 
    		dcsg.StateId as GroupState, 
    		dcsg.[Description] as GroupStateDescription, 
    		eim.DocCircId as DocCircId, 
    		dcs.StateId as DocCircState, 
    		dcs.[Description] as DocCircStateDescription, 
    		dc.timeUpdate as [Date] 
    		from 
    	ExternalIdMain as eim
    	inner join dbo.DocCirculations as dc on eim.DocCircId = dc.DocCircId
    	inner join dbo.DocCirculations as dcg on eim.GroupId = dcg.DocCircId
    	inner join dbo.DocCircStates as dcs on dcs.StateId = dc.StateId
    	inner join dbo.DocCircStates as dcsg on dcsg.StateId = dcg.StateId
    ),
    ExternalIdFull as (
    select
    	ExternalId as ExternalId,
    	GroupId as GroupId,
    	GroupState as GroupState,
    	GroupStateDescription as GroupStateDescription,
    	eis.DocCircId as DocCircId,
    	DocCircState as DocCircState,
    	DocCircStateDescription as DocCircStateDescription,
    	[Date] as [Date],
    	[Filename] as [Filename]
    from 
    ExternalIdStates as eis
    left join dbo.Transactions as t on eis.DocCircId = t.DocCircId and t.idTranstype = @ResultAdmissionSubmissionNO
    left join dbo.Docs as d on t.idTransaction = d.idTransaction
    left join dbo.Contents as c on d.idContent = c.idContent
    )
    select ExternalId as "@Value",
    (
    	select GroupId as "@GroupId", Max(GroupState) as "@GroupState", Max(GroupStateDescription) as "@GroupStateDescription",
    	(
    		select DocCircId as "@DocCircId", Max(DocCircState) as "@DocCircState", Max(DocCircStateDescription) as "@DocCircStateDescription", Max([Date]) as "@Date",
    		(
    			--"case when" for null filenames
    			case when 
    						(exists (select TOP 1 [Filename] from ExternalIdFull as eif3 where eif3.DocCircId = eif2.DocCircId and [Filename] is not null))
    				then (select [Filename] as "@Value" from ExternalIdFull as eif3 where eif3.DocCircId = eif2.DocCircId FOR XML PATH('Filename'), type) 
    				else N'' end
    		)
    		from ExternalIdFull as eif2 where eif2.GroupId = eif1.GroupId group by DocCircId FOR XML PATH('DocCirc'), type
    	)
    	from ExternalIdFull as eif1 where eif1.ExternalId = eif0.ExternalId group by GroupId FOR XML PATH('Group'), type
    )
    from ExternalIdFull as eif0 group by ExternalId FOR XML PATH('ExternalId'), Root('Root')
    end

    laMer007, 15 Июня 2016

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

    0

    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
    unsigned int FileScanner::smartBruteForce(QByteArray &haystack, QByteArray &needle)
    {
        unsigned int count = 0;
        unsigned int dataSize = haystack.size();
        unsigned int needleSize = needle.size();
        unsigned int needleSizeCut = needleSize - 1;
        char* dp = haystack.data();
        char* np = needle.data();
        char lastNeedle = *(np + needleSize - 1);
    
        for(unsigned int i = 0; i < dataSize - needleSize + 1; i++)
        {
            if(*(dp + (i + needleSizeCut)) != lastNeedle) //This is smart technology ))))
                continue;
            unsigned int j;
            for(j = 0; j < needleSize; j++)
            {
                if(*(dp + (i + j)) != *(np + j))
                    break;
            }
            if(j == needleSize)
                count++;
        }
        return count;
    }

    laMer007, 20 Февраля 2016

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

    −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
    #include <iostream>
    using namespace std;
    
    auto print(auto arg)
    {
    	return (cout<<arg);
    	//return cout;
    }
    auto print(auto arg, auto... args)
    {
    	return (print(args...)<<arg);
    	//return cout;
    }
    
    int main() {
    	print(1,"ko")<<"ok";
    	return 0;
    }

    https://ideone.com/YvoHi3
    ГЦЦ так и не научился в возвращаемые значения с авто

    laMer007, 02 Февраля 2016

    Комментарии (12)
  10. Куча / Говнокод #19350

    +1

    1. 001
    2. 002
    3. 003
    4. 004
    5. 005
    6. 006
    7. 007
    8. 008
    9. 009
    10. 010
    11. 011
    12. 012
    13. 013
    14. 014
    15. 015
    16. 016
    17. 017
    18. 018
    19. 019
    20. 020
    21. 021
    22. 022
    23. 023
    24. 024
    25. 025
    26. 026
    27. 027
    28. 028
    29. 029
    30. 030
    31. 031
    32. 032
    33. 033
    34. 034
    35. 035
    36. 036
    37. 037
    38. 038
    39. 039
    40. 040
    41. 041
    42. 042
    43. 043
    44. 044
    45. 045
    46. 046
    47. 047
    48. 048
    49. 049
    50. 050
    51. 051
    52. 052
    53. 053
    54. 054
    55. 055
    56. 056
    57. 057
    58. 058
    59. 059
    60. 060
    61. 061
    62. 062
    63. 063
    64. 064
    65. 065
    66. 066
    67. 067
    68. 068
    69. 069
    70. 070
    71. 071
    72. 072
    73. 073
    74. 074
    75. 075
    76. 076
    77. 077
    78. 078
    79. 079
    80. 080
    81. 081
    82. 082
    83. 083
    84. 084
    85. 085
    86. 086
    87. 087
    88. 088
    89. 089
    90. 090
    91. 091
    92. 092
    93. 093
    94. 094
    95. 095
    96. 096
    97. 097
    98. 098
    99. 099
    100. 100
    -- Few Scum
    import Data.Char
    import Text.Read
    import Control.Applicative
    import Data.Ratio
    import Numeric
    import Data.List
    import Data.Maybe
    data Token
        =TLetter Char
        |TNumf Rational
        |TOp Char
        |LBrace
        |RBrace
        deriving (Show, Eq)
    data Expr
        =Letter Char
        |Numf Rational
        |Op Char Expr Expr
        |Diff Expr
    instance Show Expr where
        show (Letter c)     = [c]
        show (Op c el er)   = '(' : show el ++ ')' :
            c : '(' : show er ++ ")"
        show (Numf v)       = show $ toDouble v
        show (Diff e)       = '(' : show e ++ ")'"
    
    toDouble r = fromRational r :: Double
    readUnsignedRationalMaybe f = getParseResult $ parseValue f where
        parseValue f = {- readSigned -} readFloat f :: [(Rational, String)]
        getParseResult [(value, "")] = Just value
        getParseResult _ = Nothing
    
    -- Разбиваем строку на элементы, возаращает перевернутый список токенов
    tokenize ""                     = Nothing
    tokenize sourceExpressionString = tok [] sourceExpressionString where
        tok [] (c:s)
            | c == '-'                  = tok [TOp '-', TNumf 0] s
        tok r@(LBrace:_) (c:s)
            | c == '-'                  = tok (TOp '-':TNumf 0:r) s
        tok r (c:s)
            | c == '('                  = tok (LBrace:r) s
            | c == ')'                  = tok (RBrace:r) s
            | isLetter c                = tok (TLetter c:r) s
            | isOperation c             = tok (TOp c:r) s
            | isNumber c                = parseNumf r (c:s)
        tok r ""                        = Just r
        tok resultParsedTokens sourceExpressionString = Nothing
        isOperation     = (`elem` "+-*/")
        isNumf c        = isNumber c || c == '.'
        parseNumf r s   = maybeNumber >>= makeResult where
            (numberString, tail) = span isNumf s
            maybeNumber = readUnsignedRationalMaybe numberString--readMaybe numberString
            makeResult number = tok (TNumf number:r) tail
    
    -- Дерево выражений из списка токенов
    parse reversedTokens             = reversedTokens >>= makeTree where
        priorityOps         = ["+-","/*"]
        subExpr             = splitIntoOperationAndSubExpressions
        splitIntoOperationAndSubExpressions reversedTokens =
            id =<< find isJust (map (findOp reversedTokens [] 0) priorityOps)
        findOp (LBrace:_) _ 0 _         = Nothing -- dont checked on left expression, probably can safety removed
        findOp (RBrace:l) r b ops       = findOp l (RBrace:r) (b+1) ops
        findOp (LBrace:l) r b ops       = findOp l (LBrace:r) (b-1) ops
        findOp (TOp c:l) r 0 ops
            | c `elem` ops              = Just (c, l, reverse r)
            | otherwise                 = findOp l (TOp c:r) 0 ops
        findOp leftSubExpression [] b operationsForFind
            | b > 0                     = Nothing
        findOp (c:l) r b ops            = findOp l (c:r) b ops
        findOp [] rightSubExpression braceAmount operationsForFind = Nothing
        makeTree reversedTokens     = mt reversedTokens $ subExpr reversedTokens
        mt t@(RBrace:tt) Nothing
            | last t == LBrace      = mt (init tt) $ subExpr (init tt)
        mt [TLetter v] Nothing      = Just $ Letter v
        mt [TNumf v] Nothing        = Just $ Numf v
        mt _ Nothing                = Nothing
        mt _ (Just (o, l, r))       = makeOperationExpression leftExpressionTree rightExpressionTree o where
            leftExpressionTree          = mt l $ subExpr l
            rightExpressionTree         = mt r $ subExpr r
            makeOperationExpression = moe
            moe Nothing _ _         = Nothing
            moe _ Nothing _         = Nothing
            moe (Just leftExpressionTree) (Just rightExpressionTree) operation = Just $ Op operation leftExpressionTree rightExpressionTree
    
    -- Простейшее упрощение выражений
    firstSimplify e     = simplifyTreeHeightTimes <$> e where
        stepSimplify = fs
        fs (Op '*' e (Numf 1))           = e
        fs (Op '*' (Numf 1) e)           = e
        fs (Op '+' e (Numf 0))           = e
        fs (Op '+' (Numf 0) e)           = e
        fs (Op '/' e (Numf 1))           = e
        fs (Op '-' e (Numf 0))           = e
        fs (Op '*' (Numf 0) _)           = Numf 0
        fs (Op '*' _ (Numf 0))           = Numf 0
        fs (Op '/' (Numf 0) _)           = Numf 0
        fs (Op '/' (Letter l) (Letter r))
            | l == r                     = Numf 1
        fs (Op '-' (Letter l) (Letter r))

    Новая Специальная Олимпиада объявляется открытой.

    https://ideone.com/Bottp0

    Реализовать поиск производной по выражению на любом языке. У кого получится компактнее, правильнее и больше функционала, тот и победил. Заявлять кандидата в победители (код и его автора) можно несколько раз если код улучшил или написал на другом языке. Призов, кроме почета и приятного времяпрепровождения, - не будет

    Если кто-то что-нибудь поломает, то я буду очень рад.

    Пока упрощение не работает на полную катушку и из функций производных только +-*/

    Мой друг обещает ещё версию на крестах подогнать.

    laMer007, 26 Января 2016

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

    −4

    1. 1
    2. 2
    3. 3
    4. 4
    std::string CryptoOperations::getLastError()
    	{
    		return "Произошла неизвестная ошибка при выполнении криптооперации";
    	}

    laMer007, 08 Октября 2015

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