- 1
- 2
@Mock
QueryParser queryParserMock = mock(QueryParser.class);
Нашли или выдавили из себя код, который нельзя назвать нормальным, на который без улыбки не взглянешь? Не торопитесь его удалять или рефакторить, — запостите его на говнокод.ру, посмеёмся вместе!
0
@Mock
QueryParser queryParserMock = mock(QueryParser.class);
Для надежности
+1
<?php
$img = imagecreatefromgif('http://web.archive.org/web/20070419044913im_/upyachka.ru/img/kot/16.gif');
$w = imagesx($img);
$h = imagesy($img);
$symbols = array(' ', '▀', '▄', '█');
for($y = 0; $y < floor($w/2); ++$y) {
for($x = 0; $x < $w; ++$x) {
$color1 = imagecolorat($img, $x, 2*$y);
$color2 = imagecolorat($img, $x, 2*$y+1);
$bit1 = intval(($color1 & 0xff) > 0x80);
$bit2 = intval(($color2 & 0xff) > 0x80);
echo $symbols[$bit1 + ($bit2 << 1)];
}
echo PHP_EOL;
}
+3
/**
* Four state boolean.
*/
enum Bool {
/** */
FALSE,
/** */
TRUE,
/** */
READY,
/** */
DONE
}
0
template<typename T> Histogram<T>& histogram (std::string const& name) {
std::lock_guard<std::mutex> guard(_lock);
auto const it = _registry.find(name);
if (it == _registry.end()) {
LOG_TOPIC("32d85", ERR, Logger::STATISTICS) << "No histogram booked as " << name;
TRI_ASSERT(false);
throw std::exception();
}
std::shared_ptr<Histogram<T>> h = nullptr;
try {
h = std::dynamic_pointer_cast<Histogram<T>>(*it->second);
if (h == nullptr) {
LOG_TOPIC("d2358", ERR, Logger::STATISTICS) << "Failed to retrieve histogram " << name;
}
} catch (std::exception const& e) {
LOG_TOPIC("32d75", ERR, Logger::STATISTICS)
<< "Failed to retrieve histogram " << name << ": " << e.what();
}
if (h == nullptr) {
TRI_ASSERT(false);
}
return *h;
};
0
В УЗБЕКИСТАНЕ ДАН СТАРТ МАСШТАБНОМУ ПРОЕКТУ ONE MILLION UZBEK CODERS
https://uznews.uz/ru/article/17817
Проект представляет собой дистанционное бесплатное обучение населения посредством онлайн-портала по четырем IT-специальностям.
0
from datetime import datetime, timedelta
from dateutil import parser
import os
import pytest
from tests.db_support import psg_db
intake_iot_mapper = [('sourceId', 'DEVICE_ID', str),
('altitude', 'ALTITUDE', int),
('odometer', 'ODOMETER', int),
('battery', 'BATTERY_LEVEL', int),
('speed', 'SPEED', int),
('satCount', 'SAT_COUNT', float),
('gpsQuality', 'GPSQUALITY', float),
('lat', 'LAT', float),
('lon', 'LON', float),
('radius', 'RADIUS', int),
('objectId', 'OBJECT_ID', str),
('direction', 'DIRECTION', int)]
@pytest.fixture(scope='module')
def device_ids():
sql_device = """SELECT
dvc.id,
dvc.source_id device_id,
dvc_m.object_id
FROM iot_platform.iot_device_mecomo dvc_m
JOIN iot_platform.iot_device dvc on dvc.id = dvc_m.id
WHERE dvc_m.object_id is not NULL ORDER BY dvc_m.object_id"""
ids = psg_db(sql=sql_device)
ids_dict = [(row['device_id'], row['id'], row['object_id']) for row in ids]
return ids_dict
@pytest.mark.parametrize('device_id, uuid, object_id', device_ids())
@pytest.mark.parametrize('check_date', [str((datetime.now() - timedelta(days=1)).date())])
def test_telemetry_all(device_id, uuid, object_id, get_intake_data, devices_list, get_iot_data, check_date, expect):
_from = parser.parse(check_date)
_to = _from + timedelta(hours=23, minutes=59, seconds=59)
intake_from = _from.strftime('%Y/%m/%d %H:%M:%S')
intake_to = _to.strftime('%Y/%m/%d %H:%M:%S')
# take wider period from Dymano (+24 hours)
dynamo_from = _from.timestamp()*1000
dynamo_to = (_to + timedelta(hours=24)).timestamp()*1000
xml_file_name = '%s/IntakeRaw/device_telemetry/telemetry_device_%s_%s.xml' % (os.path.dirname(__file__), device_id, _from.date())
# write response data to file if there is no file saved
if not os.path.isfile(xml_file_name):
params = {'objectId': object_id, 'startIndex': 1, 'startDate': intake_from, 'endDate': intake_to}
content = get_intake_data('positions_report', **params)
# create dir, get intake data and write it to the file
os.makedirs(os.path.dirname(xml_file_name), exist_ok=True)
with open(xml_file_name, 'w') as f_xml:
f_xml.write(content.decode('utf-8'))
telemetry_in = devices_list(xml_file_name, 'POSITION')
telemetry_out = get_iot_data(uuid, dynamo_from, dynamo_to, 'telemetry')
# check if IOT data is empty but there are entries in the intake, go no further if this fails
if telemetry_in:
assert telemetry_out, \
'Fail: empty data received for device %s, period %s - %s: Entries count: Intake %s != %s Dynamo DB' \
% (uuid, dynamo_from, dynamo_to, len(telemetry_in), len(telemetry_out))
for pos_id in telemetry_in:
# check if the position id was saved in Dynamo
if pos_id in telemetry_out:
for key_out, key_in, to_type in intake_iot_mapper:
# check if the parameter is in the intake and it is not null
if key_in in telemetry_in[pos_id] and telemetry_in[pos_id][key_in] is not None:
if key_out in telemetry_out[pos_id]:
if key_in in ('LAT', 'LON'):
expect(
to_type(telemetry_out[pos_id]['location'][key_out]) == to_type(float(telemetry_in[pos_id][key_in])),
'Fail: position id %s, %s: in %s != %s out' % (pos_id, key_out, telemetry_in[pos_id][key_in],
telemetry_out[pos_id]['location'][key_out]))
else:
expect(str(telemetry_out[pos_id][key_out]) == telemetry_in[pos_id][key_in],
'Fail: position id %s, %s: in %s != %s out' %
(pos_id, key_out, telemetry_in[pos_id][key_in], telemetry_out[pos_id][key_out]))
else:
expect(key_out in telemetry_out[pos_id],
'Fail: record time %s, device id: %s:%s: %s in %s != None %s out'
% (pos_id, device_id, uuid, key_in, telemetry_in[pos_id][key_in], key_out))
интеграционный тест одной тупой педовки
0
public static long NextTimestamp()
{
if (initTimestamp == null)
{
lock (syncRoot)
{
if (initTimestamp == null)
{
initTimestamp = false;
var sessionProvider = Locator.GetServiceNotNull<ISessionProvider>();
TimestampService.GetTimestamp();
sessionProvider.CloseSession("");
initTimestamp = true;
}
}
}
return initTimestamp.Value ? TimestampService.GetTimestamp() : 0;
}
Нельзя просто взять и вызвать TimestampService.GetTimestamp() - StackOverflowException получишь. Вот как надо!
0
IT Оффтоп #26
#1: https://govnokod.ru/18142 https://govnokod.xyz/_18142
#2: https://govnokod.ru/18378 https://govnokod.xyz/_18378
#3: https://govnokod.ru/19667 https://govnokod.xyz/_19667
#4: https://govnokod.ru/21160 https://govnokod.xyz/_21160
#5: https://govnokod.ru/21772 https://govnokod.xyz/_21772
#6: https://govnokod.ru/24063 (потёр пидор сракер) https://govnokod.xyz/_24063
#7: https://govnokod.ru/24538 https://govnokod.xyz/_24538
#8: https://govnokod.ru/24815 (потёр пидор сракер) https://govnokod.xyz/_24815
#9: https://govnokod.ru/24867 https://govnokod.xyz/_24867
#10: https://govnokod.ru/25328 https://govnokod.xyz/_25328
#11: https://govnokod.xyz/_25436 https://govnokod.ru/25436 (потёр пидор сракер)
#12: https://govnokod.xyz/_25471
#13: https://govnokod.xyz/_25590 (потёр пидор сракер)
#14: https://govnokod.xyz/_25684
#15: https://govnokod.xyz/_25694
#16: https://govnokod.xyz/_25725
#17: https://govnokod.xyz/_25731
#18: https://govnokod.xyz/_25762
#19: https://govnokod.xyz/_25767
#20: https://govnokod.xyz/_25776
#21: https://govnokod.xyz/_25798
#22: https://govnokod.xyz/_25811
#23: https://govnokod.xyz/_25863
#24: https://govnokod.xyz/_25941
#25: https://govnokod.xyz/_26026
+1
Segmentation fault
Я против «неинформативных ошибок».
0
# Если вы желаете ограничить диапазон "снизу",
# то просто производите генерацию псевдослучайных чисел в цикле до тех пор,
# пока не получите число большее нижней границы.
FLOOR=200
number=0 # инициализация
while [ "$number" -le $FLOOR ]
do
number=$RANDOM
done
echo "Случайное число, большее $FLOOR --- $number"
https://www.opennet.ru/docs/RUS/bash_scripting_guide/x4812.html