- 1
- 2
- 3
- 4
- 5
- 6
- 7
long a=1;
for(;;)
{
long *p_ex = new long;
*p_ex = a++;
std::cout << *p_ex << std::endl;
}
Нашли или выдавили из себя код, который нельзя назвать нормальным, на который без улыбки не взглянешь? Не торопитесь его удалять или рефакторить, — запостите его на говнокод.ру, посмеёмся вместе!
+13
long a=1;
for(;;)
{
long *p_ex = new long;
*p_ex = a++;
std::cout << *p_ex << std::endl;
}
"У кого больше?" Или пытки компа утечкой памяти)
+141
#include <stdio.h>
#include <conio.h>
#include <windows.h>
int main()
{
nachalo: system("cls");
int a;
printf("Write first number...");
scanf("%i", &a);
int b;
printf("Write second number...");
scanf("%i", &b);
int res1;
res1=a+b;
int res2;
res2=a-b;
int res3;
res3=a*b;
float res4;
res4=(float)a/b;
int res5;
res5=a*a;
int res6;
res6=b*b;
printf("\nSumm of %i + %i = %i\n", a, b, res1);
printf("Difference of %i - %i = %i\n", a, b, res2);
printf("Production of %i * %i = %i\n", a, b, res3);
printf("Private of %i / %i = %.4f\n\n", a, b, res4);
printf("Square of %i is %i\n", a, res5);
printf("Square of %i is %i\n\n", b, res6);
int max;
max = (b>a) ? b:a;
printf("The greatest number of %i and %i is %d\n\n", a, b, max);
int choice;
printf("To run program again, press number 1, else numbers \nor symbols will close the program...\n> ");
scanf("%i", &choice);
if (choice == 1)
{
goto nachalo;
}
else (choice != 1);
{
return 0;
}
}
Калькулятор. Nuff said
+16
#include <functional>
using namespace std;
class O{};
class foo
{
public:
constexpr static auto anyGarbage = O(O(O(O())));//:Жаль, что написать auto anyGarbage = O(O(O(O()))); нельзя.
O anyGarbage2 = O(O(O(O())));
private:
int var;
public:
std::function<void(int)> setter=[this](int s){(void)s;/*var=s;*/};
};
Я хочу написать свои property, принимающие лямбды в качестве параметра setter и getter. Как сделать friend лямбду?
http://liveworkspace.org/code/39082e70108502c2e44c4fe6c5762d9a
+33
std::function<int()> gl()
{
int a=0;
return [=]()mutable{return a++;};
}
int main()
{
auto a=gl();
cout
<<a()
<<endl
<<a()
<<endl
<<a()
<<endl
<<a();
return 0;
}
http://liveworkspace.org/code/22012a32e91743cd7357c86930df4b9c+48
PHP supports eight primitive types - four scalar types, two compound types and finally three special types.
8 == 4+2+3?
http://www.php.net/manual/en/language.types.intro.php
+18
template <typename TYPE> class Ptr
{
public:
Ptr():
Pointer_(0),
IsValid_(false)
{
}
Ptr( const Ptr<TYPE> &other )
{
this->Pointer_ = other.Pointer_;
this->IsValid_ = other.IsValid_;
}
Ptr( TYPE* &ptr ):
IsValid_(true)
{
if ( std::find( Ptr<TYPE>::List_.begin(), Ptr<TYPE>::List_.end(), ptr ) == Ptr<TYPE>::List_.end() )
Ptr<TYPE>::List_.push_back( ptr );
this->Pointer_ = ptr;
}
~Ptr()
{
}
inline Ptr<TYPE>& operator = ( const Ptr<TYPE> &other )
{
this->Pointer_ = other.Pointer_;
this->IsValid_ = other.IsValid_;
return *this;
}
inline Ptr<TYPE>& operator = ( TYPE* &ptr )
{
if ( std::find( Ptr<TYPE>::List_.begin(), Ptr<TYPE>::List_.end(), ptr ) == Ptr<TYPE>::List_.end() )
Ptr<TYPE>::List_.push_back( ptr );
this->Pointer_ = ptr;
this->IsValid_ = true;
return *this;
}
inline bool operator == ( const Ptr<TYPE> &other )
{
return (this->Pointer_ == other.Pointer_) ? true:false;
}
inline bool operator != ( const Ptr<TYPE> &other )
{
return (this->Pointer_ != other.Pointer_) ? true:false;
}
inline TYPE* operator -> ()
{
return this->Pointer_;
}
inline bool isValid() const
{
if (!this->IsValid_)
return false;
return this->IsValid_ = ( (std::find( Ptr<TYPE>::List_.begin(), Ptr<TYPE>::List_.end(), this->Pointer_ ) == Ptr<TYPE>::List_.end() ) ? false:true );
}
inline void release()
{
if ( this->isValid() )
{
Ptr<TYPE>::List_.erase( std::find( Ptr<TYPE>::List_.begin(), Ptr<TYPE>::List_.end(), this->Pointer_ ) );
delete this->Pointer_;
}
this->Pointer_ = 0;
this->IsValid_ = false;
}
inline TYPE* get()
{
return this->Pointer_;
}
private:
TYPE* Pointer_;
mutable bool IsValid_;
static std::list < TYPE* > List_;
};
template <typename TYPE> std::list < TYPE* > Ptr<TYPE>::List_;
+139
<HEADER>
<TITLE>The World Wide Web project</TITLE>
<NEXTID N="55">
</HEADER>
<BODY>
<H1>World Wide Web</H1>The WorldWideWeb (W3) is a wide-area<A
NAME=0 HREF="WhatIs.html">
hypermedia</A> information retrieval
initiative aiming to give universal
access to a large universe of documents.<P>
Everything there is online about
W3 is linked directly or indirectly
to this document, including an <A
NAME=24 HREF="Summary.html">executive
summary</A> of the project, <A
NAME=29 HREF="Administration/Mailing/Overview.html">Mailing lists</A>
, <A
NAME=30 HREF="Policy.html">Policy</A> , November's <A
NAME=34 HREF="News/9211.html">W3 news</A> ,
<A
NAME=41 HREF="FAQ/List.html">Frequently Asked Questions</A> .
<DL>
<DT><A
NAME=44 HREF="../DataSources/Top.html">What's out there?</A>
<DD> Pointers to the
world's online information,<A
NAME=45 HREF="../DataSources/bySubject/Overview.html"> subjects</A>
, <A
NAME=z54 HREF="../DataSources/WWW/Servers.html">W3 servers</A>, etc.
<DT><A
NAME=46 HREF="Help.html">Help</A>
<DD> on the browser you are using
<DT><A
NAME=13 HREF="Status.html">Software Products</A>
<DD> A list of W3 project
components and their current state.
(e.g. <A
NAME=27 HREF="LineMode/Browser.html">Line Mode</A> ,X11 <A
NAME=35 HREF="Status.html#35">Viola</A> , <A
NAME=26 HREF="NeXT/WorldWideWeb.html">NeXTStep</A>
, <A
NAME=25 HREF="Daemon/Overview.html">Servers</A> , <A
NAME=51 HREF="Tools/Overview.html">Tools</A> ,<A
NAME=53 HREF="MailRobot/Overview.html"> Mail robot</A> ,<A
NAME=52 HREF="Status.html#57">
Library</A> )
<DT><A
NAME=47 HREF="Technical.html">Technical</A>
<DD> Details of protocols, formats,
program internals etc
<DT><A
NAME=40 HREF="Bibliography.html">Bibliography</A>
<DD> Paper documentation
on W3 and references.
<DT><A
NAME=14 HREF="People.html">People</A>
<DD> A list of some people involved
in the project.
<DT><A
NAME=15 HREF="History.html">History</A>
<DD> A summary of the history
of the project.
<DT><A
NAME=37 HREF="Helping.html">How can I help</A> ?
<DD> If you would like
to support the web..
<DT><A
NAME=48 HREF="../README.html">Getting code</A>
<DD> Getting the code by<A
NAME=49 HREF="LineMode/Defaults/Distribution.html">
anonymous FTP</A> , etc.</A>
</DL>
</BODY>
HTML первого в мире сайта, которому на днях исполнился 21 год.
+63
private function lowercase($s) {
$chars_hi = utf8_encode('ABCDEFGHIJKLMNOPQRSTUVWXYZАБВГДЕЖЗИЙКЛМНОПРСТУФХЦЧШЩЪЫЬЭЮЯЁ');
$chars_lo = utf8_encode('abcdefghijklmnopqrstuvwxyzабвгдежзийклмнопрстуфхцчшщъыьэюяё');
return strtr($s, $chars_hi, $chars_lo);
}
Картина маслом: Велосипедист бьётся лбом о локали.
Сие говно выдаёт нечто из греческого алфавита вместо 'ё'.
+138
public class ImageWorkerSingleton
{
private static ImageWorkerSingleton instance;
private ImageWorkerSingleton() { }
public static ImageWorkerSingleton Instance
{
get
{
if (instance == null)
{
instance = new ImageWorkerSingleton();
}
return instance;
}
}
public void Init() {}
public string UrlToImage(Guid id, ImageTypeEnum imageType = ImageTypeEnum.PhotoUndefined)
{
...
}
public bool IsImageExist(Guid id, ImageTypeEnum imageType = ImageTypeEnum.PhotoUndefined)
{
...
}
}
И на кой, здесь синглтон о_О
−78
tg_hujak_v_zap_na_sklade
Название триггера в промышленной системе.
Hint: zap_na_sklade - таблица