- 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! похоже :)
+113
public string GetNormalImage(int newWidth, int newHeight, string sufix = "normal") {
String[] tmp = _originalImagePath.Split('.');
String newImagePath = "";
for (int i = 0; i < tmp.Length - 1; i++)
{
newImagePath += tmp[i];
newImagePath += "_";
}
newImagePath += sufix + ".";
newImagePath += tmp[tmp.Length - 1];
Image oldImage = Image.FromFile(_originalImagePath);
if (oldImage.Height >= oldImage.Width) {
Image newImage;
newImage = FixedSize(oldImage, newWidth, newHeight);
newImage.Save(newImagePath);
} else {
float heightRatio = (float)newHeight / (float)oldImage.Height;
float widthRatio = (float)newWidth / (float)oldImage.Width;
float bestRatio = 1;
if (heightRatio < widthRatio) {
bestRatio = heightRatio;
} else {
bestRatio = widthRatio;
}
var result = new System.Drawing.Bitmap((int)Math.Round(oldImage.Width * bestRatio), (int)Math.Round(oldImage.Height * bestRatio));
using (var graphics = Graphics.FromImage(result))
{
graphics.CompositingQuality = CompositingQuality.HighQuality;
graphics.InterpolationMode = InterpolationMode.HighQualityBicubic;
graphics.PixelOffsetMode = PixelOffsetMode.HighQuality;
graphics.SmoothingMode = SmoothingMode.HighQuality;
graphics.DrawImage(oldImage, new Rectangle(Point.Empty, new Size((int)Math.Round(oldImage.Width * bestRatio), (int)Math.Round(oldImage.Height * bestRatio))));
}
result.Save(newImagePath);
}
return newImagePath;
}
ресайз изображения
−104
<%= !!@case[:img] ? image_tag(@case[:img]) : "" %>
−144
#! /bin/sh
# some code
daemon1="/usr/home/daemon1.sh"
daemon2="/home/daemon2.sh"
# some code with variables
Скрипт на BSD. Хомяк находится в /usr/home, а /home симлинк на него
+147
int __fastcall TForm1::iscomm(AnsiString str)
{
int i=1;
while (str[i]==' ')
i++;
if (str[i]=='#')
{
return 1;
}
else
{
return 0;
};
};
+159
jQuery("select[id='select1']").change(
function ()
{
var city_id = jQuery(this).attr("value");
jQuery("select[id='select_hotel']").html('<option>Выберите категорию</option>');
jQuery("select[name='room']").html('<option>Выберите категорию и отель</option>');
jQuery("select[id='select_5']").change(
function ()
{
....................................
}
);
}
);
обратите внимание на то, как селекторы объектов написаны.. автор вместо "#select1" пишет "select[id='select1']" зачем это делать непонятно.
наговнокодено на сайте el-tour.com
+147
if(!empty(_SESSION['order']['contact']['user_id']))
$user_id = preg_replace('/\D|\s/', '', $_SESSION['order']['contact']['user_id']);
Радует знание регулярных выражений =)
+155
uses crt;
var s:integer;
begin
readln(s);
writeln(ord(s[0]));
readln;
end.
+123
this.Border1.BackColor = System.Drawing.Color.FromArgb(((int)(((byte)(111)))), ((int)(((byte)(111)))), ((int)(((byte)(111)))));
Встретилось такое внутри сгенеренной системой InitializeComponent()
+143
// find the start and end of the upload file.
static FILE * _uploadGet(request *wp, unsigned int *startPos, unsigned *endPos) {
FILE *fp=NULL;
struct stat statbuf;
unsigned char c, *buf;
if (wp->method == M_POST)
{
fstat(wp->post_data_fd, &statbuf);
lseek(wp->post_data_fd, SEEK_SET, 0);
printf("file size=%d\n",statbuf.st_size);
fp=fopen(wp->post_file_name,"rb");
if(fp==NULL) goto error;
}
else goto error;
//printf("_uploadGet\n");
do
{
if(feof(fp))
{
printf("Cannot find start of file\n");
goto error;
}
c= fgetc(fp);
if (c!=0xd)
continue;
c= fgetc(fp);
if (c!=0xa)
continue;
c= fgetc(fp);
if (c!=0xd)
continue;
c= fgetc(fp);
if (c!=0xa)
continue;
break;
}while(1);
(*startPos)=ftell(fp);
if(fseek(fp,statbuf.st_size-0x200,SEEK_SET)<0)
goto error;
do
{
if(feof(fp))
{
printf("fmmgmt: Cannot find end of file\n");
goto error;
}
c= fgetc(fp);
if (c!=0xd)
continue;
c= fgetc(fp);
if (c!=0xa)
continue;
c= fgetc(fp);
if (c!='-')
continue;
c= fgetc(fp);
if (c!='-')
continue;
break;
}while(1);
(*endPos)=ftell(fp);
return fp;
error:
return NULL;
}
Вот так вот китайцы парсят MIME при загрузке прошивки в роутер.