- 1
"(\{\{([#%$])([^:\}]+)(:([^\}]+))?\}\})"
Нашли или выдавили из себя код, который нельзя назвать нормальным, на который без улыбки не взглянешь? Не торопитесь его удалять или рефакторить, — запостите его на говнокод.ру, посмеёмся вместе!
+124
"(\{\{([#%$])([^:\}]+)(:([^\}]+))?\}\})"
Регуляркоговно.
Заменено на
"(\{\{([#%$])(.+?)(:(.+))?\}\})"
+9
HRESULT hr = ReadGenericXMLFile(srcStorage, pagePath, result);
if (hr == S_FALSE) return STG_E_FILENOTFOUND; // File must exist
if (FAILED(hr)) return hr;
Могу понять, обратное, когда вызывающая функция просто возвращает "false" при любом неудачном вызове внутренней функции: нет файла / нет доступа / runtime error и т.д. Здесь же наоборот, при "общем" неудачном вызове внутренней функции возвращается "конкретное" сообщение об ошибке.
+69
protected String getException (final Exception exception) throws IOException
{
final ByteArrayOutputStream bos = new ByteArrayOutputStream ();
try
{
final PrintStream ps = new PrintStream (bos);
exception.printStackTrace (ps);
}
finally
{
bos.close ();
}
return bos.toString ();
}
+17
struct c_log
{
template<typename T> const c_log& operator << (const T& value)
{
//...
}
};
template<> const c_log& c_log::operator << <p_wstr> (const p_wstr& value)
{
fwrite(value, sizeof(wchar_t), wcslen(value), log_file);
return *this;
}
+155
if( $yandexXML==false ){
//...
}
elseif( $yandexXML==true ){
//...
}
не ну а вдруг как бы че
+159
function check_fio() {
var space = /^\s/;
var fio = $("#form_fio").val();
var fio_length = fio.length - 1;
if (fio[fio_length].match(space)) {
fio = fio.substring(0, fio.length - 1);
$("#form_fio").val(fio);
check_fio();
}
}
Казалось бы, удаление пробелов в конце строки, что может быть проще.
−98
try:
while True:
prices.remove(u"")
except ValueError:
pass
Удаление пустых строк из списка.
+142
// main.cpp
#include <stdio.h>
#include <stdlib.h>
//...
#include "tcp.h"
//...
#include "tcp.c"
//...
int main(int argc, char ** argv)
{
//...
receive_tcp_message(sock, &tcp_msg);
switch(tcp_msg.type)
{
#include "cases.h"
default:
break;
}
//...
}
Имелась небольшая утилита, написанная матёрым сишником. Имелся еще меньший шаблонный проект для таких утилит, написанный на плюсах с простым makefile. Таким вот нехитрым способом этот сишник влил первое во второе. Он не пользуется makefile, т.к. обычно пишет шелл-скрипт, собирающий весь проект. А еще он знает кучу анекдотов и историй, выпить не дурак и вообще отличный дядька.
+132
#define max 0x08 //Max number of samples to average/filter
#define byte unsigned char
#define word unsigned int
#define dword unsigned long
#define FILTER 0
#define AVG 1
typedef struct {
word reading[max];
word result[max];
} ResultStct;
static ResultStct x;
static char samp = 0;//filter;
const byte filter_mode = FILTER;
extern int avg_result;
void MYfilter(word input_sample)
{
byte j;
dword X;
x.reading[samp] = input_sample;
if(samp>0){
X=0;
for (j=0;j<=samp;j++){
X += x.reading[j];
}
avg_result = (X >> 3) - 0x0200;
}
// Shift array of results if we hit max
if (samp >= max-1) {
for (j=0;j<max-1;j++){
x.result[j] = x.result[j+1];
x.reading[j] = x.reading[j+1];
}
samp = max-1;
}
else
{
samp++;
} //end if (i => max)
Такой вот МОЩНЕЙШИЙ фильтр встретился в одном проекте.
+120
if (IsSetPrinter)
{
if (Counter == 0)
{
printingIsOkay = PrintDocument(letterIDsString
, row.DocumentTemplateVersionID
, row.DocumentTemplate
, (row.IsHeader_DocumentTemplateVersionIDNull() ? (int?)null : row.Header_DocumentTemplateVersionID)
, (row.IsFooter_DocumentTemplateVersionIDNull() ? (int?)null : row.Footer_DocumentTemplateVersionID)
, true
, Counter
, Counter == documentTemplateVersions.Count - 1);
}
else
{
printingIsOkay = PrintDocument(letterIDsString
, row.DocumentTemplateVersionID
, row.DocumentTemplate
, (row.IsHeader_DocumentTemplateVersionIDNull() ? (int?)null : row.Header_DocumentTemplateVersionID)
, (row.IsFooter_DocumentTemplateVersionIDNull() ? (int?)null : row.Footer_DocumentTemplateVersionID)
, false
, Counter
, Counter == documentTemplateVersions.Count - 1);
}
}
else
{
printingIsOkay = PrintDocument(letterIDsString
, row.DocumentTemplateVersionID
, row.DocumentTemplate
, (row.IsHeader_DocumentTemplateVersionIDNull() ? (int?)null : row.Header_DocumentTemplateVersionID)
, (row.IsFooter_DocumentTemplateVersionIDNull() ? (int?)null : row.Footer_DocumentTemplateVersionID)
, false
, Counter
, Counter == documentTemplateVersions.Count - 1);
}
Я бы выложил весь класс. Он весь такой. Но, думаю, вы поняли кто писал?