- 1
- 2
- 3
- 4
- 5
- 6
function getMinQueueOrdering()
{
$sql="SELECT MAX(ordering)
FROM priceloaddata_queue";
.........
}
Нашли или выдавили из себя код, который нельзя назвать нормальным, на который без улыбки не взглянешь? Не торопитесь его удалять или рефакторить, — запостите его на говнокод.ру, посмеёмся вместе!
+157
function getMinQueueOrdering()
{
$sql="SELECT MAX(ordering)
FROM priceloaddata_queue";
.........
}
нет слов.
+64
import java.util.HashMap;
import java.util.Map;
import java.util.StringTokenizer;
public class PolynomialParser {
public Polynomial parse(String rawPolynomial) {
String source = normalizeSourceString(rawPolynomial);
Map<Integer, Integer> result = new HashMap<>();
StringTokenizer tokenizer = new StringTokenizer(source, "[+-]", true);
boolean isCurrentNegative = false;
int currentDegree;
int currentCoefficient;
while (tokenizer.hasMoreTokens()) {
String currentToken = tokenizer.nextToken();
if ("-".equals(currentToken)) {
isCurrentNegative = true;
} else if ("+".equals(currentToken)) {
isCurrentNegative = false;
} else {
if (currentToken.contains("x")) {
if (currentToken.contains("^")) {
String[] tmp = currentToken.split("x\\^");
currentDegree = Integer.parseInt(tmp[1]);
int draftCoefficient = Integer.parseInt(tmp[0]);
currentCoefficient = (isCurrentNegative) ? - draftCoefficient : draftCoefficient;
} else {
currentDegree = 1;
String[] tmp = currentToken.split("x");
int draftCoefficient = (tmp.length == 0) ? 1 : Integer.parseInt(tmp[0]);
currentCoefficient = (isCurrentNegative) ? - draftCoefficient : draftCoefficient;
}
} else {
currentDegree = 0;
int draftCoefficient = Integer.parseInt(currentToken);
currentCoefficient = (isCurrentNegative) ? - draftCoefficient : draftCoefficient;
}
result.put(currentDegree, currentCoefficient);
}
}
return new Polynomial(result);
}
private String normalizeSourceString(String source) {
String result = source.replaceAll("\\s+","");
return result.toLowerCase();
}
}
Из сегодняшнего. Парсинг многочленов.
+158
// classes.php
return [
'yii\base\Action' => YII2_PATH . '/base/Action.php',
'yii\base\ActionEvent' => YII2_PATH . '/base/ActionEvent.php',
'yii\base\ActionFilter' => YII2_PATH . '/base/ActionFilter.php',
// еще порядка трех сотен классов
];
https://github.com/yiisoft/yii2/blob/d2b864da84a68d56a96709479af78d203f050451/framework/classes.php
осень 2014, использующий composer модный фреймворк, "requires PHP 5.4 and embraces the best practices and protocols found in modern Web application development", и, конечно, ебаный стыд.
+84
List selection = new ArrayList((s != null) ? s : new ArrayList());
Больше мусора для бога сборщика мусора!
+86
const n=10;
type
xfl = record x: double; fl: longint; end;
ar_xfl = array[1..2*n] of xfl;
var
i: longint;
x,y,r: double;
a: ar_xfl;
f: text;
procedure qsort(var a: ar_xfl; lo,hi: longint);
procedure sort(l,r: longint);
var
i,j,k: longint;
tmp: xfl;
begin
i:=l;
j:=r;
k:=(l+r) div 2;
repeat
while a[i].x<a[k].x do inc(i);
while a[k].x<a[j].x do dec(j);
if i<=j then
begin
tmp:=a[i];
a[i]:=a[j];
a[j]:=tmp;
inc(i);
dec(j);
end;
until i>j;
if l<j then sort(l,j);
if i<r then sort(i,r);
end;
begin
sort(lo,hi);
end;
За такие названия переменных надо руки завязывать узлом. Да и помимо этого..
+58
MainWindow::~MainWindow()
{
delete ui;
}
struct t_point {
int i,j;
};
#define stack_len 50000000
long int head, tail;
t_point *steck;
// long int take_border( short int*arr, int h1, int w1, int deep ){
long int take_border( short int*arr, int h1, int w1 ){
long int k=0;
//int i,j,m,n,ii,jj;
int i,j,m,ii,n,jj;
steck = (t_point*) malloc(tail*sizeof(t_point));
if(! steck ){
//ui->teDebug->setText("out of Memory");
return 0;
}
{
QFile file("buffer.dat");
file.open(QIODevice::ReadOnly);
unsigned int size = sizeof(t_point)* tail;
QDataStream in(&file); // we will serialize the data into the file
in.readRawData((char*) steck, size );
}
// <...>
}
Это чувство когда сишник взялся писать на Qt.
+50
#include <deque>
#include <stdint.h>
#include <iterator>
#include <algorithm>
#include <iostream>
#include <iomanip>
using namespace std;
typedef uint32_t bt;
typedef uint64_t dbt;
typedef deque<bt> bn;
#define cat2(b,e) b##e
#define cat(b,e) cat2(b,e)
#define fsi(i,s,e) for(size_t i(s), cat(i,_end)(e); i<cat(i,_end); ++(i))
#define fe(i,c) for(auto i((c).begin()), cat(i,_end)((c).end()); i!=cat(i,_end); ++(i))
void ml10(bn& n){
n.push_front(0);
}
uint32_t ni(const bn& n, size_t i){
if(n.size()<=i)
return 0;
else
return n[i];
}
size_t ms(const bn& n1, const bn& n2){
return (max) (n1.size(), n2.size());
}
bt gr(dbt tr){
return tr & (numeric_limits<bt>::max)();
}
bt gc(dbt tr){
return (tr & (~((dbt)(numeric_limits<bt>::max)()))) >> (numeric_limits<bt>::digits);
}
void pb(bt b1, bt b2, bt lc, bt& r, bt& c){
dbt tr = ((uint64_t)b1 + b2 + lc);
r = gr(tr);
c = gc(tr);
}
void mb(bt b1, bt b2, bt lc, bt& r, bt& c){
dbt tr = ((uint64_t)b1 * b2 + lc);
r = gr(tr);
c = gc(tr);
}
bn /*constexpr*/ bi(bn n){
reverse(n.begin(), n.end());
return n;
}
bn pl(const bn& n1, const bn& n2){
bn r;
bt c=0,br=0;
size_t ms_ = ms(n1, n2);
//r.reserve(ms_+1);
fsi(i,0,ms_){
pb(ni(n1,i),ni(n2,i),c,br,c);
r.push_back(br);
}
if (c)
r.push_back(c);
return r;
}
bn ml(bn n1, const bn& n2){
bn lr, r;
bt c=0;
//r.reserve(n1.size() + n2.size() + 1);
fsi(i2,0,n2.size()){
fsi(i1, 0, n1.size()){
lr.emplace_back();
mb(n1[i1], n2[i2], c, lr[i1], c);
}
if (c){
lr.push_back(c);
c = 0;
}
r = pl(r, lr);
lr.clear();
ml10(n1);
}
return r;
}
#define STR1(x) #x
#define STR(x) STR1(x)
#define EXPECT_TRUE(expr)\
do{\
if(!(expr))\
cout<<"*****Failed test: \"" STR(expr) "\"" << endl;\
else\
cout << "Test OK: \"" STR(expr) "\"" << endl;\
}while(false)
#define TEST(expr)\
do{\
cout << "Test begined: \"" STR(expr) "\"" << endl;\
(void)(expr);\
} while (false)
И вот мой просмотр аниме закончен.
http://ideone.com/eRJ7FA
main смотри в коментах
+155
<?php
$data = file_get_contents("/path/to/photo.jpg"); // Read the file's contents
$name = 'myphoto.jpg';
force_download($name, $data);
Я знаю конечно что это не говнокод, но последствия будут ужасными если не передать сразу же в функцию данные (т.к. PHP будет копировать содержимое дважды), представьте себе файл в 2МБ и много запросов, сервер капут в два раза быстрее.
- https://ellislab.com/codeigniter/user-guide/helpers/download_helper.html
+133
private void gv3_HiddenEditor(object sender, EventArgs e)
{
if (cloneDt != null)
{
cloneDt = null;
}
if (cloneCt != null)
{
cloneCt = null;
}
}
Коллега в скайпе поделился говном из одного коммерческого проекта
+144
public static void main(String[] args) {
int temp = 0;
out: // label
for (int i = 0; i < 3; ++i) {
System.out.println("I am here");
for (int j = 0; j < 20; ++j) {
if(temp==0) {
System.out.println("j: " + j);
if (j == 1) {
temp = j;
continue out; // goto label "out"
}
}
}
}
System.out.println("temp = " + temp);
}
Оригинал: http://stackoverflow.com/questions/2545103/is-there-a-goto-statement-in-java
Помнится, кто-то недавно упомянул именнованные циклы.
Вот они и нашлись.
Получается, что по "continue out" мы пойдём на следующую итерацию внешнего цикла, а при "break out", выйдем из внешнего цикла.
Странно, что M$ не утянули себе такую фичу...