- 1
- 2
HTTP referer (originally a misspelling of referrer) is an HTTP header field that identifies the address of the webpage
(i.e. the URI or IRI) that linked to the resource being requested.
Нашли или выдавили из себя код, который нельзя назвать нормальным, на который без улыбки не взглянешь? Не торопитесь его удалять или рефакторить, — запостите его на говнокод.ру, посмеёмся вместе!
+133
HTTP referer (originally a misspelling of referrer) is an HTTP header field that identifies the address of the webpage
(i.e. the URI or IRI) that linked to the resource being requested.
Originally a misspelling of referrer...
+137
#include <time.h>
int rrand(int start, int end)
{
int range=end-start+1;
int speed=1;
int base=0;
int rez=start;
if(range>200) speed=range/100;
while(range>=0)
{
srand(clock());
if(rand()%2) base=base+speed+1;
else base--;
rez=rez+base;
rez=(rez < start)? end-rez : rez;
rez=(rez > end)? (rez%end)+start : rez;
range=range-speed;
}
return rez;
}
случайные числа в определенном диапазоне...
+160
foreach (scandir(DIR.'app'.SLASH.'lib') as $filename) {
$path = DIR.'app'.SLASH.'lib'.SLASH.$filename;
if (is_file($path) && substr($filename,strlen($filename)-4,4)=='.php') {
require_once($path);
}
}
foreach (scandir(DIR.'app'.SLASH.'models') as $filename) {
$path = DIR.'app'.SLASH.'models'.SLASH.$filename;
if (is_file($path) && substr($filename,strlen($filename)-4,4)=='.php') {
require_once($path);
}
}
foreach (scandir(DIR.'app'.SLASH.'ext') as $filename) {
$path = DIR.'app'.SLASH.'ext'.SLASH.$filename;
if (is_file($path) && substr($filename,strlen($filename)-4,4)=='.php') {
require_once($path);
}
}
Начался разбор проблемы со слов заказчика - "сайт долго грузится"
+108
void Data3Fill(string _TownCheck, string _StreetCheck, string _HouseCheck, string _FlatCheck, string _BloodCheck,
string _InsuranceCheck, string _EndPolCheck, string _DateFutureCheck, string _DoctorCheck, string _DiagnosisCheck, string _ComplaintsCheck, string _VichCheck, string _CancerCheck, string _SurnameCheck, string _NameCheck, string _MidnameCheck,
string _SexCheck, string _StatusCheck, string _HighStatusCheck)
{
...
}
Одному моему другу такой подход кажется нормальным.
+130
char* obrab_stroki(char*, int);
int move(char*);
int action_register(char*);
int speed(char*);
int condition(char*);
char answer1[25];
uint8_t Output[512];
uint32_t number_for_output=16;
typedef struct { char *name; uint8_t adress; } struct_label;
typedef struct { char *name; uint8_t adress; } struct_goto_label;
//----------------------------------------------------------------------------------------
while (strcmp(qwerty[++string_count],""))
{
str=obrab_stroki(qwerty[string_count], 0);
printf("s:%s\n",str);
if (!strcmp(qwerty[string_count]+strlen(qwerty[string_count])-1,"{")) fig_skob++;
if (!strcmp(qwerty[string_count]+strlen(qwerty[string_count])-1,"}")) fig_skob--;
if (!strcmp(qwerty[string_count]+strlen(qwerty[string_count])-1,"{") && !strcmp(str,"if")) { fig_skob_if++; adres_return[fig_skob_if]=number_for_output+3; }
if (!strcmp(qwerty[string_count]+strlen(qwerty[string_count])-1,"}") && fig_skob_if>0) { Output[adres_return[fig_skob_if]]=number_for_output; fig_skob_if--;}
if (fig_skob==0)
{
Output[number_for_output++]=0;
Output[number_for_output++]=0;
}
if (!strcmp(qwerty[string_count]+strlen(qwerty[string_count])-1,":"))
{
label[number_label].name=qwerty[string_count];
label[number_label++].adress = number_for_output;
continue;
}
//-------------------------------------------------------------------------------------------
if (!strcmp(str,"r")) if (action_register(qwerty[string_count]) == 1) {printf("ERROR in string: %d", string_count); return 1;} else continue;
if (!strcmp(str,"move")) if (move(qwerty[string_count]) == 1) {printf("ERROR in string: %d", string_count); return 1;} else continue;
if (!strcmp(str,"speed")) if (speed(qwerty[string_count]) == 1) {printf("ERROR in string: %d", string_count); return 1;} else continue;
if (!strcmp(str,"if")) if (condition(qwerty[string_count]) == 1) {printf("ERROR in string: %d", string_count); return 1;} else continue;
//-----------------------------------------------------------------------------------------
char* obrab_stroki(char* qwerty, int i)
{
int count;
char asnwer1[25];
for (count=0; (qwerty[count+i]<='z' && qwerty[count+i]>='a') || (qwerty[count+i]<='Z' && qwerty[count+i]>='A'); count++)
{
answer1[count]=qwerty[count+i];
}
answer1[count]='\0';
return answer1;
}//тут как бы нет ошибок =)
//----------------------------------------------------------------------------------------------
if (qwerty[i]=='-')
{
if (qwerty[i+1]=='1' && qwerty[i+2]=='0')
{
Output[number_for_output++]=answer|MOTOR_SPEC_SPEED_DEC;
Output[number_for_output++]=0;
return 0;
}
else
return 1;
}
Человек писал компилятор. Самые эпичные моменты
+126
class Program
{
static void Main(string[] args)
{
User admin = new User() { Name = "Admin", Dick = new User.UserDick(18) };
User guest = new User() { Name = "guest", Dick = new User.UserDick(12) };
Console.WriteLine(guest.Suck(admin.Dick));
Console.ReadLine();
}
}
public class User
{
public User() { }
public class UserDick
{
public UserDick(int _length) { Length = _length; }
public long Length { get; set; }
}
public string Name { get; set; }
public UserDick Dick { get; set; }
public string Suck(UserDick _dick)
{
return String.Format("{0}: OH YEAH FUCK ME BY YOUR {1} CM YEEEEEAH I WANNA SUCK YOUR {2} DICK!", Name, _dick.Length, _dick.Length >= 17 ? "BIG" : "SMALL");
}
}
+132
private Duplicate CheckForDuplicate(object name, object surname, object patronymic, object birthday, object oldSurname, out List<long> duplicateRowIDs)
{
duplicateRowIDs = new List<long>();
DataTable _idDuplicateRowTable = new DataTable();
//Проверка на полные дубликаты
_idDuplicateRowTable = SqlWrapper.ExecuteQuery(
@"
SELECT id
FROM [Физические лица]
WHERE [Физические лица].Фамилия=@param0
AND [Физические лица].Имя=@param1
AND [Физические лица].Отчество=@param2
AND [Физические лица].[Дата рождения]=@param3
AND (( @param4 IS NOT NULL AND [Физические лица].[Старая фамилия]=@param4 )
OR (@param4 IS NULL AND [Физические лица].[Старая фамилия] IS NULL ))
",
surname, name, patronymic, birthday, oldSurname
).Tables[0];
if (_idDuplicateRowTable.Rows.Count == 1)
{
duplicateRowIDs.Add((long)_idDuplicateRowTable.Rows[0]["id"]);
return Duplicate.Fully;
}
//Несколько полных дубликатов
if (_idDuplicateRowTable.Rows.Count > 1)
{
foreach (DataRow duplicate in _idDuplicateRowTable.Rows)
{
duplicateRowIDs.Add((long)duplicate["id"]);
}
return Duplicate.SomeFullyDuplicates;
}
//Проверяем только ФИО+дата рождения
_idDuplicateRowTable = SqlWrapper.ExecuteQuery(
@"
SELECT id, [Старая фамилия]
FROM [Физические лица]
WHERE [Физические лица].Фамилия=@param0
AND [Физические лица].Имя=@param1
AND [Физические лица].Отчествo=@param2
AND [Физические лица].[Дата рождения]=@param3
",
surname, name, patronymic, birthday
).Tables[0];
if (_idDuplicateRowTable.Rows.Count == 1)
{
if (_idDuplicateRowTable.Rows[0]["Старая фамилия"].Equals(DBNull.Value) && oldSurname is String)//Если стар. фамилия в БД == null & в файле != null
{
duplicateRowIDs.Add((long)_idDuplicateRowTable.Rows[0]["id"]);
return Duplicate.OldSurnameDiff;
}
duplicateRowIDs.Add((long)_idDuplicateRowTable.Rows[0]["id"]);
return Duplicate.ErrOldSurname;
}
else if (_idDuplicateRowTable.Rows.Count > 1)
{
foreach (DataRow row in _idDuplicateRowTable.Rows)
{
duplicateRowIDs.Add((long)row["id"]);
}
return Duplicate.SomeBaseDuplicates;
}
return Duplicate.NonDuplicate;
}
private bool IsPotentilaDuplicate(object name, object surname, object patronymic, object birthday, object oldSurname)
{
bool _isPotentilaDuplicate = false;
//Проверяем, не станет ли строка дубликатом, после изменения
//Только по ФИО+дате рождения
DataTable _ponentialDuplicates1 = SqlWrapper.ExecuteQuery(
@"
SELECT id
FROM [Физические лица]
WHERE [Физические лица].Фамилия=@param0
AND [Физические лица].Имя=@param1
AND [Физические лица].Отчество=@param2
AND [Физические лица].[Дата рождения]=@param3
",
oldSurname, name, patronymic, birthday
).Tables[0];
//Полное совпадение
DataTable _ponentialDuplicates2 = SqlWrapper.ExecuteQuery(
@"
SELECT id
FROM [Физические лица]
WHERE [Физические лица].Фамилия=@param0
AND [Физические лица].Имя=@param1
AND [Физические лица].Отчество=@param2
AND [Физические лица].[Дата родения]=@param3
AND [Физические лица].[Старая фамилия]=@param4
",
oldSurname, name, patronymic, birthday, surname
).Tables[0];
if (_ponentialDuplicates1.Rows.Count > 0 || _ponentialDuplicates2.Rows.Count > 0)
{
_isPotentilaDuplicate = true;
}
return _isPotentilaDuplicate;}
Ну.... Проверка на дубликаты перед вставкой в БД. Сляпал его я, по методологии "давай-давай-быстрее!!!!а-а-а не успеваем", для показа заказчикам будущей функциональности. Сейчас переделываю с помощью паттерна Декоратор (т.к. нужно опционально проверка по ФИО+Дата рождения или СНИЛС или и то, и другое)+ввел табличку История изменений фамилий вместо столбца Старая фамилия
+135
return (true == is_break) ? resource : NULL;
Вонъ изъ профессiи!
−366
sub rotate {
my ($filename, $max_entries) = @_;
$max_entries //= 10; # TODO: make infinity available
return if (! -f $filename);
my ($name, $dir, $suffix) = fileparse($filename, qr/\.[^.]*$/);
my %old_files = ();
my $shift_max = 0; # maximum number of file that is going to be rotated
my $glob = File::Spec->catfile($dir, $name . '.*' . $suffix);
for my $file (glob qq/"$glob"/) {
my ($number) = $file =~ /\.(\d+)\Q$suffix\E$/;
$old_files{$number} = $file if (defined $number);
$shift_max++ while (exists $old_files{$shift_max + 1});
}
$shift_max = $max_entries - 1 if ($shift_max >= $max_entries);
# how many files to remove from the end
my $to_remove = scalar(keys %old_files) - $max_entries;
# rename and unlink
for my $number (sort { $b <=> $a } keys %old_files) {
my $file = $old_files{$number};
if ($to_remove-- > 0) {
print "## DEBUG: unlink $file\n";
unlink($file)
or croak('Cannot unlink ' . $file);
} elsif ($number <= $shift_max) {
my $new_name = File::Spec->catfile($dir, $name . '.' . ($number + 1) . $suffix);
print "## DEBUG: rename $file -> $new_name\n";
rename($file, $new_name)
or croak('Cannot rename ' . $file . ' to ' . $new_name);
}
}
my $new_name = File::Spec->catfile($dir, $name . '.1' . $suffix);
print "## DEBUG: rename $filename -> $new_name\n";
rename($filename, $new_name)
or croak('Cannot rename ' . $filename . ' to ' . $new_name);
}
Продолжаем парад велосипедов. Сделал ротацию бекап-архивов :-{
+1
int i=1;
Console.WriteLine((i+null)==null); //True
Console.WriteLine(1+null); //1
Console.WriteLine(null+1); //1
Console.WriteLine((1+null).GetType()); //System.Int32
http://ideone.com/LomfRC