- 1
"%s[@%s='%s']"
Нашли или выдавили из себя код, который нельзя назвать нормальным, на который без улыбки не взглянешь? Не торопитесь его удалять или рефакторить, — запостите его на говнокод.ру, посмеёмся вместе!
+128
"%s[@%s='%s']"
Аццкий смайлик! Сборка запроса XPath для поиска элементов в XML DOM по значениям, переданным из другой функции.
sprintf(str,"%s[@%s='%s']",elemPath,attrName,value);
+128
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
Решил все-таки выложить этот позор. Если есть предложения по улучшению - с радостью выслушаю.
+128
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)
+128
[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. Я не знаю, что ему ответить?
+128
f = expr `catches` [Handler (\ (ex :: ArithException) -> handleArith ex), Handler (\ (ex :: IOException) -> handleIO ex)]
Собственно это пример как в хаскеле перехватывать исключения из одного выражения expr.
Выглядит конечно отстойно. Очень многословно и судя по всему метода проще нет. И понятное дело, в чистых ленивых функциях это не работает. Ловить исключения можно только в грязных IO-функциях, тк сигнатура такова: catches :: IO a -> [Handler a] -> IO a
+128
#!/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
+128
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) < (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 < l)
then s -- return start index
else if (h > 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
+128
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
+128
<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&domain=govnokod&color=adadad&align=left&charset=cp1251&ltitle=%CE%F2%E7%FB%E2%FB&lfont=Verdana, Geneva, sans-serif&lsize=11px&waction=0&regime=1"></script></li>
Чтобы решить проблему с кодировкой - нужно просто поменять charset=cp1251 на charset=utf8, вестимо.
Но страйко который год не может.
+128
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)