- 1
- 2
- 3
- 4
ClassName::~ClassName()
{
memset( this, 0, sizeof( *this ) );
}
Нашли или выдавили из себя код, который нельзя назвать нормальным, на который без улыбки не взглянешь? Не торопитесь его удалять или рефакторить, — запостите его на говнокод.ру, посмеёмся вместе!
+179
ClassName::~ClassName()
{
memset( this, 0, sizeof( *this ) );
}
Написано коллегой из теплой страны. Случайно нашел в коде :)
−181
from django.db import models
# Класс Студент
class Student(models.Model):
name = models.CharField(max_length=50) # ФИО студента
group = models.CharField(max_length=10) # Группа студента
starosta = models.BooleanField(default=False) # Является ли студент старостой группы?
# Класс Пара
class Pair(models.Model):
name = models.CharField(max_length=30) # Название пары
auditory = models.CharField(max_length=7) # Аудитория
lecturer = models.CharField(max_length=50) # ФИО преподавателя
# Класс День
class Day(models.Model):
pair1 = models.ForeignKey(Pair) # Первая пара
pair2 = models.ForeignKey(Pair) # Вторая пара
pair3 = models.ForeignKey(Pair) # Третья пара
pair4 = models.ForeignKey(Pair) # Четвёртая пара
pair5 = models.ForeignKey(Pair) # Пятая пара
pair6 = models.ForeignKey(Pair) # Шестая пара
pair7 = models.ForeignKey(Pair) # Седьмая пара
# Класс Расписание
class TimeTable(models.Model):
group = models.CharField(max_length=10) # Группа, к которой относится расписание
weekcolor = models.BooleanField() # False, 0 - Красная неделя; True, 1 - Синяя неделя
monday = models.ForeignKey(Day) # Понедельник
tuesday = models.ForeignKey(Day) # Вторник
wednesday = models.ForeignKey(Day) # Среда
thursday = models.ForeignKey(Day) # Четверг
friday = models.ForeignKey(Day) # Пятница
saturday = models.ForeignKey(Day) # Суббота
Очередной шедевр от Magister Yoda
Попытка сделать модель расписания для студентов.
−862
SET @SQL = '
SELECT
@diff1 = @diff1 + ''CASE WHEN '' + Field_Name + ''=@'' + Field_Name +
'' OR ('' + Field_Name + '' IS null AND @'' + Field_Name + '' IS NULL) THEN ''''''''
ELSE '''''' + Field_Name + ''="''''+COALESCE(CAST('' + Field_Name + '' AS varchar(max)), ''''NULL'''')
+ ''''", '''' END +'',
@diff2 = @diff2 + ''CASE WHEN '' + Field_Name + ''=@'' + Field_Name +
'' OR ('' + Field_Name + '' IS Null AND @'' + Field_Name + '' IS NULL) THEN ''''''''
ELSE '''''' + Field_Name + ''="''''+COALESCE(CAST(@'' + Field_Name + '' AS varchar(max)), ''''NULL'''')
+ ''''", '''' END +'',
@declare = @declare + ''DECLARE @'' + Field_Name + '' '' + Field_Type + '';'',
@set = @set + ''SET @'' + Field_Name + ''='' + Field_Value + '';''
FROM (' + @pre + ') AS t'
Моё. Кусочек небольшой хранимки в 700 строк.
Формирование SQL-a, который формирует SQL, который, в свою очередь, формирует строку для записи изменений таблицы в лог.
−110
Dim num As Integer
Dim inp As Integer
Dim wrt As String
Dim liv As Integer
Sub Main()
liv = 3
Console.WriteLine("LIVES = " & liv)
pl:
If liv = 0 Then GoTo st
num = Fix(Rnd() * 5)
Console.WriteLine("ENTER NUMBER:")
inp = Console.ReadLine()
If inp < num Then
Console.WriteLine("GREATER")
liv = liv - 1
Console.WriteLine("LIVES = " & liv)
GoTo pl
End If
If inp > num Then
Console.WriteLine("LESS")
liv = liv - 1
Console.WriteLine("LIVES = " & liv)
GoTo pl
End If
If inp = num Then Console.WriteLine("YES!")
st:
Console.WriteLine("GAME OVER")
Console.WriteLine("ENTER ANY NUMBER TO EXIT")
inp = Console.ReadLine()
End Sub
Одна из моих первых "прог" на VB, написанная около 4х лет назад - "Угадай число".
+137
<Skript>
<center><B>Счет $USERNAME$а:</B></center><br>
<script type="text/javascript">
p=<?if($POSTS$)?>$POSTS$ <?else?>0<?endif?>
v=p*2
document.writeln("<B> "+v+" </B>StalkerMoney.<br>");
</script></skript>
Увидел на форуме по JS, вот цитирую:
"Я делаю проект по сталкеру в системе юКоз. Есть скрипт StalkerMoney. Сталкер мани образуются путем умножения количества сообщений на 2. Мне нужно оставить прибавление денег путем габивания постов, но добавить Редактор этих денег, на странице у каждого пользователя, что бы этот редактор был доступен только для администраторов, так же как и редактор счетчика сообщений. Вот сам недоработанный скрипт ... помогите пожалоста"
+148
preg_replace('/^(.*)\s(.*)$/i', '$1', $item['updated']);
+142
<tr>
<td><img src=images/spacer.gif border=0 height=1 width=15></td>
<td><img src=images/spacer.gif border=0 height=1 width=77></td>
<td><img src=images/spacer.gif border=0 height=1 width=19></td>
<td><img src=images/spacer.gif border=0 height=1 width=68></td>
<td><img src=images/spacer.gif border=0 height=1 width=19></td>
<td><img src=images/spacer.gif border=0 height=1 width=1></td>
</tr>
Ой ща я разгуляюсь!
Работаю в колл-центре, это исходный код веб-морды панели звонков.
Буду кидать куски потихоньку. Хотя там надо сразу все кидать.
Вот так мы верстаем.
+165
function ChangePhoto(num, photo)
{
if (photo.className != 'photo_selected')
{
var image1 = document.getElementById("ctl00_MainContent_ProductInfo1_ctl00_AlternativePictures_Image1");
var image2 = document.getElementById("ctl00_MainContent_ProductInfo1_ctl00_AlternativePictures_Image2");
var image3 = document.getElementById("ctl00_MainContent_ProductInfo1_ctl00_AlternativePictures_Image3");
var image4 = document.getElementById("ctl00_MainContent_ProductInfo1_ctl00_AlternativePictures_Image4");
var image5 = document.getElementById("ctl00_MainContent_ProductInfo1_ctl00_AlternativePictures_Image5");
var image6 = document.getElementById("ctl00_MainContent_ProductInfo1_ctl00_AlternativePictures_Image6");
if (image1 != null) image1.className = 'photo_notselected';
if (image2 != null) image2.className = 'photo_notselected';
if (image3 != null) image3.className = 'photo_notselected';
if (image4 != null) image4.className = 'photo_notselected';
if (image5 != null) image5.className = 'photo_notselected';
if (image6 != null) image6.className = 'photo_notselected';
photo.className = 'photo_selected';
Hide(0);
setTimeout("ChangeSrc("+num+")", 300);
setTimeout("ShowPhoto()", 400);
}
}
Чо мне ща сказал? Цыклы мне ща сказал? Какие тенна цыклы, ыдисюданна!
Строчки 22, 23 активируют какое-то хитрожопое многопоточное отображение фоток со взаимными блокировками и ожиданием друг друга по таймеру с интервалами в 10 мс.
+138
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <ctime>
#include <signal.h>
#include <sys/time.h>
#include <fcntl.h>
#include <termios.h>
#include <time.h>
#include <iostream>
using namespace std;
struct termios savetty;
struct termios tty;
char num[]="0123456789QWERTYUIOPASDFGHJKLZXCVBNM";
char let[]="!\",#$%&'()*qwertyuiopasdfghjklzxcvbnm";
int t=1;
int tm=0;
int opnum=0;
char buffer[30];
char var[1000];
char out[1000];
struct timeval tv;
struct timeval tv2;
int main()
{
if ( !isatty(0) ) {
fprintf (stderr, "stdin not terminal\n");
exit (1);
};
tcgetattr (0, &tty);
savetty = tty;
tty.c_lflag &= ~(ICANON|ISIG);
tty.c_cc[VMIN] = 1;
tcsetattr (0, TCSAFLUSH, &tty);
srand(time(0));
int i=0;
bool c=true;
time_t curtime;
int passLen=200+rand()%400;
for(int i=0;i<=passLen;i++){
int s=rand()%2;
if(s==1){
out[i]=let[rand()%37];
} else {
out[i]=num[rand()%35];
};
if((i%5)==0 && i!=0)out[i]=' ';
};
out[passLen]='\0';
int tt=gettimeofday(&tv, NULL);
if(tt<0)exit(0);
printf("%s\n",out);
while(out[i]!='\0')
{
var[i]=getchar();
if(var[i]!=out[i]){
opnum++;
printf("Er%c",out[i]);
};
i++;
};
tt=gettimeofday(&tv2, NULL);
if(tt<0)exit(0);
int tm=tv2.tv_sec-tv.tv_sec;
int v=(passLen*60)/tm;
int min=tm/60;
tm%=60;
printf("Time %d min %d sec\n",min,tm);
cout<<"Num of errors "<<opnum<<" Speed "<<v<<endl;
tcsetattr (0, TCSAFLUSH, &savetty);
};
Клавиатурный тренажер
+171
void Cryptogram(const vector<string> &vector1, vector<string> &vector2)
{
string word;
char new_letter;
long i, j, wordSize, vecSize, vecSize2;
vecSize = vector1.size();
for(j=0; j<vecSize; j++)
{
word = vector1[j];
//cout<<word<<endl;
wordSize = word.size();
cout<<wordSize<<endl;
for(i=0; i<wordSize; i++)
{
new_letter = word[i];
cout<<"& " << new_letter<< " " << isalpha(new_letter) << endl;
if(isalpha(new_letter)==true)
{
if(isupper(new_letter)==true)
{
if (new_letter == 'A')
new_letter = 'W';
else if(new_letter == 'B')
new_letter = 'Y';
else if(new_letter == 'C')
new_letter = 'I';
else if(new_letter == 'D')
new_letter = 'J';
else if(new_letter == 'E')
new_letter = 'K';
else if(new_letter == 'F')
new_letter = 'C';
else if(new_letter == 'G')
new_letter = 'U';
else if(new_letter == 'H')
new_letter = 'V';
else if(new_letter == 'I')
new_letter = 'D';
else if(new_letter == 'J')
new_letter = 'P';
else if(new_letter == 'K')
new_letter = 'Q';
else if(new_letter == 'L')
new_letter = 'L';
else if(new_letter == 'M')
new_letter = 'Z';
else if(new_letter == 'N')
new_letter = 'H';
else if(new_letter == 'O')
new_letter = 'T';
else if(new_letter == 'P')
new_letter = 'G';
else if(new_letter == 'Q')
new_letter = 'A';
else if(new_letter == 'R')
new_letter = 'B';
else if(new_letter == 'S')
new_letter = 'M';
else if(new_letter == 'T')
new_letter = 'X';
else if(new_letter == 'U')
new_letter = 'E';
else if(new_letter == 'V')
new_letter = 'F';
else if(new_letter == 'W')
new_letter = 'O';
else if(new_letter == 'X')
new_letter = 'N';
else if(new_letter == 'Y')
new_letter = 'R';
else if(new_letter == 'Z')
new_letter = 'S';
}
Cryptogram function, it's much longer, with 26 if statements if the letter is lowercase.