- 1
- 2
- 3
- 4
- 5
#!/bin/bash
#
# Поздравляю с 8 марта!
# Желаю море любви, блядь.
#
Нашли или выдавили из себя код, который нельзя назвать нормальным, на который без улыбки не взглянешь? Не торопитесь его удалять или рефакторить, — запостите его на говнокод.ру, посмеёмся вместе!
+140
#!/bin/bash
#
# Поздравляю с 8 марта!
# Желаю море любви, блядь.
#
8===o
+135
// где-то в коде нашлось
PRIVATE IdxArray* idx_array_append_val_dyn(IdxArray* arr, PlmIndex idx)
// private.h
#ifdef PLM_TEST
#define PRIVATE extern
#else
#define PRIVATE static
#endif
внезапно...
+75
public class ExtractSubstrings {
public static void main(String[] args) {
String text = “To be or not to be”;
int count = 0;
char separator = ‘ ‘;
int index = 0;
do {
++count;
++index;
index = text.indexOf(separator, index);
} while (index != -1);
String[] subStr = new String[count];
index = 0;
int endIndex = 0;
for(int i = 0; i < count; ++i) {
endIndex = text.indexOf(separator,index);
if(endIndex == -1) {
subStr[i] = text.substring(index);
} else {
subStr[i] = text.substring(index, endIndex);
}
index = endIndex + 1;
}
for(String s : subStr) {
System.out.println(s);
}
}
}
Очень чёткий, простой и с первого взгляда сразу понятный способ сделатЬ сплит строки.
+116
public const string Checked = "☑";
public const string Unchecked = "☐";
Чекбокс
+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_;