- 1
#define $(x) [&](void)->auto{try{return (x);}catch(...){return decltype(x){};}}()
Нашли или выдавили из себя код, который нельзя назвать нормальным, на который без улыбки не взглянешь? Не торопитесь его удалять или рефакторить, — запостите его на говнокод.ру, посмеёмся вместе!
0
#define $(x) [&](void)->auto{try{return (x);}catch(...){return decltype(x){};}}()
Собачка
0
/*
xdrv_96_blacklist.ino - Blacklist for Tasmota
SPDX-FileCopyrightText: 2022 Theo Arends
SPDX-License-Identifier: GPL-3.0-only
*/
#define USE_BLACKLIST
#ifdef USE_BLACKLIST
/*********************************************************************************************\
* Blacklist support
*
* Check language and user set latitude/longitude against blacklist table
\*********************************************************************************************/
#define XDRV_96 96
typedef struct {
int16_t latitude_tl; // - 8999 to 8999
int16_t longitude_tl; // -17999 to 17999
int16_t latitude_br;
int16_t longitude_br;
uint16_t lcid;
} tBlArray;
//const char BlacklistText[] PROGMEM = "Stop war - Free Ukrain|Stop war - Free Ukrain|";
const char BlacklistText[] PROGMEM = "Stop war, Free Ukrain";
// lat_tl lon_tl lat_br lon_br lcid
tBlArray BlArray[] { 5900, 3200, 5300, 4400, 1049, // Around Moscow
5450, 2633, 5280, 2900, 1049 // Around Minsk
};
uint8_t blist_show = 0;
void BListEverySecond(void) {
if (Rtc.utc_time < 1648771200) { // Only until 2022-04-01
if (0 == (TasmotaGlobal.uptime % 20)) { // Only every 20 seconds
if (TasmotaGlobal.power) { // Only if any power on
uint32_t latitude = Settings->latitude / 10000;
uint32_t longitude = Settings->longitude / 10000;
uint32_t count = sizeof(BlArray) / sizeof(tBlArray);
for (uint32_t i = 0; i < count; i++) {
// Currently only supports top-right quarter of the earth
if ((LANGUAGE_LCID == BlArray[i].lcid) && // Check language id
(latitude < BlArray[i].latitude_tl) && // Check user set latitude and longitude against table
(latitude > BlArray[i].latitude_br) &&
(longitude > BlArray[i].longitude_tl) &&
(longitude < BlArray[i].longitude_br)) {
// char bl_text[100];
// snprintf_P(bl_text, sizeof(bl_text), PSTR("Power0 0")); // Turn all power off - annoying
// snprintf_P(bl_text, sizeof(bl_text), PSTR("Restart 1")); // Restart - more annoying
// snprintf_P(bl_text, sizeof(bl_text), PSTR("Reset 1")); // Reset - disastrous
// ExecuteCommand(bl_text, SRC_IGNORE);
// char bl_text[100];
// AddLog(LOG_LEVEL_NONE, PSTR("**** %s ****"), GetTextIndexed(bl_text, sizeof(bl_text), i, BlacklistText));
AddLog(LOG_LEVEL_NONE, PSTR("**** %s ****"), BlacklistText);
blist_show = i +1; // Set GUI message id
break;
}
}
}
} else if (0 == (TasmotaGlobal.uptime % 10)) { // Only every 10 seconds
blist_show = 0; // Reset GUI message id after 10 seconds
}
}
}
void BListShow(bool json) {
if (blist_show) {
// char bl_text[100];
// WSContentSend_PD(PSTR("{s}**** %s ****{m}{e}"), GetTextIndexed(bl_text, sizeof(bl_text), blist_show -1, BlacklistText));
WSContentSend_P(PSTR("{s}**** %s ****{m}{e}"), BlacklistText);
}
}
/*********************************************************************************************\
* Interface
\*********************************************************************************************/
bool Xdrv96(uint8_t function) {
bool result = false;
switch (function) {
case FUNC_EVERY_SECOND:
BListEverySecond();
break;
#ifdef USE_WEBSERVER
case FUNC_WEB_SENSOR:
BListShow(0);
break;
#endif // USE_WEBSERVER
}
return result;
}
https://github.com/arendst/Tasmota/commit/98cbf2587a1a914bbd16996ebb48dd451d3da448
+1
stop() {
PIDS=$(/sbin/pidof $PNAME)
CNT=0
if [[ $PIDS != "" ]]; then
echo -n "Stopping $PNAME: "
killall $PNAME && echo "ok" || echo "failed"
while [[ $PIDS != "" ]]
do
PIDS=$(/sbin/pidof $PNAME)
echo -n "."
sleep 1
CNT=$(($CNT+1))
if [[ $CNT -eq 3 ]]; then killall -9 $PNAME;echo -e "\n$PNAME: Force kill";break; fi
done
echo
else echo "$PNAME: don't start"
fi
}
Так автор видел выключение процесса. Процесс работает с файлами на жестком диске и ему важна их целостность, поэтому за 3 секунды не завершался. А еще при gracefully shutdown пишется обновление конфига процесса на диск. Но кого волнуют такие мелочи если оно уже работает в проде 7+ лет
0
function main() {
print("testArrayFoEach");
[1, 2, 3].forEach(x => print(x))
print("done.");
}
вот... проимплементил ненужную никому хрень :) чето я устал дампики постить.. и так поймете все что надо :)
+4
function H2I takes handle h returns integer
return h
return 0
endfunction
Return Bug. Интересно, кто-то ещё помнит?
+2
- null, null, null, null, null, null, null, null, null, null, null, null, null, null))
+ null, null, null, null, null, null, null, null, null, null, null, null, null, null, null))
Это реальный коммит с работы
(не мой, я к jawa не притрагиваюсь)
−1
template distance(b1, b2: AstronomicalBody): float64 = dist(b1.pos, b2.pos)
proc attractionForce(body_1, body_2: AstronomicalBody): DVec3 =
let r = distance(body_1, body_2)
let module = (body_1.m * body_2.m) / (r.pow(2))
return normalize(body_2.pos - body_1.pos) * module
proc updateForce(body: var AstronomicalBody, bodies: seq[AstronomicalBody]) =
body.F = dvec3(0, 0, 0)
for other_body in bodies:
if other_body != body:
body.F += attractionForce(body, other_body)
template acceleration(body: AstronomicalBody): float64 = body.F / body.m
template updateAcceleration(body: var AstronomicalBody) = body.a = acceleration(body)
template velocity(body: AstronomicalBody, dt: float64) = body.V + body.F.normalize * body.a * dt
template updateVelocity(body: var AstronomicalBody, dt: float64) = body.V = velocity(body, dt)
template updatePosition(body: var AstronomicalBody, dt: float64) = body.pos += (body.V * dt)
proc updateProperties(body: var AstronomicalBody, bodies: seq[AstronomicalBody], dt: float64) =
body.updateForce(bodies)
body.updateAcceleration()
body.updateVelocity(dt)
body.updatePosition(dt)
Как же "Nim" хорош, как же "Nim" красив, изящен и элегантен!
+1
#include <string>
#include <type_traits>
#include <iostream>
template<int N> struct tag {};
template<typename T, int N>
struct loophole_t
{
friend auto loophole(tag<N>) { return T{}; };
};
#define BA(c) auto loophole(tag< (c) >);
#define Cb(c) BA(c) BA(c+1) BA(c+2) BA(c+3) BA(c+4)
#define KA(c) Cb(c) Cb(c+5) Cb(c+10) Cb(c+15) Cb(c+20)
#define ZDES(c) KA(c) KA(c+20) KA(c+40) KA(c+60) KA(c+80)
#define BACbKAZDES ZDES(0) ZDES(80) ZDES(160) ZDES(240) ZDES(300)
BACbKAZDES
template<int I>
struct wrp
{
int a;
};
int main(void)
{
sizeof(loophole_t<wrp<67>, 0>);
sizeof(loophole_t<wrp<66>, 1>);
sizeof(loophole_t<wrp<68>, 2>);
sizeof(loophole_t<wrp<99>, 3>);
sizeof(loophole_t<wrp<76>, 4>);
sizeof(loophole_t<wrp<66>, 5>);
sizeof(loophole_t<wrp<33>, 6>);
sizeof(loophole_t<wrp<73>, 7>);
sizeof(loophole_t<wrp<66>, 8>);
sizeof(loophole_t<wrp<68>, 9>);
sizeof(loophole_t<wrp<85>, 10>);
sizeof(loophole_t<wrp<70>, 11>);
sizeof(loophole_t<wrp<79>, 12>);
sizeof(loophole_t<wrp<99>, 13>);
sizeof(loophole_t<wrp<76>, 14>);
sizeof(loophole_t<wrp<66>, 15>);
sizeof(loophole_t<wrp<33>, 16>);
sizeof(loophole_t<wrp<109>, 17>);
sizeof(loophole_t<wrp<112>, 18>);
sizeof(loophole_t<wrp<119>, 19>);
sizeof(loophole_t<wrp<102>, 20>);
std::string nactenbka;
#define L(c, i) if(std::is_same< wrp< (c) >, decltype( loophole(tag< (i) >{}) )>::value) nactenbka.push_back((char)( c-1 ) );
#define O(c, i) L(c, i) L(c+1, i) L(c+2, i) L(c+3, i) L(c+4, i)
#define V(c, i) O(c, i) O(c+5, i) O(c+10,i) O(c+15,i) O(c+20,i)
#define E(c, i) V(c, i) V(c+20,i) V(c+40,i) V(c+60,i) V(c+80,i)
#define LOVE(c, i) E(c, i) V(c+80, i) V(c+100, i)
#define FORE(i) LOVE(0, i)
#define VER(i) FORE(i) FORE(i+1) FORE(i+2) FORE(i+3) FORE(i+4)
#define FOREVER VER(0) VER(5) VER(10) VER(15) FORE(20)
FOREVER
std::cout << nactenbka << std::endl;
return 0;
}
<3
+2
uint16_t Mnemonic::describeMnemonics(void) const
{
uint16_t result = 0;
size_t i = 0;
for (auto&& m : mnemonics)
result += m.index() << i++ * 4;
return result;
}
...
switch(mnemonic.describeMnemonics())
{
case constructDescription(REGISTER, REGISTER):
{
...
}
break;
case constructDescription(REGISTER, CONSTANT):
{
...
}
break;
case constructDescription(REGISTER, LABEL):
{
...
}
break;
case constructDescription(REGISTER, INDIRECT_ADDRESS):
{
...
}
break;
case constructDescription(INDIRECT_ADDRESS, REGISTER):
{
...
}
break;
default:
break;
}
спасибо папочка за паттерн матчинг
0
private List<OutputData> AddSomeSpecialStateToFoo(
List<OutputData> foos,
IDictionary<Guid, SomeSpecialState> fooStates)
{
foreach(var foo in foos)
{
foo .State = fooStates.FirstOrDefault(x => x.Key == cam.FooId).Value;
}
return foos;
}
Митируем листы и юзаем словарь правильно.