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

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

    +128

    1. 1
    "%s[@%s='%s']"

    Аццкий смайлик! Сборка запроса XPath для поиска элементов в XML DOM по значениям, переданным из другой функции.

    sprintf(str,"%s[@%s='%s']",elemPath,attrName,value);

    GoblinAlchemist, 27 Ноября 2012

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

    +128

    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
    data Mode = Start | Read | Skip | End
    data State = State Mode String String [String]
    
    space c = elem c [' ', '\n', '\r', '\f', '\t', '\v', '\160']
    
    end r     = State End "" "" r
    skip t r  = State Skip t "" r
    get t w r = State Read t w r
    start t   = State Start t "" []
    
    step (State Start at@(t:ts) w r)
    	| space t   = step $ skip at r
    	| otherwise = step $ get at w r
    
    step (State Read at@(t:ts) w r)
    	| space t   = step $ skip at $ r ++ [w]
    	| otherwise = step $ get ts (w ++ [t]) r
    
    step (State Skip at@(t:ts) _ r)
    	| space t   = step $ skip ts r
    	| otherwise = step $ get at "" r
    
    step (State Start "" _ r) = step $ end r
    step (State Read "" w r)  = step $ end $ r ++ [w]
    step (State Skip "" _ r)  = step $ end r
    
    step (State End _ _ r) = r
    
    words' text = step $ start text

    Решил все-таки выложить этот позор. Если есть предложения по улучшению - с радостью выслушаю.

    Fai, 23 Ноября 2012

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

    +128

    1. 1
    2. 2
    3. 3
    4. 4
    5. 5
    right_triangles = [ (a, b, c a b) | b <- [1..], a <- [1..b], isRight a b ]
    	where
    		rc a b = sqrt $ fromIntegral (a^2 + b^2)
    		c a b = round $ rc a b
    		isRight a b = (rc a b) == fromIntegral (c a b)

    Fai, 14 Ноября 2012

    Комментарии (8)
  5. Куча / Говнокод #12031

    +128

    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
    [Record] variant ItemPatternMatched: PatternMatchedBase, IPatternMatched
    			_matchByLexemeValue:option[string]
    			public Match(source:SourceLexemes, namedLinkDictionary:NamedLinkDictionary):MatchResult
    				match(source)
    					|[]               => MatchResult.EndOfLexemes(source, namedLinkDictionary)
    					|lexeme_::lexemes_=>    def updatedNamedLinkDictionary = updateNamedLinkDictionary(lexeme_::[], namedLinkDictionary);
    											def failure = MatchResult.Failure(source, namedLinkDictionary);
    											def success = MatchResult.Success(lexemes_, updatedNamedLinkDictionary);
    											match(_matchByLexemeValue)
    												|None | Some(lexemeValue_) when (lexemeValue_==lexeme_._value) =>											
    													match(this, lexeme_._type)
    														|(Symbol, SourceLexeme.Type.Symbol) | (Identificator, SourceLexeme.Type.Identificator) | (Number, SourceLexeme.Type.Number) => 
    															success
    														|_                                                                                                                          => 
    															failure
    												|_                                                             => 
    													failure
    			|Symbol
    			|Identificator
    			|Number

    Начальник, посмотрев на код, сказал, что NemerleGovno. Я не знаю, что ему ответить?

    LispGovno, 30 Октября 2012

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

    +128

    1. 1
    f = expr `catches` [Handler (\ (ex :: ArithException) -> handleArith ex), Handler (\ (ex :: IOException)    -> handleIO    ex)]

    Собственно это пример как в хаскеле перехватывать исключения из одного выражения expr.
    Выглядит конечно отстойно. Очень многословно и судя по всему метода проще нет. И понятное дело, в чистых ленивых функциях это не работает. Ловить исключения можно только в грязных IO-функциях, тк сигнатура такова: catches :: IO a -> [Handler a] -> IO a

    HaskellGovno, 21 Октября 2012

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

    +128

    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
    #!/bin/bash
    hl=`cat $1`
    wrdl=`cat ~/worlds.txt`
    addr=$PWD'/extra_hosts.txt'
    rm -f $addr && echo "Deleted host list file "$addr
    touch $addr && echo "Created file "$addr
    for address in $hl
    do
    rm $PWD/`basename $address`.txt && echo "Deleted file "$PWD/`basename $address`.txt
    done
    for address in $hl
    do
    #echo $address
    export address
    tmp=$PWD/`basename $address`.txt
    trc=$PWD/`basename $address`.tr.txt
    mytmp=/tmp/`basename $address`.txt
    curl -Ss --retry 2 --trace $trc --tr-encoding --tcp-nodelay $address > $mytmp &
    sleep 10s
    cat $mytmp \
     | grep -e '<a href=\"[^"]*\"' | grep -E -o '[^"]+'\
     | grep htm | perl -pe 's/$ENV{address}//'| \
     perl -pe 's/^\//$ENV{address}\//' | perl -pe 's/text\/html//'|\
      sed -e 's/<[^>]*>//g' -e '/\/http:/d;/^http/p;d;' | sort | uniq >> $addr &
    for wrd in `cat ~/worlds.txt`
    do
    export wrd
    cat -b $mytmp\
    | sed -e 's/<[^>]*>//g' |grep -i $wrd \
     | perl -pe 's/^/$ENV{address}:$ENV{wrd}:/' | tee -a $tmp &
    done
    done
    mkdir -p extra_hosts && echo "Made dir extra_hosts"
    cd extra_hosts
    $0 $addr

    AliceGoth, 18 Сентября 2012

    Комментарии (9)
  8. Куча / Говнокод #11568

    +128

    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
    rotate n xs = b ++ a
        where n'     = n `mod` (length xs)
          (a, b) = splitAt ((length xs) - n') xs
    
    rotateAmount xs = _ra 0 ((length xs) - 1) (listArray (0, ((length xs) - 1)) xs)
        where _ra s e ys = if (e - s) == 1 
                           then (if ((ys ! s) &lt (ys ! e)) then s else e)  -- base case
                           else let h  = ys ! s                  -- first item
                                    l  = ys ! e                  -- last item
                                    mi = s + ((e - s) `div` 2)   -- middle index
                                    m  = ys ! mi                 -- middle item
                                in if (h &lt l)
                                   then s                        -- return start index
                                   else if (h &gt m)
                                        then _ra s  mi ys
                                        else _ra mi e  ys

    A “rotated array” is an array of integers in ascending order, after which for every element i, it has been moved to element (i + n) mod sizeOfList. Write a function that takes a rotated array and, in less-than-linear time, returns n (the amount of rotation). http://techguyinmidtown.com/2008/07/05/my-answers-to-the-microsoft-interview-questions

    FAKYOUINTIRNEAT, 10 Августа 2012

    Комментарии (31)
  9. Куча / Говнокод #11456

    +128

    1. 1
    2. 2
    3. 3
    func fff() func() func() func() string {
    	return func() func() func() string { return func() func() string { return func() string { return "DON'T DO THAT!" } } }
    }

    http://play.golang.org/p/KN4E1RotKl

    USB, 22 Июля 2012

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

    +128

    1. 1
    2. 2
    3. 3
    4. 4
    5. 5
    6. 6
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
    <title>По колено в коде —  Говнокод.ру</title>
    
    <!-- Пару десятков строчек спустя -->
    
    <li><script type="text/javascript" src="http://reformal.ru/tab.js?title=%C3%EE%E2%ED%EE%EA%EE%E4.%F0%F3%3A+%EF%EE+%EA%EE%EB%E5%ED%EE+%E2+%EA%EE%E4%E5&amp;domain=govnokod&amp;color=adadad&amp;align=left&amp;charset=cp1251&amp;ltitle=%CE%F2%E7%FB%E2%FB&amp;lfont=Verdana, Geneva, sans-serif&amp;lsize=11px&amp;waction=0&amp;regime=1"></script></li>

    Чтобы решить проблему с кодировкой - нужно просто поменять charset=cp1251 на charset=utf8, вестимо.
    Но страйко который год не может.

    7ion, 13 Мая 2012

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

    +128

    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
    Unsigned long int getset (void)
    {unsigned long int a; int k; h=0;
    While (‘<не конец файла>==<читать число в k>’);
    {switch k
    {case 1: h = h/0x 0001; break;
    case 2: h = h/0x 0002; break;
    case 3: h = h/0x 4; break;
    case 4: h = h/0x 8; break;
    case 5: h = h/0x 10; break;
    case 6: h = h/0x 20; break;
    case 7: h = h/0x 40; break;
    case 8: h = h/0x 80; break;
    …
    case 30: h = h/0x 2000 0000; break;
    case 31: h = h/0x 4000 0000; (- 1 на 31 месте) break;
    case 32: h = h/0x 8000 0000; (- 1 на 32 месте) break;
    }
    }
    return (h)
    }

    Мне кажется или весь смысл сводиться к h = h/2^(k-1)

    ApeNN, 21 Апреля 2012

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