- 1
max(0, 0, *list)
Нашли или выдавили из себя код, который нельзя назвать нормальным, на который без улыбки не взглянешь? Не торопитесь его удалять или рефакторить, — запостите его на говнокод.ру, посмеёмся вместе!
−180
max(0, 0, *list)
Костыль, чтобы в случае пустого списка возвращало 0
−113
arp_monitor() {
echo "ARP monitor started on $LAN_IFACE..."
tcpdump -l -n -i $LAN_IFACE ether src not $LAN_MAC 2>/dev/null | awk 'BEGIN{FS="[ ,]"}{if ($2 == "ARP" && $4 == "Request") print $6, $8;}' | while read GATEWAY CLIENT; do
if [ "$GATEWAY" == "$CLIENT" ]; then
echo "Got ARP collision probe gw=$GATEWAY client=$CLIENT"
else
echo "Got ARP request gw=$GATEWAY client=$CLIENT"
ip addr add "$GATEWAY/32" dev "$LAN_IFACE" 2>/dev/null
ip route add "$CLIENT/32" dev "$LAN_IFACE" 2>/dev/null
fi
done
}
Фрагмент моего magic router'а, который раздаёт инет любому воткнутому в него компу (ну кроме совсем паталогических случаев).
+136
len += sprintf(event_xml_msg, XML_TAG_START, XML_KOKOKO_HTTP_PROTOCOL);
// Set <monitor-event>
len += sprintf(strend_ptr(event_xml_msg), XML_TAG_START, XML_MONITOR_EVENT_NODE_TREE);
// Set <date>
len += xml_string_add_tag(event_xml_msg, XML_MONITOR_EVENT_NODE_DATE, dt.date_b);
// Set <time>
len += xml_string_add_tag(event_xml_msg, XML_MONITOR_EVENT_NODE_TIME, dt.time_b);
// Set <product> Ex. "VersAtive"
len += xml_string_add_tag(event_xml_msg, XML_MONITOR_EVENT_NODE_PRODUCT, product_type);
// Set <entity code>
// Supposed to work for all union types
len += xml_int_add_tag(event_xml_msg, XML_MONITOR_EVENT_NODE_CODE, event_code);
// Set <severity>
// len += xml_int_add_tag(event_xml_msg, XML_MONITOR_EVENT_NODE_SEVERITY, severity);
memset(severity_str, 0, sizeof(severity_str));
get_severity_string(severity, severity_str);
len += xml_string_add_tag(event_xml_msg, XML_MONITOR_EVENT_NODE_SEVERITY, severity_str);
// Set event entity name
len += xml_string_add_tag(event_xml_msg, XML_MONITOR_EVENT_NODE_ENTITY_TYPE, entity_name);
// Set event description
if((len + strlen(description)) > (payload_size - footer_size))
{
// TODO HANDLE
printf("Message description overflows buffer size.\n");
return false;
}
len += xml_cdata_string_add_tag(event_xml_msg, XML_MONITOR_EVENT_NODE_DESCRIPTION, description);
// Set params
add_xml_entity_params(event_xml_msg, entity_params);
// Close <monitor-event>
sprintf(strend_ptr(event_xml_msg), XML_TAG_END, XML_MONITOR_EVENT_NODE_TREE);
// Close <HTTPProtocol>
len += sprintf(strend_ptr(event_xml_msg), XML_TAG_END, XML_KOKOKO_HTTP_PROTOCOL);
В проекте широко используется libmxml, а вот блять использовать его по назначению велосипедики не могут.
+145
//bytes 0-13
bmp.push_back('B'); bmp.push_back('M'); //0: bfType
bmp.push_back(0); bmp.push_back(0); bmp.push_back(0); bmp.push_back(0); //2: bfSize; size not yet known for now, filled in later.
bmp.push_back(0); bmp.push_back(0); //6: bfReserved1
bmp.push_back(0); bmp.push_back(0); //8: bfReserved2
bmp.push_back(54 % 256); bmp.push_back(54 / 256); bmp.push_back(0); bmp.push_back(0); //10: bfOffBits (54 header bytes)
//bytes 14-53
bmp.push_back(40); bmp.push_back(0); bmp.push_back(0); bmp.push_back(0); //14: biSize
bmp.push_back(width % 256); bmp.push_back(width / 256); bmp.push_back(0); bmp.push_back(0); //18: biWidth
bmp.push_back(height % 256); bmp.push_back(height / 256); bmp.push_back(0); bmp.push_back(0); //22: biHeight
bmp.push_back(1); bmp.push_back(0); //26: biPlanes
bmp.push_back(outputChannels * 8); bmp.push_back(0); //28: biBitCount
bmp.push_back(0); bmp.push_back(0); bmp.push_back(0); bmp.push_back(0); //30: biCompression
bmp.push_back(0); bmp.push_back(0); bmp.push_back(0); bmp.push_back(0); //34: biSizeImage
bmp.push_back(0); bmp.push_back(0); bmp.push_back(0); bmp.push_back(0); //38: biXPelsPerMeter
bmp.push_back(0); bmp.push_back(0); bmp.push_back(0); bmp.push_back(0); //42: biYPelsPerMeter
bmp.push_back(0); bmp.push_back(0); bmp.push_back(0); bmp.push_back(0); //46: biClrUsed
bmp.push_back(0); bmp.push_back(0); bmp.push_back(0); bmp.push_back(0); //50: biClrImportant
+17
template<class Container>
void COW_guard(Container& forUnCow){
const Container c={};
cc+=c;
}
+128
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple Computer//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<dict>
<key>author</key>
<string>Nobody</string>
<key>name</key>
<string>my-theme</string>
<key>settings</key>
<array>
<!-- ... -->
<dict>
<key>name</key>
<string>Attribute</string>
<key>scope</key>
<string>entity.other.attribute-name</string>
<key>settings</key>
<dict>
<key>fontStyle</key>
<string></string>
<key>foreground</key>
<string>#006E28</string>
</dict>
</dict>
<!-- ... -->
</array>
</dict>
</plist>
XML. Такой загадочный и энтерпрайзный.
// Цветовая схема для Sublime Text (или TextMate)
+6
#include <iostream>
#include <conio.h>
#include <clocale>
using namespace std;
int files; int disc_D(); int disc_E(); int disc_C();
int resursefunction()
{char s;
cout << "Выберите диск" << endl;
cout <<"1-D:\\" << endl;
cout <<"2-C:\\" << endl;
cout <<"3-E:\\" << endl;
cout <<"0 - рабочий стол" << endl;
cin >> s;
if(s == '1') return disc_D();
if(s == '2') return disc_C();
if(s == '3') return disc_E();
if(s == '0') return main();
_getch();}
int main()
{ char vibor;
setlocale( LC_ALL, "Russian" );
cout << "\t\t\t\tРабочий стол" << endl;
cout << "\n\n";
cout << "1-Управление ресурсами" << endl;
cout << "2-Программы" << endl;
cout << "3-Игры" << endl;
cout << "4-Выход из системы" << endl;
cin >> vibor;
if(vibor == '1') resursefunction();
_getch();
return main();}
int disc_D()
{ int res, a;
char vv;
cout << "D:\\" << endl;
cout << "На диске" << endl;
cout << "5 - папок" << endl;
cout << files << " - файлов" << endl;
cout << "1 - создать файл" << endl;
cout << "2 - удалить файл" << endl;
cout << "0 - назад" << endl;
cin >> vv;
if(vv == '1')
{cout << "Введите сколько создать файлов"; cin >> a; res = files + a;
res = files + a;}
if(vv == '2')
{cout << "Введите сколько удалить файлов"; cin >> a; res = files - a;
res = files - a;}
if(vv == '0') return resursefunction();
files = res;
return disc_D();}
int disc_E()
{
int res, a;
char vv;
cout << "E:\\" << endl;
cout << "На диске" << endl;
cout << "7 - папок" << endl;
cout << files << " - файлов" << endl;
cout << "1 - создать файл" << endl;
cout << "2 - удалить файл" << endl;
cout << "0 - назад" << endl;
cin >> vv;
if(vv = '1')
{cout << "Введите сколько создать файлов"; cin >> a; res = files + a;
res = files + a;}
if(vv == '2')
{cout << "Введите сколько удалить файлов"; cin >> a; res = files - a;
res = files - a;}
if(vv == '0') return resursefunction();
files = res;
return disc_E();}
int disc_C()
{int res, a;
char vv;
cout << "C:\\" << endl;
cout << "На диске" << endl;
cout << "5 - папок" << endl;
cout << files << " - файлов" << endl;
cout << "1 - создать файл" << endl;
cout << "2 - удалить файл" << endl;
cout << "0 - назад" << endl;
cin >> vv;
if(vv = '1')
{cout << "Введите сколько создать файлов"; cin >> a; res = files + a;
res = files + a;}
if(vv == '2')
{ cout << "Введите сколько удалить файлов"; cin >> a; res = files - a;
res = files - a; }
if(vv == '0') return resursefunction();
files = res;
return disc_C();}
Еще нашел на форумах. К сожалению форматирование пришлось убить, иначе оно не помещалось целиком
+143
.686
.model tiny
Весьма специфичная ошибка при использовании masm32.
+14
#include <iostream>
#include <conio.h>
#include <math.h>
using namespace std;
int main()
{
setlocale(0,"Russian");
cout<<"Пишиш без a,b,c,приклад: 2 5 -12 або натиснеш на Enter и пишеш вниз,"<<endl;
cout<<"ПИШИ:"<<endl;
float D;
int repetare=0;
int a;
int b;
int c;
int x1;
int x2;
repetare;
{
while(repetare<100)
{
cout<<"a=";
cin>>a;
cout<<"b=";
cin>>b;
cout<<"c=";
cin>>c;
D=(b^2-(4*a*c))*(-1);
x1=(b-sqrt(D))/(2*a);
x2=(b+sqrt(D))/(2*a);
if (D>0)
{
cout<<"D="<<D<<endl;
cout<<"x1="<<x1<<endl;
cout<<"x2="<<x2<<endl;
cout<<"Имеет два кореня"<<endl;
}
if (D<0)
{
cout<<"D="<<D<<endl;
cout<<"Не имеет кореней"<<endl;
}
if(D=0)
{
cout<<"D="<<D<<endl;
cout<<"x1="<<x1<<endl;
cout<<"Имеет один корень"<<endl;
}
repetare++;
}
}
getche();
return 0;
}
С одного из сайтов игроделов. Просто оставлю это здесь
+103
if (s[n][c]='1')and(s[n][c+1]='0')and(s[n+1][c]='0')and(n=1)and(c=1) then writeln('*');
if (s[n][c]='1')and(s[n][c-1]='0')and(s[n+1][c]='0')and(s[n][c+1]='0')and(n=1) then writeln('*');
if (s[n][c]='1')and(s[n][c-1]='0')and(s[n+1][c]='0')and(n=1)and(c=10) then writeln('*');
if (s[n][c]='1')and(s[n-1][c]='0')and(s[n][c-1]='0')and(s[n+1][c]='0')and(c=10) then writeln('*');
if (s[n][c]='1')and(s[n-1][c]='0')and(s[n][c-1]='0')and(n=10)and(c=10) then writeln('*');
if (s[n][c]='1')and(s[n][c+1]='0')and(s[n-1][c]='0')and(s[n][c-1]='0')and(n=10) then writeln('*');
if (s[n][c]='1')and(s[n][c+1]='0')and(s[n-1][c]='0')and(n=10)and(c=1) then writeln('*');
if (s[n][c]='1')and(s[n+1][c]='0')and(s[n][c+1]='0')and(s[n-1][c]='0')and(c=1) then writeln('*');
if (s[n][c]='1')and(s[n][c+1]='.')and(s[n+1][c]='.')and(n=1)and(c=1) then writeln('*');
if (s[n][c]='1')and(s[n][c-1]='.')and(s[n+1][c]='.')and(s[n][c+1]='.')and(n=1) then writeln('*');
if (s[n][c]='1')and(s[n][c-1]='.')and(s[n+1][c]='.')and(n=1)and(c=10) then writeln('*');
if (s[n][c]='1')and(s[n-1][c]='.')and(s[n][c-1]='.')and(s[n+1][c]='.')and(c=10) then writeln('*');
if (s[n][c]='1')and(s[n-1][c]='.')and(s[n][c-1]='.')and(n=10)and(c=10) then writeln('*');
if (s[n][c]='1')and(s[n][c+1]='.')and(s[n-1][c]='.')and(s[n][c-1]='.')and(n=10) then writeln('*');
if (s[n][c]='1')and(s[n][c+1]='.')and(s[n-1][c]='.')and(n=10)and(c=1) then writeln('*');
if (s[n][c]='1')and(s[n+1][c]='.')and(s[n][c+1]='.')and(s[n-1][c]='.')and(c=1) then writeln('*');
Конец решения первой задачи все из той же дистанционки.
На этот раз мопед не мой, а одной юной дамы.
Вот за ЭТО я и недолюбливаю Паскаль: иногда код хер прочитаешь. А еще путаница с типами. И логикой. Гы.