- 1
- 2
- 3
update sometable
set value2=convert(char(100), @int_variable+convert(int,value2))
where someconditions
Нашли или выдавили из себя код, который нельзя назвать нормальным, на который без улыбки не взглянешь? Не торопитесь его удалять или рефакторить, — запостите его на говнокод.ру, посмеёмся вместе!
−167
update sometable
set value2=convert(char(100), @int_variable+convert(int,value2))
where someconditions
В цикле колбасится, упростил для понимания.
Мне кажется эту штуку изначально проектировал человек, который работал с bash и sqlite, а потом оппа, и нет слабой типизации.
+9
void drawAAWave(DWORD *image, WAVE *w, int top, int left,
int width, int height, int offsetPx)
{
int thd2 = top + height/2;
float hm2 = this->height - 2;
int x = 0, xc = 0, yc = 0;
float mul = amplify;
if (invert) mul = -mul;
if (x*scale + offsetPx*scale > w->length) return;
float yFrom = (thd2 - w->data[offsetPx*scale]*mul);
if (yFrom < 2.0f) yFrom = 2.0f;
if (yFrom > hm2) yFrom = hm2;
float yTo, dist, delta, sdelta, alpha, lc;
int yMin, yMax, xcl, n;
for ( ; x < width-1 && (x+offsetPx)*scale < w->length; x++)
{
yTo = thd2 - w->data[(x + offsetPx)*scale]*mul;
if (yTo < 2) yTo = 2; if (yTo > hm2) yTo = hm2;
delta = yTo - yFrom;
sdelta = 1.0f / sqrtf(1.0f + delta*delta);
lc = ((x + 0.5f)*yTo - (x + 1.5f)*yFrom) + 0.5f;
yMin = (int)(min(yFrom, yTo)) - 1;
yMax = (int)(max(yFrom, yTo)) + 1;
xcl = x;
if (delta > 1.0f || delta < -1.0f) xcl++;
for (xc = x; xc <= xcl; xc++)
for (yc = yMin; yc <= yMax; yc++)
{
dist = ((-delta)*(xc + 0.5f) + yc + lc)*sdelta;
alpha = 1.0f - fabs(dist*0.8f);
if (alpha < 0.0f) alpha = 0.0f;
n = maxWidth*yc + xc;
image[n] = clrBlend(image[n], lineColor, alpha);
}
yFrom = yTo;
}
}
Велосипедный метод рисования кривой с антиализингом
+158
public static function checkWriteToTorrentPath($path)
{
if (file_put_contents($path.'file.txt', ' '))
{
unlink($path.'file.txt');
return TRUE;
}
else
return FALSE;
}
is_writable ? Не, не слышал!
https://github.com/ElizarovEugene/TorrentMonitor/blob/master/class/System.class.php#L48 Эпик!
−84
use constant MAX_INT => 4294967295;
Code hard.
P.S. perl -MPOSIX -we 'print INT_MAX'
+134
bool generateEfDbEachRun = false;
bool.TryParse(config.Get("GenerateEFDBEachRun"), out generateEfDbEachRun);
if (generateEfDbEachRun && bool.Parse(config.Get("GenerateEFDBEachRun")))
{
Database.SetInitializer(new SADatabaseInitializer());
}
+136
public double Supremum()
{
HazardEstimation intensityEstimation = new IntensityEstimation(Sample, new EpanechnikovKernel(), SmoothingParameterMethod.Asymptotic);
var s = new List<double>(Sample.Size);
for (int i = 0; i < Sample.Size; i++)
s.Add(Math.Abs(intensityEstimation.NonParametricEstimation(Sample[i].Value) - rv.h(Sample[i].Value)));
return s.Max();
}
Дипломники не ищут легких путей
+152
<html>
<head>
<meta http-equiv='Content-Type' content='text/html; charset=windows-1251'>
<head>
<title>test</title>
<script type="text/javascript">
// Функция, осуществляющая AJAX запрос
function loadXMLDoc(method, url) {
if(window.XMLHttpRequest) {
req = new XMLHttpRequest();
req.onreadystatechange = processReqChange;
req.open(method, url, true);
req.send(null);
} else if (window.ActiveXObject) {
req = new ActiveXObject("Microsoft.XMLHTTP");
req.onreadystatechange = processReqChange;
req.open(method, url, true);
req.send();
}
}
// Функция, выполняемая при изменении статуса
// запроса, если статус равен 200, данные получены
function processReqChange() {
if(req.readyState == 4) {
if(req.status == 200) {
getNumber(req.responseText);
} else {
alert("There was a problem retrieving the XML data:\n" + req.statusText);
}
}
}
// Функция выполняется при клике по кнопке
function process() {
var v = document.getElementById("flag");
var url = "ajax.php?flag=" + v.checked;
loadXMLDoc( "get", url );
setTimeout('process()', 1000);
}
// Функция записывает в элемент content значение, полученное от сервера
function getNumber(text) {
//для текстового поля
var content = document.getElementById( "content" );
content.value = text;
//для div
var content = document.getElementById( "content2" );
content.innerHTML = text;
}
</script>
</head>
<body onload='process()'>
<input type='checkbox' id='flag'>Флажок
<input type='text' id='content'>
<div id='content2'></div>
</body>
</html>
.....................................................................................
//файл ajax.php
<?php
if (isset($_GET['flag']))
{
if($_GET['flag']==='true') echo 'checked';
else echo 'not checked';
}
?>
Как скопировать значение одного поля в другое.
Очередное оригинальное решение от нашего старого знакомого, который не верит в существование говнокода и быдлокодеров.
+153
$_SESSION["db_options"] = array ('host' => trim($this->IP).":".trim($this->Port),
'user' => trim($this->User),
'password' => trim($this->Pass),
'database' => trim($this->DB)
);
Наследование? Не, не слышал
+154
$code_date = strtotime($sms_action_date);
$date = date(
"Y-m-d H:i:s",
mktime(
date('H', $code_date),
date('i', $code_date) + 30,
date('s', $code_date),
date("m", $code_date),
date("d", $code_date),
date("Y", $code_date)
)
);
Определяем +30 минут грамотно.
+74
private boolean userInOneRegistrationNode() throws DfException {
String uname = OrganizationStaffStructureHelper.getCurrentUserName();
int i = 0;
IDfCollection NodesCol = DQLHelper.getCollection(DQL_GET_REGISTRATOR_DIV, new String[]{uname});
while (NodesCol.next()) {
if (!(NodesCol == null)) {
String group_name = NodesCol.getString(GROUP_NAME);
i = i + 1;
}
}
if (i == 1) {
return true;
}
return false;
}
Заменяется 2мя строками один - select count(*), вторая - полученный результат Integer.ValueOf(...).