- 1
- 2
- 3
- 4
- 5
- 6
- 7
- 8
list<int> l;
//...
for(int i=0;i<l.size();++i)
{
auto it=l.begin();
advance(it, i);
int item=*it;
//...
Нашли или выдавили из себя код, который нельзя назвать нормальным, на который без улыбки не взглянешь? Не торопитесь его удалять или рефакторить, — запостите его на говнокод.ру, посмеёмся вместе!
+997
list<int> l;
//...
for(int i=0;i<l.size();++i)
{
auto it=l.begin();
advance(it, i);
int item=*it;
//...
+82
/**
* метод возвращает int-овое смещение тайм-зоны
*/
public long getIntOffset() {
if (timeZone == null) {
return 0;
}
return timeZone.getOffset(System.currentTimeMillis());
Calendar now = Calendar.getInstance();
int millisPerDay =
now.get(Calendar.HOUR) * ONE_HOUR +
now.get(Calendar.MINUTE) * ONE_MINUTE +
now.get(Calendar.SECOND) * ONE_SECOND;
int offset = timeZone.getOffset(
now.get(Calendar.ERA),
now.get(Calendar.YEAR),
now.get(Calendar.MONTH),
now.get(Calendar.DAY_OF_MONTH),
now.get(Calendar.DAY_OF_WEEK),
millisPerDay
);
int diff = now.get(Calendar.ZONE_OFFSET);
boolean isNegative = (offset < 0);
long intOffset = Math.abs(offset) - Math.abs(diff);
//todo здесь наверное как-то по-лучше можно выделить часы
SimpleDateFormat sdf = new SimpleDateFormat("HH:mm");
String time = sdf.format(new Date(intOffset));
Date d;
try {
d = sdf.parse(time);
} catch (ParseException e) {
d=null;
}
if (d!=null)
return (isNegative?-1:1) * d.getHours()*3600000;
else
return 0;
}
Этот "шедевр" был написан не индусами, а суровыми программистами Новосиба ;) Это чудо долго работало, вплоть до обновления tzdata на 2011. Придется удалить, а жаль...
+181
void MultipleSquareMatrix(Matrix*rres, Matrix*mul1, Matrix* mul2)
{
int N = mul1->height();
Matrix rmul1(N,N);
Matrix rmul2(N,N);
#define SM (CLS / sizeof (double))
for (i = 0; i < N; i += SM)
for (j = 0; j < N; j += SM)
for (k = 0; k < N; k += SM)
for (i2 = 0, rres = &res[i][j],
rmul1 = &mul1[i][k]; i2 < SM;
++i2, rres += N, rmul1 += N)
for (k2 = 0, rmul2 = &mul2[k][j];
k2 < SM; ++k2, rmul2 += N)
for (j2 = 0; j2 < SM; ++j2)
rres[j2] += rmul1[k2] * rmul2[j2];
}
Перемножение квадратных матриц.....
+135
#include <stdio.h>
#include <stdlib.h>
int main()
{
static int val = 1;
while(val /* vanish */ --> 0)
{
(++ /* do black magic ! */ val) /* very black magic !!! */ ++;
(val == 2 ? printf("WTF ??!") : val =- 1);
}
if(val<-15)
return ((1<0?/* magic */100500:500?233?33?321?2223?0:0:0:0:0:0));
return ((!!val==!!false)?val ==- 100500?5:1:main());
}
Из разряда синтаксиса языка
+2
union bitdata {
struct {
unsigned int bit1 : 1;
unsigned int bit2 : 1;
unsigned int bit3 : 1;
unsigned int bit4 : 1;
unsigned int bit5 : 1;
unsigned int bit6 : 1;
unsigned int bit7 : 1;
unsigned int bit8 : 1;
};
unsigned char byte;
} first_byte, second_byte;
<...>
for ( j = 0; j < bytes_count; j++ ) {
unsigned char t;
ret = gzread( gz_fd, &t, sizeof( t ) );
if ( ret != sizeof( t ) ) {
printf( "Failed to read file %s: %s\n", argv[i], strerror( errno ) );
gzclose( gz_fd );
return EXIT_FAILURE;
}
first_byte.byte = t;
second_byte.byte = ready_bytes[j];
first_byte.bit1 = first_byte.bit1 == 0 && second_byte.bit1 == 0 ? 0 : 1;
first_byte.bit2 = first_byte.bit2 == 0 && second_byte.bit2 == 0 ? 0 : 1;
first_byte.bit3 = first_byte.bit3 == 0 && second_byte.bit3 == 0 ? 0 : 1;
first_byte.bit4 = first_byte.bit4 == 0 && second_byte.bit4 == 0 ? 0 : 1;
first_byte.bit5 = first_byte.bit5 == 0 && second_byte.bit5 == 0 ? 0 : 1;
first_byte.bit6 = first_byte.bit6 == 0 && second_byte.bit6 == 0 ? 0 : 1;
first_byte.bit7 = first_byte.bit7 == 0 && second_byte.bit7 == 0 ? 0 : 1;
first_byte.bit8 = first_byte.bit8 == 0 && second_byte.bit8 == 0 ? 0 : 1;
ready_bytes[j] = first_byte.byte;
}
Всё еще не можем понять, зачем в конце тернарник. Всё остальное уже не смущает.
0
auto DivisibleBy = [](int d)
{
return [d](int m) { return m % d == 0; };
};
if (ranges::any_of(v, DivisibleBy(7))) {
std::cout << "At least one number is divisible by 7\n";
}
https://en.cppreference.com/w/cpp/algorithm/ranges/all_any_none_of
0
function isNumeric(str) //for non-numeric fields
{
var FlagS=0, FlagN=0;
var str1=new Array();
for(var i=0;i<str.length;i++) //convert string to a char array
{
str1[i]=str.charAt(i);
}
for(i=0;i<str1.length;i++) //check for digits
{
if(str1[i]>='0'&&str1[i]<='9' )
{
FlagN=1;
}
}
if(FlagS==1||FlagN==1) //give a final decision
{
FlagS=FlagN=0;
return true;
}
}
Красота по-индийски. FlagS не понадобился, ну и хер с ним :)
0
public function addMoney($name, $amount, $type)
{
$checkExist = $this->checkUserMoney($name);
$checkExist = ($checkExist != '<b>(Ico)</b> <h11 style=\"color: red\">Произошла ошибка!</h11> <br/>') ? true : false;
$name_uuid = $this->genUUID($name);
if ($this->version == '1.12.2' AND $this->plugin != 'iconomy')
{
if ($checkExist)
{
if ($type == 'add')
{
$queryText = ($this->plugin == 'economylite') ? "UPDATE `economyliteplayers` SET `balance` = `balance` + '$amount' WHERE `uuid` = '$name_uuid' AND `currency` = 'economylite:coin'"
: "UPDATE `{$this->table}` SET `money` = `money` + '$amount' WHERE `player_name` = '$name'";
} else
{
$queryText = ($this->plugin == 'economylite') ? "UPDATE `economyliteplayers` SET `balance` = '$amount' WHERE `uuid` = '$name_uuid' AND `currency` = 'economylite:coin'"
: "UPDATE `{$this->table}` SET `money` = '$amount' WHERE `player_name` = '$name'";
}
} else
{
$queryText = ($this->plugin == 'economylite') ? "INSERT INTO `economyliteplayers` (`uuid`, `balance`, `currency`) VALUES ('$name_uuid', '$amount', 'economylite:coin')"
: "INSERT INTO `{$this->table}` (`player_uuid`, `player_name`, `money`, `sync_complete`, `last_seen`) VALUES ('$name_uuid', '$name', '$amount', 'true', '0')";
}
} else
{
if ($checkExist)
{
$queryText = ($type == 'add') ? "UPDATE `{$this->table}` SET `balance` = `balance` + $amount WHERE `username` = '$name'"
: "UPDATE `{$this->table}` SET `balance` = $amount WHERE `username` = '$name'";
} else
{
$queryText = "INSERT INTO `{$this->table}` (`username`, `balance`) VALUES ('$name', $amount)";
}
}
echo $queryText;
$data = siteQuery($queryText, 'query', $this->mysqli);
$text = ($data != NULL) ? "<b>(Ico)</b> <h11 style=\"color: green\">Игроку $name успешно начисленно: $amount эмеральдов!</h11> <br/>"
: '<b>(Ico)</b> <h11 style="color: red">Произошла ошибка!</h11> <br/>';
return $text;
}
public function checkUserMoney($name)
{
$name_uuid = $this->genUUID($name);
if ($this->version == '1.12.2' AND $this->plugin != 'iconomy')
{
$queryText = ($this->plugin == 'economylite') ? "SELECT `balance` FROM `economyliteplayers` WHERE `uuid` = '{$name_uuid}' AND `currency` = 'economylite:coin'"
: "SELECT `money` as 'balance' FROM `{$this->table}` WHERE `player_name` = '{$name}'";
} else
{
$queryText = "SELECT `balance` FROM `{$this->table}` WHERE `username` = '{$name}'";
}
$data = siteQuery($queryText, 'assoc', $this->mysqli);
$text = ($data != NULL) ? "<b>(Ico)</b> <h11 style=\"color: green\">Балланс игрока $name: {$data['balance']} эмеральдов!</h11> <br/>"
: '<b>(Ico)</b> <h11 style=\"color: red\">Произошла ошибка!</h11> <br/>';
return $text;
}
Этот говнокод кодил наш сотрудник https://vk.com/valiev_off, здесь вы можете наблюдать мастерские SQL запросы под тернарным соусом
0
<?php declare(strict_types=1);
/**
* This file is part of Swoft.
*
* @link https://swoft.org
* @document https://swoft.org/docs
* @contact [email protected]
* @license https://github.com/swoft-cloud/swoft/blob/master/LICENSE
*/
namespace Database;
use Swoft;
use Swoft\SwoftComponent;
/**
* Class AutoLoader
*
* @since 2.0
*/
class AutoLoader extends SwoftComponent
{
/**
* Class constructor.
*/
public function __construct()
{
parent::__construct();
Swoft::setAlias('@database', dirname(__DIR__) . '/database');
}
/**
* @return array
*/
public function getPrefixDirs(): array
{
return [
__NAMESPACE__ => __DIR__,
];
}
/**
* @return array
*/
public function metadata(): array
{
return [];
}
}
https://github.com/swoft-cloud/swoft/blob/master/database/AutoLoader.php
−9
BOOL ShaderElement::equal(ShaderElement* S)
{
if (nullptr == S && nullptr == this)
return TRUE;
if (nullptr == S || nullptr == this)
return FALSE;
return equal(*S);
}
https://www.linux.org.ru/forum/development/14512625