- 1
- 2
- 3
- 4
- 5
@hands_by_value.each do |hand|
if @hands_by_value.slice(@hands_by_value.index(hand)+1..@hands_by_value.index(@hands_by_value.last)).include?(hand)
@hands_by_value.delete_at(@hands_by_value.index(hand))
end
end
Нашли или выдавили из себя код, который нельзя назвать нормальным, на который без улыбки не взглянешь? Не торопитесь его удалять или рефакторить, — запостите его на говнокод.ру, посмеёмся вместе!
−104
@hands_by_value.each do |hand|
if @hands_by_value.slice(@hands_by_value.index(hand)+1..@hands_by_value.index(@hands_by_value.last)).include?(hand)
@hands_by_value.delete_at(@hands_by_value.index(hand))
end
end
Рукотворный array.uniq! похоже :)
+152
$search_string = str_replace('"', '', $search_string);
$search_string = str_replace('+', '%20', $search_string);
//$search_string = preg_replace( '#([[:punct:]])#e', '( isset($punct[\'\1\']) ? $punct[\'\1\'] : \'\')', $search_string );
$search_string = trim($search_string);
$search_string = addslashes(stripslashes(htmlspecialchars(strip_tags(rawurldecode($search_string)))));
Борямся с XSS
+160
<?php
//...
$fileinattachments = $root_directory.$filepath.$fileid.'_'.$filename;
if(!file($fileinattachments)) $fileinattachments = $root_directory.$filepath.$fileid."_".$filename
//...
?>
Много думал. Код из незабвенной vTiger CRM.
+147
if(typeof n!="number"&&(k==Number||!(n instanceof Number))||p.round(n)!=n||n==NaN||n==Infinity)return!1;
+146
Я ХОЧУ ПОКАКАТЬ!
ПОМОГИТЕ МНЕ ПАЖАЛУЙСТА!
+137
rem ID generator
:idgen
set nsmb=36
set idstr=
for /l %%i in (1,1,8) do call :rsadd
echo ID=%idstr%
exit /b
rem Random symbol adding [0-9a-z]
:rsadd
set r=%random%
set /a c=r-r/nsmb*nsmb
if %c% lss 10 set idstr=%idstr%%c%
if %c% == 10 set idstr=%idstr%a
if %c% == 11 set idstr=%idstr%b
if %c% == 12 set idstr=%idstr%c
if %c% == 13 set idstr=%idstr%d
if %c% == 14 set idstr=%idstr%e
if %c% == 15 set idstr=%idstr%f
if %c% == 16 set idstr=%idstr%g
if %c% == 17 set idstr=%idstr%h
if %c% == 18 set idstr=%idstr%i
if %c% == 19 set idstr=%idstr%j
if %c% == 20 set idstr=%idstr%k
if %c% == 21 set idstr=%idstr%l
if %c% == 22 set idstr=%idstr%m
if %c% == 23 set idstr=%idstr%n
if %c% == 24 set idstr=%idstr%o
if %c% == 25 set idstr=%idstr%p
if %c% == 26 set idstr=%idstr%q
if %c% == 27 set idstr=%idstr%r
if %c% == 28 set idstr=%idstr%s
if %c% == 29 set idstr=%idstr%t
if %c% == 30 set idstr=%idstr%u
if %c% == 31 set idstr=%idstr%v
if %c% == 32 set idstr=%idstr%w
if %c% == 33 set idstr=%idstr%x
if %c% == 34 set idstr=%idstr%y
if %c% == 35 set idstr=%idstr%z
exit /b
Windows shell
Собственноручно написанное. Нашел, разбирая старые скрипты.
+170
(function(a){ var m
return (m=a.length)<2 ? a[0] : (m=a[--m],a.length--,(a[a.length-1]>m)&&(a[a.length-1]=m),arguments.callee(a))
})(this.prop)
Вроде бы ищет минимум в this.prop.
P.S. this.prop как массив удаляется. Равен результату.
+151
elseif (array_key_exists(pathinfo($_SERVER['HTTP_HOST'], PATHINFO_EXTENSION), $lang_array)) {
$language = pathinfo($_SERVER['HTTP_HOST'], PATHINFO_EXTENSION);
}
else
$language = 'en';
Из того же проекта, где зародился шаблонизатор.
Минималистичный файл-хостинг, который все решает за хозяина.
Конфиг - только папка хранения файлов и макс. объем.
А язык он определяет сам. По доменному имени. Каждый раз при обращении к странице.
+74
private static java.util.Hashtable<String, Session> sessions =
new java.util.Hashtable<String, Session>();
...
public static SessionOperations[] getSessions() {
int cnt = sessions.size();
SessionOperations[] res = new SessionOperations[cnt];
java.util.Enumeration<String> e = sessions.keys();
for( int i = 0; i < res.length; i++ ) {
String sid = e.nextElement();
res[i] = sessions.get( sid ).getOperations( sid );
}
return res;
}
Удаление из sessions между получением размера и набора ключей приводит к весьма печальным последствиям...
P.S. В результате в течение трех суток в production не удалялись оставленные сессии (без Logout), sessions отожрал 600М и всё свалилось с OOM.
−111
NetworkStatus internet = [internetReachable currentReachabilityStatus];
switch (internet)
{
case NotReachable: { internetStatus = NO; break; }
case ReachableViaWiFi: { internetStatus = YES; break; }
case ReachableViaWWAN: { internetStatus = YES; break; }
default: break;
}
NetworkStatus host = [hostReachable currentReachabilityStatus];
switch (host)
{
case NotReachable: { hostStatus = NO; break; }
case ReachableViaWiFi: { hostStatus = YES; break; }
case ReachableViaWWAN: { hostStatus = YES; break; }
default: break;
}
//-------------------------------------------------------------
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation {
return false;
}
//-------------------------------------------------------------
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation
{
if (logicRotate == 1)
{
if (toInterfaceOrientation == UIInterfaceOrientationLandscapeRight) // если ЛандскейпРайт
{
FlowCover.transform = CGAffineTransformIdentity;
indexLandscape = 1;
}
if (toInterfaceOrientation == UIInterfaceOrientationLandscapeLeft) // если ЛандскейпЛефт
{
FlowCover.transform = CGAffineTransformMakeRotation(M_PI);
indexLandscape = 0;
}
}
else
{
if (indexLandscape == 1)
{
FlowCover.transform = CGAffineTransformIdentity;
}
else
{
FlowCover.transform = CGAffineTransformMakeRotation(M_PI);
}
logicRotate = 1;
}
return false;
}
//-------------------------------------------------------------
pagetextLabel.hidden = (pageFullScreen.realPageNo) ? NO : YES;
//-------------------------------------------------------------
[(FastImageView*)page showImage:[listOfImages objectAtIndex:pageIndex]]; //картинка
//-------------------------------------------------------------
if (firstPages>2) {
...
if (theAudio) {
[theAudio play]; //звук
}
firstPages++;
}
else
{
firstPages++;
}
//-------------------------------------------------------------
LabPercent.text = [NSString stringWithFormat:@"%d%@", percent * 100, @"%"];
//-------------------------------------------------------------
if ([DELEGATE isIPad]) {
mTempSize = [tempstr sizeWithFont:[UIFont fontWithName:@"Helvetica" size:17.0f] constrainedToSize:maxSize lineBreakMode:UILineBreakModeTailTruncation];
}
else {
mTempSize = [tempstr sizeWithFont:[UIFont fontWithName:@"Helvetica" size:12.0f] constrainedToSize:maxSize lineBreakMode:UILineBreakModeTailTruncation];
}
h = mTempSize.height;
if ([DELEGATE isIPad]) {
lab.font = [UIFont fontWithName:@"Helvetica" size:17.0f];
}
else {
lab.font = [UIFont fontWithName:@"Helvetica" size:12.0f];
}
От того же автора http://govnokod.ru/6964. Тут избранные куски, хотя можно постить весь проект