- 01
- 02
- 03
- 04
- 05
- 06
- 07
- 08
- 09
- 10
- 11
- 12
#include <iostream>
using namespace std;
class Program
{
public:
friend int main()
{
return 0;
}
};
Нашли или выдавили из себя код, который нельзя назвать нормальным, на который без улыбки не взглянешь? Не торопитесь его удалять или рефакторить, — запостите его на говнокод.ру, посмеёмся вместе!
+38
#include <iostream>
using namespace std;
class Program
{
public:
friend int main()
{
return 0;
}
};
Мой знакомый говорит, что его компилятор поддерживает Java\C#-нотацию точки входа таким образом. И ещё он говорит, что так должно компилироваться по стандарту.
+33
class Chatter : public QListBoxItem {
[...]
private:
static ChatterRef *chatters[MAX_NUM_CHATTERS];
[...]
friend int main(int, char *argv[]); // to destroy chatters[]
};
Сам проект: http://www.qtchat.org/qtchat/
Пример дается в этой книге: http://books.google.ru/books?id=8lYbNfsAVT4C&dq=qtchat&source=g bs_navlinks_s как пример friend-функций
+36
gp_terrains.at(0)->draw();
//it took me only 50 lines of spaghetti code to implement the spiral layout
//direction 1 for +x, 2 for +y, 3: -x, 0: -y
int repetition_count = 1;
int i = 1;
int direction = 0;
while(i < (int)gp_terrains.size()) {
for (int k = 0; k < 2; k++) {
direction = (++direction) % 4;
for (int j = 0; j < repetition_count; j++) {
switch(direction) {
case 1: {
glTranslated(512, 0, 0);
gp_terrains.at(i)->draw();
break;
}
case 2: {
glTranslated(0, 512, 0);
gp_terrains.at(i)->draw();
break;
}
case 3: {
glTranslated(-512, 0, 0);
gp_terrains.at(i)->draw();
break;
}
case 0: {
glTranslated(0, -512, 0);
gp_terrains.at(i)->draw();
break;
}
}
if (++i >= (int)gp_terrains.size())
break;
}
if (i >= (int)gp_terrains.size())
break;
}
if (i >= (int)gp_terrains.size())
break;
repetition_count++;
−98
-(UIImage*) getImageForDigit:(int)value
{
UIImage *img = nil;
switch (value)
{
case -1:
{
img = [UIImage imageNamed:@"beat_0_off.png"];
break;
}
case 0:
{
img = [UIImage imageNamed:@"beat_0.png"];
break;
}
case 1:
{
img = [UIImage imageNamed:@"beat_1.png"];
break;
}
case 2:
{
img = [UIImage imageNamed:@"beat_2.png"];
break;
}
case 3:
{
img = [UIImage imageNamed:@"beat_3.png"];
break;
}
case 4:
{
img = [UIImage imageNamed:@"beat_4.png"];
break;
}
case 5:
{
img = [UIImage imageNamed:@"beat_5.png"];
break;
}
case 6:
{
img = [UIImage imageNamed:@"beat_6.png"];
break;
}
case 7:
{
img = [UIImage imageNamed:@"beat_7.png"];
break;
}
case 8:
{
img = [UIImage imageNamed:@"beat_8.png"];
break;
}
case 9:
{
img = [UIImage imageNamed:@"beat_9.png"];
break;
}
default:
{
break;
}
}
return img;
}
Ученица отрыла простановку цифр на "кагбэ жидкокристаллический" дисплей.
+20
D:\Sources\jimbot_at_cpp>make -f Makefile.win clean-full
rm -f *.o lib.a dist/jimbot.exe
D:\Sources\jimbot_at_cpp>make -f Makefile.win lib
gcc -c sqlite3.c -pipe -O2 -g1 DSQLITE_THREADSAFE=1
gcc.exe: error: DSQLITE_THREADSAFE=1: No such file or directory
make: *** [lib] Error 1
D:\Sources\jimbot_at_cpp>make -f Makefile.win
g++ -c *.cpp -std=c++0x -O2 -g1 -pipe -Wno-deprecated -Wno-write-strings -Wno-de
precated-declarations -DDEBUG -DEASTER -DTESTER
g++ -o dist/jimbot -pipe *.o -O2 -g1 lib.a -lpthread -lgnutls -lwsock32 -ladvap
i32 -lcrypt32 -lsecur32 -ldnsapi -liconv
g++.exe: error: lib.a: No such file or directory
make: *** [all] Error 1
D:\Sources\jimbot_at_cpp>
+134
// histogram_data.c 550 Kb
int n_records = 100000;
unsigned char data[] = {
215, 100, 200, 204, 233, 50 , 85 , 196, 71 , 141, 122, 160, 93 , 131, 243, 234, 162, 183, 36 , 155,
4 , 62 , 35 , 205, 40 , 102, 33 , 27 , 255, 55 , 131, 214, 156, 75 , 163, 134, 126, 249, 74 , 197,
134, 197, 102, 228, 72 , 90 , 206, 235, 17 , 243, 134, 22 , 49 , 169, 227, 89 , 16 , 5 , 117, 16 ,
60 , 248, 230, 217, 68 , 138, 96 , 194, 131, 170, 136, 10 , 112, 238, 238, 184, 72 , 189, 163, 90 ,
176, 42 , 112, 225, 212, 84 , 58 , 228, 89 , 175, 244, 150, 168, 219, 112, 236, 101, 208, 175, 233,
123, 55 , 243, 235, 37 , 225, 164, 110, 158, 71 , 201, 78 , 114, 57 , 48 , 70 , 142, 106, 43 , 232,
26 , 32 , 126, 194, 252, 239, 175, 98 , 191, 94 , 75 , 59 , 149, 62 , 39 , 187, 32 , 203, 42 , 190,
19 , 243, 13 , 133, 45 , 61 , 204, 187, 168, 247, 163, 194, 23 , 34 , 133, 20 , 17 , 52 , 118, 209,
146, 193, 13 , 40 , 255, 52 , 227, 32 , 255, 13 , 222, 18 , 1 , 236, 152, 46 , 41 , 100, 233, 209,
91 , 141, 148, 115, 175, 25 , 135, 193, 77 , 254, 147, 224, 191, 161, 9 , 191, 213, 236, 223, 212,
250, 190, 231, 251, 170, 127, 41 , 212, 227, 19 , 166, 63 , 161, 58 , 179, 81 , 84 , 59 , 18 , 162,
57 , 166, 130, 248, 71 , 139, 184, 28 , 120, 151, 241, 115, 86 , 217, 111, 0 , 88 , 153, 213, 59 ,
172, 123, 123, 78 , 182, 46 , 159, 10 , 105, 178, 172, 163, 88 , 47 , 155, 160, 187, 84 , 189, 51 ,
235, 175, 167, 65 , 136, 22 , 66 , 224, 175, 23 , 28 , 92 , 147, 151, 170, 73 , 198, 73 , 84 , 48 ,
251, 0 , 211, 84 , 48 , 111, 245, 235, 195, 178, 31 , 175, 98 , 198, 241, 234, 220, 52 , 203, 140,
// over 5000 строк подобного
int expected_results[] = {
404, 389, 376, 394, 376, 342, 364, 364, 383, 396,
412, 409, 394, 409, 405, 383, 379, 401, 377, 400,
383, 410, 386, 383, 418, 416, 406, 349, 390, 388,
393, 372, 386, 386, 400, 384, 404, 355, 400, 361,
398, 371, 389, 383, 406, 414, 364, 389, 418, 391,
404, 396, 390, 397, 375, 389, 387, 392, 368, 430,
407, 387, 380, 380, 383, 352, 386, 413, 435, 413,
358, 453, 436, 409, 419, 393, 423, 398, 407, 372,
399, 353, 370, 389, 399, 376, 395, 439, 412, 379,
404, 374, 392, 393, 366, 377, 374, 395, 402, 380,
422, 407, 379, 398, 376, 410, 376, 392, 374, 409,
415, 382, 411, 398, 379, 385, 383, 374, 421, 371,
359, 403, 373, 396, 365, 365, 382, 383, 352, 399,
367, 439, 401, 418, 407, 403, 392, 373, 385, 374,
389, 365, 414, 415, 360, 384, 387, 381, 400, 410,
400, 406, 385, 395, 373, 381, 419, 362, 383, 399,
424, 379, 394, 401, 371, 426, 376, 375, 383, 370,
405, 402, 372, 404, 364, 419, 390, 376, 368, 405,
393, 386, 402, 393, 420, 388, 380, 364, 412, 383,
411, 357, 412, 377, 346, 389, 380, 371, 393, 408,
386, 425, 392, 338, 373, 382, 380, 365, 379, 394,
379, 378, 415, 394, 352, 378, 417, 403, 407, 388,
390, 433, 352, 394, 398, 407, 397, 409, 419, 378,
387, 359, 406, 384, 403, 385, 411, 418, 408, 371,
384, 386, 392, 422, 377, 399, 364, 381, 362, 379,
393, 383, 381, 400, 434, 404};
// example_vectors.c - 1.8 Mb
int vector_size=100000;
int vector_a[] = {
215 , 100 , 200 , 204 , 233 , 50 , 85 , 196 , 71 , 141 , 122 , 160 , 93 , 131 , 243 , 234 , 162 , 183 , 36 , 155 ,
4 , 62 , 35 , 205 , 40 , 102 , 33 , 27 , 255 , 55 , 131 , 214 , 156 , 75 , 163 , 134 , 126 , 249 , 74 , 197 ,
134 , 197 , 102 , 228 , 72 , 90 , 206 , 235 , 17 , 243 , 134 , 22 , 49 , 169 , 227 , 89 , 16 , 5 , 117 , 16 ,
60 , 248 , 230 , 217 , 68 , 138 , 96 , 194 , 131 , 170 , 136 , 10 , 112 , 238 , 238 , 184 , 72 , 189 , 163 , 90 ,
176 , 42 , 112 , 225 , 212 , 84 , 58 , 228 , 89 , 175 , 244 , 150 , 168 , 219 , 112 , 236 , 101 , 208 , 175 , 233 ,
123 , 55 , 243 , 235 , 37 , 225 , 164 , 110 , 158 , 71 , 201 , 78 , 114 , 57 , 48 , 70 , 142 , 106 , 43 , 232 ,
26 , 32 , 126 , 194 , 252 , 239 , 175 , 98 , 191 , 94 , 75 , 59 , 149 , 62 , 39 , 187 , 32 , 203 , 42 , 190 ,
19 , 243 , 13 , 133 , 45 , 61 , 204 , 187 , 168 , 247 , 163 , 194 , 23 , 34 , 133 , 20 , 17 , 52 , 118 , 209 ,
146 , 193 , 13 , 40 , 255 , 52 , 227 , 32 , 255 , 13 , 222 , 18 , 1 , 236 , 152 , 46 , 41 , 100 , 233 , 209 ,
91 , 141 , 148 , 115 , 175 , 25 , 135 , 193 , 77 , 254 , 147 , 224 , 191 , 161 , 9 , 191 , 213 , 236 , 223 , 212 ,
250 , 190 , 231 , 251 , 170 , 127 , 41 , 212 , 227 , 19 , 166 , 63 , 161 , 58 , 179 , 81 , 84 , 59 , 18 , 162 ,
57 , 166 , 130 , 248 , 71 , 139 , 184 , 28 , 120 , 151 , 241 , 115 , 86 , 217 , 111 , 0 , 88 , 153 , 213 , 59 ,
172 , 123 , 123 , 78 , 182 , 46 , 159 , 10 , 105 , 178 , 172 , 163 , 88 , 47 , 155 , 160 , 187 , 84 , 189 , 51 ,
235 , 175 , 167 , 65 , 136 , 22 , 66 , 224 , 175 , 23 , 28 , 92 , 147 , 151 , 170 , 73 , 198 , 73 , 84 , 48 ,
// over 15000 cтрок
- Сударь, вы изволили принять наркотических средств?
- Чего?
- Ты что, сука, упоротый?!
−94
def __call__(self, *args, **kw):
# ...
if args and len(args) > 1 and args[0] is args[1][0]:
# fml...
temp = list(args)
temp.pop(1)
args = tuple(temp)
return self._execute(*args, **kw)
Быль про архитектуру.
+29
template <class Monad>
struct XMapM {
template <class F, class M> struct Sig : FunType<F,M,
typename RT<typename ::fcpp::BindM<Monad>::Type,M,typename LEType<
LAM<LV<1>,CALL<typename ::fcpp::UnitM<Monad>::Type,
CALL<F,LV<1> > > > >::Type>::ResultType> {};
template <class F, class M>
typename Sig<F,M>::ResultType
operator()( const F& f, const M& m ) const {
LambdaVar<1> A;
return bindM<Monad>()( m, lambda(A)[ unitM<Monad>()[f[A]] ] );
}
};
Хаскель не нужен.
+95
final HCons<String, HCons<Integer, HCons<Boolean, HNil>>> a =
nil().extend(true).extend(3).extend("Foo");
final HCons<Double, HCons<String, HCons<Integer[], HNil>>> b =
nil().extend(new Integer[]{1, 2}).extend("Bar").extend(4.0);
// A lot of type annotation
final HAppend<HNil, HCons<Double, HCons<String, HCons<Integer[], HNil>>>,
HCons<Double, HCons<String, HCons<Integer[], HNil>>>> zero = append();
final HAppend<HCons<Boolean, HNil>, HCons<Double, HCons<String, HCons<Integer[], HNil>>>,
HCons<Boolean, HCons<Double, HCons<String, HCons<Integer[], HNil>>>>> one = append(zero);
final HAppend<HCons<Integer, HCons<Boolean, HNil>>, HCons<Double, HCons<String, HCons<Integer[], HNil>>>,
HCons<Integer, HCons<Boolean, HCons<Double, HCons<String, HCons<Integer[], HNil>>>>>> two = append(one);
final HAppend<HCons<String, HCons<Integer, HCons<Boolean, HNil>>>,
HCons<Double, HCons<String, HCons<Integer[], HNil>>>,
HCons<String, HCons<Integer, HCons<Boolean, HCons<Double, HCons<String, HCons<Integer[], HNil>>>>>>>
three = append(two);
// And all of that lets us append one list to the other.
final HCons<String, HCons<Integer, HCons<Boolean, HCons<Double, HCons<String, HCons<Integer[], HNil>>>>>>
x = three.append(a, b);
// And we can access the components of the concatenated list in a type-safe manner
System.out.println(x.head()); // Foo
System.out.println(x.tail().tail().tail().tail().head()); // Bar
Это вот такая она, функциональщина, упрощающая жизнь.
http://functionaljava.googlecode.com/svn/artifacts/3.0/demo/1.5/HList_append.java
+52
foreach ($sxe->categories->category as $category) {
$cid = $category['id'];
if ($clear == 0) {
$query = "SELECT `id` FROM `" . PREF . "category` WHERE `id`='" . $cid . "' LIMIT 1;";
$result = mysql_query($query);
if (mysql_num_rows($result) == 0) {
$parent = $category['parentId'];
$name = quote_smart($category);
$query = "INSERT IGNORE INTO `" . PREF . "category` VALUES('$cid','$parent','$name','1', 0);";
mysql_query($query);
}
} else {
$parent = $category['parentId'];
$name = quote_smart($category);
$query = "INSERT IGNORE INTO `" . PREF . "category` VALUES('$cid','$parent','$name','1');";
mysql_query($query);
}
$cat_i++;
}