- 1
- 2
const size_t longstring_size = 1000500; // TODO: O RLY magic constant? => Can't load edges >= 1Mbp
char longstring[longstring_size];
Нашли или выдавили из себя код, который нельзя назвать нормальным, на который без улыбки не взглянешь? Не торопитесь его удалять или рефакторить, — запостите его на говнокод.ру, посмеёмся вместе!
+2
const size_t longstring_size = 1000500; // TODO: O RLY magic constant? => Can't load edges >= 1Mbp
char longstring[longstring_size];
Орфография комментариев сохранена.
+2
using System;
using System.Collections.Generic;
using System.Net;
using System.Web.Script.Serialization;
namespace Govnokod
{
public class Program
{
private static string input;
private static string[] inputargs;
private static int inputargsh = 0;
private static int eax;
private static string hax,hbx;
public static void CommandActions()
{
if (inputargs[0] == "download")
{
if (inputargsh > 1)
{
hax = inputargs[1];
hbx = (inputargsh > 2) ? inputargs[2]:null;
if (String.IsNullOrEmpty(hbx))
hbx = Environment.CurrentDirectory+"\\"+hax;
Console.WriteLine("Downloading...");
}
else Console.WriteLine("invalid argument: 1\n");
}
else if (inputargs[0] == "apkinfo")
{
if (inputargsh > 1)
{
Console.WriteLine("Apkinfo...");
}
else Console.WriteLine("invalid argument: 1\n");
}
else if (input != "")
Console.WriteLine("invalid command: "+input+"\n");
CommandStart();
}
public static void CommandStart()
{
if (inputargsh != 0)
{
Array.Clear(inputargs,0,inputargsh);
inputargsh = 0;
}
input = Console.ReadLine();
input = input.Trim();
hax = input.ToLower();
while (true)
{
eax = hax.IndexOf(' ');
Array.Resize(ref inputargs,inputargsh+1);
if (eax != -1)
{
inputargs[inputargsh] = hax.Substring(0,eax);
hax = hax.Substring(eax);
hax = hax.TrimStart();
inputargsh++;
}
else
{
inputargs[inputargsh] = hax;
inputargsh++;
hax = null;
break;
}
}
if (inputargs[0] == "quit")
{
Console.Clear();
Console.Write("Press any key to quit...");
Console.ReadKey();
}
else CommandActions();
}
public static void Main(string[] args)
{
Console.WriteLine("; Commands:");
Console.WriteLine(";\tdownload <apk> <path>");
Console.WriteLine(";\tapkinfo <apk> or <index>");
Console.WriteLine(";\tquit <>\n");
CommandStart();
}
}
}
"Распознователь Команд 6120"
+2
#define QVERIFY2(statement, description) \
do {\
if (statement) {\
if (!QTest::qVerify(true, #statement, (description), __FILE__, __LINE__))\
return;\
} else {\
if (!QTest::qVerify(false, #statement, (description), __FILE__, __LINE__))\
return;\
}\
} while (0)
Код из QTest либы Qt4.
+2
<input type="hidden" name="lang" value="<?= LANG ?>"/>
<input type="hidden" name="ID" value=<?= $arResult["ID"] ?>/>
<input type="hidden" name="LOGIN" value=<?= $arResult["arUser"]["LOGIN"] ?>/>
Кусок формы редактирования профиля.. Отвлечемся от горячо любимой CMS и сконцентрируемся на сути...
Кодер так спешил, что решил просто type="text" превратить в хиддены. Бог с ним что это дает юзеру намек на то как сменить логин.
Но он забыл кавычки. ID проходит через IntVal и это не заметно. А вот к логину при каждом сохранении дописывается "/", юзера не выкидывает. А вот в следующий раз он должен угадать сколько слэшей добавить к логину. Да и логин запретили менять наверное не просто так, а потому что при регистрации туда прописывается мыло, а вот при апдейте юзера уже не трогают это...
+2
#include "Node.h"
CMonom* CNode::GetMonomPtr() const
{
return _MonomPtr;
}
CNode* CNode::GetNext() const
{
return _NextPtr;
}
bool CNode::GetSign() const
{
return _MonomPtr->GetSign();
}
int CNode::GetCoeff() const
{
return _MonomPtr->GetCoeff();
}
unsigned CNode::GetDegree() const
{
return _MonomPtr->GetDegree();
}
void CNode::SetNext(CNode* Node)
{
_NextPtr = Node;
}
void CNode::SetCoeff(int iCoeff)
{
_MonomPtr->SetCoeff(iCoeff);
}
void CNode::SetDegree(unsigned uDegree)
{
_MonomPtr->SetDegree(uDegree);
}
CNode::CNode(char* szStr) : _NextPtr(nullptr)
{
try
{
_MonomPtr = new CMonom(szStr);
}
catch (const bad_alloc& exc)
{
std::cout << exc.what();
}
}
CNode::CNode(int iCoeff, unsigned uDegree) : _NextPtr(nullptr)
{
try
{
_MonomPtr = new CMonom(iCoeff, uDegree);
}
catch (const bad_alloc& exc)
{
std::cout << exc.what();
}
}
CNode::CNode(const CMonom& Monom) : _NextPtr(nullptr)
{
try
{
_MonomPtr = new CMonom(Monom);
}
catch (const bad_alloc& exc)
{
std::cout << exc.what();
}
}
CNode::CNode(const CNode& Node) : _NextPtr(nullptr)
{
try
{
_MonomPtr = new CMonom(*Node.GetMonomPtr());
}
catch (const bad_alloc& exc)
{
std::cout << exc.what();
}
}
CNode& CNode::operator=(const CNode& Node)
{
SetCoeff(Node.GetCoeff());
SetDegree(Node.GetDegree());
return *this;
}
CNode CNode::operator-() const
{
return CNode(-*_MonomPtr);
+2
public void CreateRow()
{
allow = true;
this.Height = this.Height;
allow = false;
}
private void MyWindow_SizeChanged(object sender, SizeChangedEventArgs e)
{
if (!allow)
{
MyGrid.RowDefinitions.Add(new RowDefinition());
return;
}
else
//нормальная реализация
}
Такой незамысловатый костыль в WPF
+2
connector* getConnector( int id )
{
autolock_read<lock_rw_t> alr( _lock );
return _getConnector(id);
}
П-потокобезопасность
+2
ХабраКал
//// https://habrahabr.ru/post/279029/
Пыхомакака изобрела орм из 2007
+2
<?php
/*
You can place here your functions and event handlers
AddEventHandler("module", "EventName", "FunctionName");
function FunctionName(params)
{
//code
}
*/
AddEventHandler('form', 'onBeforeResultAdd', 'my_onBeforeResultAdd');
CModule::IncludeModule('cleantalk.antispam');
function my_onBeforeResultAdd($WEB_FORM_ID, $arFields, $arrVALUES) {
$ct_status = COption::GetOptionString('cleantalk.antispam', 'status', '0');
if ($ct_status == 1) {
global $APPLICATION;
$aParams = array();
$aParams['type'] = 'comment';
$aParams['sender_email'] = isset($arrVALUES['email']) ? $arrVALUES['email'] : '';
$aParams['sender_nickname'] = isset($arrVALUES['nickname']) ? $arrVALUES['nickname'] : '';
$aParams['message_title'] = isset($arrVALUES['title']) ? $arrVALUES['title'] : '';
$aParams['message_body'] = isset($arrVALUES['message']) ? $arrVALUES['message'] : '';
$aResult = CleantalkAntispam::CheckAllBefore($aParams, FALSE);
if (isset($aResult) && is_array($aResult)) {
if ($aResult['errno'] == 0) {
if ($aResult['allow'] == 1) {
//Not spammer - just return;
return;
} else {
if (preg_match('//u', $aResult['ct_result_comment'])) {
$err_str=preg_replace('/^[^\*]*?\*\*\*|\*\*\*[^\*]*?$/iu','',$aResult['ct_result_comment']);
$err_str=preg_replace('/<[^<>]*>/iu', '', $err_str);
} else {
$err_str=preg_replace('/^[^\*]*?\*\*\*|\*\*\*[^\*]*?$/i','',$aResult['ct_result_comment']);
$err_str=preg_replace('/<[^<>]*>/i', '', $err_str);
}
$APPLICATION->ThrowException($err_str);
return false;
}
}
}
}
}
?>
Четкая конторка написала четкий антиспам-модуль для битрикса и показывает как его нужно использовать. Тут все в одном флаконе - от игнорирования всех стандартов PSR разом до иррациональной реализации ... Пост на хабре: https://habrahabr.ru/company/cleantalk/blog/302800/
+2
public function is_isset($key)