- 1
- 2
- 3
- 4
- 5
ТекЧас = Строка(Час(Дата2));
ТекЧас = Прав("00" + ТекЧас, 2);
ТекМин = Строка(Минута(Дата2));
ТекМин = Прав("00" + ТекМин, 2);
ТекВремя = ТекЧас + ":" + ТекМин;
Нашли или выдавили из себя код, который нельзя назвать нормальным, на который без улыбки не взглянешь? Не торопитесь его удалять или рефакторить, — запостите его на говнокод.ру, посмеёмся вместе!
+2
ТекЧас = Строка(Час(Дата2));
ТекЧас = Прав("00" + ТекЧас, 2);
ТекМин = Строка(Минута(Дата2));
ТекМин = Прав("00" + ТекМин, 2);
ТекВремя = ТекЧас + ":" + ТекМин;
Это способ получить время в формате "чч:мм" из даты и времени (переменная Дата2).
Заменяется этим:
ТекВремя = Формат(Дата2, "ДФ=hh:mm");
+2
private boolean checkRule(SchedulerPlanedTaskRuleBase rule, Date nowDate)
{
boolean result = (null != rule) && rule.isExecutionPlaned(nowDate, _lastExecutionDate);
if (result)
{
//Проверка, выполнялось ли уже это действие в эту минуту. Таймер настроен на 30 сек, поэтому эта задача может запускаться 2 раза в минуту.
//Этого нельзя допустить. Если разница между текущим временем и временем последнего запуска этой задачи меньше 2х минут - задача не запускается
if (_lastExecutionDate != null)
{
Calendar lastTime = DateUtils.createCalendar(_lastExecutionDate);
Calendar nowTime = DateUtils.createCalendar(nowDate);
if (Math.abs(nowTime.getTimeInMillis() - lastTime.getTimeInMillis()) < 120000)
return false;
}
}
return result;
}
+2
https://youtu.be/ITupdZ4TmkI?t=96
+2
internal class DeviceState
{
internal string PrimaryState { get; private set; }
private HashSet<string> _multiplieStates;
// много кода...
internal string[] GetStates()
{
string states = PrimaryState;
if (_multiplieStates.Count > 0)
{
states += '|' + string.Join("|", _multiplieStates);
};
return states.Split('|');
}
}
+2
from itertools import groupby
In [31]: [list(g) for k, g in groupby('AAAABBBCCDAABBB')]
Out[31]:
[['A', 'A', 'A', 'A'],
['B', 'B', 'B'],
['C', 'C'],
['D'],
['A', 'A'],
['B', 'B', 'B']]
In [30]: [list(g) for k, g in list(groupby('AAAABBBCCDAABBB'))]
Out[30]: [[], ['B'], [], [], [], []]
ЧЗХ?
+2
https://github.com/klacke/yaws/blob/ba31d14a24842e047e7fa856257df6e3f994ac96/src/yaws_api.erl#L2596
Сертификат сменился? А давайте пол-ноды ёбнем
+2
//macrolib.h
#ifndef MACRO_LIB
#define MACRO_LIB
#include <stdio.h>
typedef void proc(void);
#ifdef DEBUG
#define TRACE printf
#else
#define TRACE(...)
#endif
#ifdef TRACE_CALLS
#define ON_ENTER_TRACE(name) char __CUR_FUNC_NAME__[] = #name; TRACE("<entering %s>", __CUR_FUNC_NAME__);
#define ON_EXIT_TRACE(...) TRACE(__VA_ARGS__)
#else
#define ON_ENTER_TRACE(name) ;
#define ON_EXIT_TRACE(...)
#endif
#define def(type, name, ...) type name __VA_ARGS__ { ON_ENTER_TRACE(name)
#define ret(ret_val) {ON_EXIT_TRACE("<leaving %s>", __CUR_FUNC_NAME__); return ret_val;}
#define end(ret_val) ret(ret_val);}
#define with(type, x, on_exit) { type __CUR_WITH_VAR__ = x; int (*__ON_EXIT__)() = (int(*)())on_exit;
#define endwith __ON_EXIT__(__CUR_WITH_VAR__);}
#define dup(d, ...) __VA_ARGS__ d __VA_ARGS__
#define dupwithcomma(...) __VA_ARGS__, __VA_ARGS__
#endif
//chain.h
#ifdef I0
#undef I0
#if defined(I1) || defined(I2) || defined(I3)
ELEMENT DELIMETER
#include "chain.h"
#else
ELEMENT
#undef ELEMENT
#undef DELIMETER
#endif
#else
#ifdef I1
#undef I1
#define I0
ELEMENT DELIMETER
#include "chain.h"
#else
#ifdef I2
#undef I2
#define I1
#define I0
ELEMENT DELIMETER
#include "chain.h"
#else
#ifdef I3
#undef I3
#define I2
#define I1
#define I0
ELEMENT DELIMETER
#include "chain.h"
#endif
#endif
#endif
#endif
//test.c
#define DEBUG
#define TRACE_CALLS
#include "macrolib.h"
def(int, main, ())
printf(dup(" ", "%s"), dupwithcomma("Чот мне понравилось макроёбить..."));
FILE *f = fopen("file", "w");
with(FILE*, f, fclose)
fputs(
#define ELEMENT "o"
#define DELIMETER "l"
#define I3
#define I2
#define I1
#define I0
#include "chain.h"
, f
);
endwith
end(0)
Мне понравилось. то ещё можно намакроёбить? ;D
+2
#include <stdio.h>
#ifdef DEBUG
#define TRACE printf
#else
#define TRACE(...)
#endif
#define DEF(type, name, ...) type name __VA_ARGS__ { TRACE("<вызвали " #name ">");
#define RET(name, ret_val) {TRACE("<" #name " не упала>"); return (ret_val);}
#define END(name, ret_val) RET(name, ret_val);}
DEF(int, main, (int argc, char **argv))
puts("Моя супер-мего отладка ;D");
END(main, 0)
Моя супир-мего отладка ;D
+2
#include <stdio.h>
#include <stdlib.h>
#include <stdalign.h>
#include <inttypes.h>
#include <string.h>
float sum_f(const float arr[], const size_t len);
int32_t sum_i32t(const int32_t arr[], const size_t len);
#define sum(a, b) _Generic((a), float*: sum_f, \
const float*: sum_f, \
int32_t*: sum_i32t,\
const int32_t*: sum_i32t)(a, b)
// foldl (+) 0 arr
float sum_f(const float arr[], const size_t len)
{
return (len != 0) ? ( sum(arr+1, len-1) + arr[0] ) : 0;
}
int32_t sum_i32t(const int32_t arr[], const size_t len)
{
return (len != 0) ? ( sum(arr+1, len-1) + arr[0] ) : 0;
}
enum { we_want_int, we_want_float } what_we_want;
void test(int www)
{
void *a;
if (www == we_want_int)
{
uint8_t buf[sizeof(int32_t[10])] __attribute__ ((aligned (alignof(int32_t[10]))));
a = (void *) buf;
memcpy ( a, (int32_t[10]){1,2,3,4,5,6,7,8,9,10},
sizeof((int32_t[10]){1,2,3,4,5,6,7,8,9,10})
);
printf("%" PRIi32 "\n", sum((int32_t *)a, 10));
}
else if (www == we_want_float)
{
uint8_t buf[sizeof(float[10])] __attribute__ ((aligned (alignof(float[10]))));
a = (void *) buf;
memcpy ( a, (float[10]){1,2,3,4,5,6,7,8,9,10},
sizeof((float[10]){1,2,3,4,5,6,7,8,9,10})
);
printf("%f\n", sum((float *)a, 10));
}
}
int main(void)
{
test(we_want_int);
test(we_want_float);
return EXIT_SUCCESS;
}
https://wandbox.org/permlink/TwbKHE8l7ZJc6PNI
https://govnokod.ru/25005#comment436646
https://i.imgur.com/yFYfuED.jpg
+2
<?php
define('+1', 16384);
${'*.'} = function ($a, $b) {
return floor($a * $b / constant('+1'));
};
${'/.'} = function ($a, $b) {
return floor($a * constant('+1') / $b);
};
echo ${'/.'}(1, 1) . "\n";
echo ${'/.'}(1, 2) . "\n";
echo ${'/.'}(7, 34) + ${'/.'}(23, 99) . "\n";
Где-то за кулисами прячется факт, что в "PHP" в качестве имён констант и переменных можно использовать произвольные строки.
https://ideone.com/3MCnCW