- 1
- 2
- 3
- 4
- 5
- 6
- 7
- 8
- 9
public static unsafe int Strlen(byte* data)
{
int i = 0;
while (data[i] != 0)
{
++i;
}
return i;
}
Нашли или выдавили из себя код, который нельзя назвать нормальным, на который без улыбки не взглянешь? Не торопитесь его удалять или рефакторить, — запостите его на говнокод.ру, посмеёмся вместе!
Всего: 9
−4
public static unsafe int Strlen(byte* data)
{
int i = 0;
while (data[i] != 0)
{
++i;
}
return i;
}
Работа с C строками
−13
#include <iostream>
#include <vector>
enum class en : int {first,second,};
int main(int argc, char **argv) {
std::initializer_list<int> l = {1,2,3,4,5,6,};
std::cerr << "size:" << l.size() << std::endl;
for (const auto & elem : l )
{
std::cerr << elem << ' ';
}
std::cerr << std::endl;
return 0;
}
WTF???
−21
try {
shadow_page.insert_record(index, record);
} catch ( ... ) {
throw;
}
−50
DROP TABLE cur;
create table cur (
id int AUTO_INCREMENT,
name varchar(3),
value int,
data datetime,
PRIMARY KEY (id)
);
insert into cur values
(1, 'usd', 30, '20170130'),
(2, 'usd', 33, '20170130'),
(3, 'eur', 40, '20170130'),
(4, 'gbp', 50, '20170130');
select * from (select * from cur order by data DESC, id desc)
t1 group by name;
# работает только на MySQL
no coments;
−51
const char * c_version()
{
const char * hui = "hui";
const char * pizda = "pizda";
unsigned long huilen = strlen ( hui );
unsigned long pizdalen = strlen ( pizda );
char * sobaka = ( char* ) ::malloc ( (huilen + pizdalen) + 2 );
strcat ( sobaka,hui );
strcat ( ( sobaka + huilen ),"&" );
strcat ( ( sobaka + huilen + 1 ),pizda );
sobaka[huilen + pizdalen + 1] = '\0';
return sobaka;
}
Склеиваем строки
−21
#include <iostream>
#include <regex>
#include <strstream>
double calc(const double& a,const double & b,char op)
{
switch(op)
{
case '+':
return a+b;
case '-':
return a-b;
case '/':
return a/b;
case '*':
return a*b;
}
}
std::string calc(const std::string & ex )
{
double a{},b{};
char op{};
std::stringstream str;
str << ex;
str >> a >> op >> b;
return std::to_string(calc(a,b,op));
}
std::string parse_first(const std::string & in)
{
std::string res;
std::regex re("\\(\\d+(\\*|\\/|\\+|\\-)\\d+\\)");
std::sregex_token_iterator begin(in.begin(),in.end(),re,0);
while(begin != std::sregex_token_iterator())
{
std::string temp = begin->str();
std::regex r("(\\(|\\))");
temp = std::regex_replace(temp,r,"");
std::string calced = calc(temp);
r.assign(begin->str());
res = std::regex_replace(in,re,calced);
++begin;
}
return res;
}
std::string parse_second(const std::string & in)
{
std::string res = in;
std::regex re("\\d+(\\.\\d+)?(\\*|\\/)\\d+(\\.\\d+)?");
std::sregex_token_iterator begin(in.begin(),in.end(),re,0);
while(begin != std::sregex_token_iterator())
{
std::string calced = calc(*begin);
std::regex r(begin->str());
res = std::regex_replace(in,r,calced);
++begin;
}
return res;
}
double calculate(const std::string & in)
{
std::string res = parse_second(parse_first(in));
std::stringstream final;
final << res;
double result{},second{};
final >> result;
char op;
while ((final >> op >> second ))
{
result =calc(result,second,op);
}
return result;
}
int main(int argc, char *argv[])
{
std::string in;
std::getline(std::cin,in);
std::regex re(" ");
in =std::regex_replace(in,re,"");
std::cerr << calculate(in) << std::endl;
return 0;
}
Посчитал выражение)
−15
#include "document_validator_factory.h"
std::unique_ptr<ortax::DocumentValidator>
ortax::DocumentValidatorFactory::create_validator(ortax::DocumentType doc_type)
{
if (doc_type == DocumentType::RussianPassport) //21
{
return std::make_unique<BirthPlaceValidator>(
std::make_unique<DocIssuerValidator>(
std::make_unique<SubdivisionCodeValidator>(
std::make_unique<PassportExpireDateValidator>(
std::make_unique<RussianPassportValidator>()))));
}
else if (doc_type == DocumentType::MilitarySoldierTicket) //4
{
return std::make_unique<BirthPlaceValidator>(
std::make_unique<DocIssuerValidator>(
std::make_unique<DefaultDocumentValidator>()));
}
else if (doc_type == DocumentType::MilitarySoldierTicket) //7
{
return std::make_unique<BirthPlaceValidator>(
std::make_unique<DocIssuerValidator>(
std::make_unique<DefaultDocumentValidator>()));
}
else if (doc_type == DocumentType::SeamanPassport) //26
{
return std::make_unique<BirthPlaceValidator>(
std::make_unique<ExpireDateValidator>(
std::make_unique<DefaultDocumentValidator>()));
}
else if (doc_type == DocumentType::TemporaryIdentityCard) //14
{
return std::make_unique<BirthPlaceValidator>(
std::make_unique<ExpireDateValidator>(
std::make_unique<DefaultDocumentValidator>()));
}
else if (doc_type == DocumentType::ResidensePermitRu) //12
{
return std::make_unique<BirthPlaceValidator>(
std::make_unique<ExpireDateValidator>(
std::make_unique<DefaultDocumentValidator>()));
}
else if (doc_type == DocumentType::ForeignPassport) //10
{
return std::make_unique<BirthPlaceValidator>(
std::make_unique<DocIssuerValidator>(
std::make_unique<DefaultDocumentValidator>()));
}
else if (doc_type == DocumentType::ForeignPassport) //15
{
return std::make_unique<ExpireDateValidator>(
std::make_unique<DefaultDocumentValidator>());
}
else
{
return std::make_unique<DefaultDocumentValidator>();
}
}
Мой архитектор использует паттерны
−14
#ifndef RPCCALL_H
#define RPCCALL_H
#include <deque>
#include <typeinfo>
#include <string>
#include "byteinbuffer.h"
#include <byteoutbuffer.h>
#include <ostream>
class RPCPack
{
public:
RPCPack();
//RPCPack(const RPCPack &obj);
RPCPack(RPCPack && obj);
RPCPack & operator = (RPCPack&& obj);
template<class T, typename std::enable_if<
std::is_pod<T>::value && !std::is_pointer<T>::value>::type* = nullptr>
bool pack(const T& param);
template <class T,typename std::enable_if<
std::is_same<typename T::iterator::iterator_category,std::random_access_iterator_tag>::value>::type* = nullptr>
bool pack(const T& param);
template <class T,typename std::enable_if<
std::is_same<typename T::iterator::iterator_category,std::bidirectional_iterator_tag>::value>::type* = nullptr>
bool pack(const T& param);
template <class T,typename std::enable_if<
std::is_same<typename T::iterator::iterator_category,std::forward_iterator_tag>::value>::type* = nullptr>
bool pack(const T& param);
template<class D,class ... T >
bool pack(const D& param,const T& ... params);
template<class ... T>
bool pack(const T& ... params);
template<class T, typename std::enable_if<
std::is_pod<T>::value && !std::is_pointer<T>::value && !std::is_array<T>::value>::type* = nullptr>
bool unpack(T& param);
template <class T,typename std::enable_if<
std::is_same<typename T::iterator::iterator_category,std::random_access_iterator_tag>::value>::type* = nullptr>
bool unpack(T& param);
template <class T,typename std::enable_if<
std::is_same<typename T::iterator::iterator_category,std::bidirectional_iterator_tag>::value>::type* = nullptr>
bool unpack(T& param);
template <class T,typename std::enable_if<
std::is_same<typename T::iterator::iterator_category,std::forward_iterator_tag>::value>::type* = nullptr>
bool unpack(T& param);
template<class D,class ... T >
bool unpack(D& param, T& ... params);
template<class ... T>
bool unpack(T& ... params);
template <class T,class D>
bool pack(const std::pair<T,D> & p);
template <class T,class D>
bool unpack(std::pair<T,D>& p);
std::vector<char> getSerialized();
void deserialize(std::istream &vs);
size_t getSize();
bool isEmpty();
void copyOuttoIn();
void moveOuttoIn();
ByteOutBuffer<char> getBuffer() const;
void setBuffer(const ByteOutBuffer<char> &value);
private:
std::deque<size_t> sig;
std::vector<char> outdata;
std::vector<char> indata;
ByteOutBuffer<char> outbuffer;
ByteInBuffer<char> inbuffer;
std::istream is;
std::ostream os;
};
template<class T, typename std::enable_if<
std::is_pod<T>::value && !std::is_pointer<T>::value>::type*>
bool RPCPack::pack(const T& param)
{
sig.push_back(typeid(param).hash_code());
if(os.write((char*)¶m,sizeof(param)))
return true;
return false;
}
template <class T,class D>
bool RPCPack::pack(const std::pair<T,D>& param)
{
return pack(param.first) & pack(param.second);
}
template <class T,class D>
Хуячу сериализацию. Я метапрограммер)
+73
for (int i = 1; i <= 3; i++) {
if (i <= arr.length) {
xmlDocumentNode.setNodeValue("P_15_" + i, arr[i - 1].getNAME());
xmlDocumentNode.setNodeValue("P_16_" + i, arr[i - 1].getSERIAL());
xmlDocumentNode.setNodeValue("P_17_1_" + i, arr[i - 1].getPLANTMANUF());
xmlDocumentNode.setNodeValue("P_17_2_" + i, arr[i - 1].getPLANTMANUFNAME());
xmlDocumentNode.setNodeValue("P_18_" + i, arr[i - 1].getDATEMANUF());
xmlDocumentNode.setNodeValue("P_19_1_" + i, arr[i - 1].getPLANTREP());
xmlDocumentNode.setNodeValue("P_19_2_" + i, arr[i - 1].getPLANTREPNAME());
xmlDocumentNode.setNodeValue("P_20_" + i, arr[i - 1].getDATEREP());
xmlDocumentNode.setNodeValue("P_21_1_" + i, arr[i - 1].getDEFECT());
xmlDocumentNode.setNodeValue("P_21_2_" + i, arr[i - 1].getDEFECTNAME());
} else {
xmlDocumentNode.setNodeValue("P_15_" + i, "");
xmlDocumentNode.setNodeValue("P_16_" + i, "");
xmlDocumentNode.setNodeValue("P_17_1_" + i, "");
xmlDocumentNode.setNodeValue("P_17_2_" + i, "");
xmlDocumentNode.setNodeValue("P_18_" + i, "");
xmlDocumentNode.setNodeValue("P_19_1_" + i, "");
xmlDocumentNode.setNodeValue("P_19_2_" + i, "");
xmlDocumentNode.setNodeValue("P_20_" + i, "");
xmlDocumentNode.setNodeValue("P_21_1_" + i, "");
xmlDocumentNode.setNodeValue("P_21_2_" + i, "");
}
}
Обработка XML-таблиц. fillTable? не, не слышал