Нашли или выдавили из себя код, который нельзя назвать нормальным,
на который без улыбки не взглянешь?
Не торопитесь его удалять или рефакторить, — запостите его на
говнокод.ру, посмеёмся вместе!
std::string basic::_gettime(time_t t)
{
string res;
string tt;
//must be Wdy, DD-Mon-YYYY HH:MM:SS GMT
struct tm *tm_res;
tm_res=gmtime(&t);
switch(tm_res->tm_wday)
{
case 0:
res+="Sun";
break;
case 1:
res+="Mon";
break;
case 2:
res+="Tue";
break;
case 3:
res+="Wed";
break;
case 4:
res+="Thu";
break;
case 5:
res+="Fri";
break;
case 6:
res+="Sat";
break;
default:
throw "Internal error: cgi_app::_gettime(): Day num>6!";
}
res+=", ";
tt=itoa(tm_res->tm_mday);
if(tt.length()==1)
tt="0"+tt;
res+=tt;
res+="-";
switch(tm_res->tm_mon)
{
case 0:
res+="Jan";
break;
case 1:
res+="Feb";
break;
case 2:
res+="Mar";
break;
case 3:
res+="Apr";
break;
case 4:
res+="May";
break;
case 5:
res+="Jun";
break;
case 6:
res+="Jul";
break;
case 7:
res+="Aug";
break;
case 8:
res+="Sep";
break;
case 9:
res+="Oct";
break;
case 10:
res+="Nov";
break;
case 11:
res+="Dec";
break;
default:
throw "Internal error: cgi_app::_gettime(): Month num>11!";
}
res+="-";
tt=itoa(tm_res->tm_year+1900);
res+=tt;
res+=" ";
tt=itoa(tm_res->tm_hour);
if(tt.length()==1)
tt="0"+tt;
res+=tt;
res+=":";
tt=itoa(tm_res->tm_min);
if(tt.length()==1)
tt="0"+tt;
res+=tt;
res+=":";
tt=itoa(tm_res->tm_sec);
if(tt.length()==1)
tt="0"+tt;
res+=tt;
res+=" GMT";
}
Делаю класс для работы с CGI. Сначала хотел использовать какое-нибудь готовое решение, но ничего подходящего не нашел. По общей концепции понравилась библиотека "CGI C++ Library v0.30a". До тех пор, пока не посмотрел исходники более внимательно... Это функция, которая формирует строку для поля заголовка HTTP "Last-Modified".
На самом деле, это больше бы подошло в раздел "ООП", но раз уж такого нет, то пощу в PHP. Вообще, весь проект, в котором приходится разбираться - редкое дерьмо, но этот ляп меня умилил :)
// генерируем 2 раз для лучшей случайности
$wpdb->get_results('SELECT id FROM ' . $table_prefix . 'another_random_quote WHERE tag="'.$tag.'" ORDER BY RAND() LIMIT 1');
$quotes = $wpdb->get_results('SELECT * FROM ' . $table_prefix . 'another_random_quote WHERE tag="'.$tag.'" ORDER BY RAND() LIMIT ' . intval($amount));
Встретил в плагине для вордпресса. Объясните, что такое лучшая случайность?
...
// TODO: remove this godless "switch()"!
switch(tuntype) { // TODO: Important: do as in documentation instead of reverse-ingeniering!
#define PACKET_TRY {\
if(packet->ip_v == 4) {\
hl=packet->ip_hl<<2;\
if(hl>=sizeof(*packet))\
break;\
/* TODO: Check in RFC something about of ICMP send-back in this case */\
fprintf(stderr, "Got too short IP-header (%i)...\n",hl);\
}\
if((packet->ip_v&IPV6_VERSION_MASK) == IPV6_VERSION) {\
break;\
}\
}
#define NEXT(a) tuntype=a;\
if(tuntry>=2)\
goto tun_process_switch_end;\
tuntry++;
#define CASE(a) NEXT(a);\
case a
tun_process_switch:
// switch(tuntype) {
case TUNTYPE_NORM: // NetBSD-like?
packet=(typeof(packet))ptr;
PACKET_TRY;
CASE(TUNTYPE_EXT): // FreeBSD-like?
packet=(typeof(packet))((char *)ptr + 4);
if(s>4)
if(*ptr==0x02)
PACKET_TRY;
CASE(TUNTYPE_ETH): // Ethernet? TODO: Implement VLAN-tagging
packet=(typeof(packet))((char *)ptr + sizeof(*eth));
eth=(typeof(eth))ptr;
if(!teth) {
teth=alloca(sizeof(*teth));
memcpy(&teth->ether_shost, ð->ether_dhost, sizeof(teth->ether_shost));
memcpy(&teth->ether_dhost, ð->ether_shost, sizeof(teth->ether_dhost));
teth->ether_type=ETHERTYPE_IP;
}
if(s>sizeof(*eth))
// if((*(char *)ð->ether_type==0x08/* not IPv4? */)||(*(char *)ð->ether_type==0x86/* not IPv6? */)) // TODO: Implement compatibility with all protocols over ethernet
PACKET_TRY;
NEXT(TUNTYPE_NORM);
goto tun_process_switch;
default:
tuntype=TUNTYPE_NORM;
goto tun_process_switch;
// }
tun_process_switch_end:
#undef CASE
#undef NEXT
#undef PACKET_TRY
if(tuntry<~0)
tuntry=0;
tuntype=oldtuntype;
fprintf(stderr, "Got unknown packet. Flushing...\n");
FLUSH; // Flush all. We don't know the length of packet with unknown type.. So, we have to flush the buffer, to probably get new packets from the start.
goto tun_process_while;
}
...
/*
CANON D-SLR cameras core routine
Property of CANON INC. 1998-2010
v 1.0 made by Radja Tokamoto Goines
v 1.1 made by Dugwin Yakioto jr.
last changes: 10.11.2009
*/
#include <stdlib.h>
#include <math.h>
#include <time.h>
#include "inc/tweakfocus.h"
#include "inc/radja_filters.h"
bool do_focus(lens, camera) {
double fp;
time_t t;
t = init_focus_timer(t);
do {
fp = measure_focus_point(lens);
move_focus(lens, fp)
if (timeout(t))
return false;
} while (!lens.is_focused());
if (!L_LensDetected(lens))
lens.adjust_focus(rand(10));
return true;
}
rawdata * scandata(matrix, lens, camera) {
rawdata *cr;
double noise, aberrations;
cr = create_cr(matrix);
read_exif_info(cr->exif, lens, camera);
prepare_everything(matrix, lens, camera);
if (!do_focus(lens, camera))
return NULL;
else
beep();
aberrations = pow(100 - lens.focallength, 2) * sqrt(2) + 10;
if (L_LensDetected(lens))
aberrations /= 2.0;
scan_sensor(cr, matrix, aberrations);
noise = matrix.iso / 100.0;
noise *= matrix.cropfactor;
if (camera.model == EOS1000D) {
noise *= 1.2;
wait_for_something();
}
if (camera.model != EOS7D)
wait_for_something();
if (lens.manufacture != CANON_LENS) {
corrupt_something(cr);
apply_random_filter(cr);
}
if (lens.model == EF_50_F1_4) {
noise /= 1.2;
apply_fcb(cr); //fucken cool bokeh
}
if (lens.model == CANON_L_17_40_F4) {
blur(cr, 0.8);
distort(cr, 40 - lens.focallength);
}
radja_filter(cr, 1.570796326794896619231321691641); //don't touch that!
if (is_eos1d_series(camera.model))
disable_all_spoiling(cr);
else
make_nice_colors(cr);
// finally...
apply_noise(cr, noise);
apply_barrel_distortion(cr, lens);
apply_pillow_distortion(cr, lens);
return cr;
}
http://habrahabr.ru/blogs/DSLR/74958/
Исходные тексты прошивки canon eos.
Многие, наверное, уже слышали, что на днях была взломана внутренняя сеть компании Canon и в числе прочего в сеть «утёк» кусок ядра исходных текстов прошивки камер серии EOS, который я имею честь эксклюзивно опубликовать на суд общественности.
Говночитатели без ЧЮ идут в *опу.