- 1
$result = array_filter($paths, fn($v) => in_array($v, $names));
Нашли или выдавили из себя код, который нельзя назвать нормальным, на который без улыбки не взглянешь? Не торопитесь его удалять или рефакторить, — запостите его на говнокод.ру, посмеёмся вместе!
0
$result = array_filter($paths, fn($v) => in_array($v, $names));
В PHP 7.4 войдут стрелочные функции.
https://habr.com/ru/post/450544/
+16
#include <iostream>
using namespace std;
struct T
{
int a, b, &c;
T():a(0), b(1), c(a){cout<<"dc"<<endl;}
T(const T& a):a(a.a), b(a.b), c(&a.c == &a.a ? this->a : b){cout<<"cc"<<endl;}
T& operator=(T a)
{
::new((void*)(&b+1)) int*(&a.c == &a.a ? &this->a : &b);
//asm volatile ("" : : : "memory");
cout<<"co"<<endl;
return *this;
}
void Switch()
{
::new((void*)(&b+1)) int*(&c == &a ? &b : &a);
//asm volatile ("" : : : "memory");
cout<<"sw"<<endl;
}
} __attribute__((aligned(1))) ;
int main() {
T a;
cout<<a.a<<endl;
cout<<a.b<<endl;
cout<<a.c<<endl;
a.Switch();
cout<<a.c<<endl;
T b;
cout<<b.c<<endl;
b=a;
cout<<b.c<<endl;
b.b=666;
cout<<b.c<<endl;
return 0;
}
Очевидно откуда это.
+123
#include <malloc.h>
#include <stdio.h>
#include <string.h>
#include <stdint.h>
typedef struct {
char * begin;
uint64_t size, data_size;
} str_t;
inline uint64_t max(uint64_t a, uint64_t b) {
return (a > b) ? a : b;
}
inline str_t correct_data_size(str_t str, uint64_t new_size) {
if(str.data_size < new_size) {
str.data_size = (max(str.data_size, new_size) << 1);
str.begin = realloc(str.begin, str.data_size);
}
return str;
}
inline str_t concat(str_t dest, str_t src) {
uint64_t new_size = (dest.size + src.size - 1);
dest = correct_data_size(dest, new_size);
memcpy((dest.begin + dest.size - 1), src.begin, src.size);
dest.size = new_size;
return dest;
}
inline str_t create_str(char * str, uint64_t size) {
return (str_t){.begin = strcat(malloc(size), str), .size = size, .data_size = size};
}
inline void print_str_t(str_t str) {
fprintf(stderr, "str = %ssize = %lu, data_size = %lu\n", str.begin, str.size, str.data_size);
}
uint64_t test(uint64_t star_n, uint64_t n, str_t str, str_t * gstr) {
uint64_t end = (star_n + n);
do {
*gstr = concat(*gstr, str);
char * pos = gstr->begin;
while((pos = strstr(pos, "efgh")))
memcpy(pos,"____",4);
} while((++star_n) != end);
return star_n;
}
int main(void) {
char data[] = "abcdefghefghefgh";
str_t str = create_str(data, sizeof(data));
str_t gstr = create_str("", 1);
time_t starttime = time(NULL);
uint64_t block_c = 0;
while((block_c = test(block_c, ((256/16) * 1024), str, &gstr)) != (((256/16) * 1024) * 20))
printf("%ldsec\t\t%lukb\n",time(NULL)-starttime,gstr.size/1024);
}
Минимально оптимизированный вариант в царь-стиле теста из предыдущего ГК. Никто не увидел и начали на меня кукарекать. То ещё ГК, давайте объясняйте что здесь говно.
+107
var
OGTC: cardinal; // для сверки с таймером
procedure CheckPhys;
begin
if OGTC < GetTickCount then begin
Phys; // тут считается вся игровая физика и все изменения состояний. Звуки тоже здесь.
Inc(OGTC, dT);
end;
end;
procedure Graph; // процедура отрисовки графики
var
i: integer;
begin
CheckPhys;
for i := 0 to ItemCount - 1 do with Items[i]^ do CopyPosition := Position; // делаем копию состояния перед отрисовкой мира!
for i := 0 to ItemCount - 1 do begin
ShowItem(Items[i]^); // рисуем элемент мира
CheckPhys; // проверяем, не пора ли снова считать физику
end;
end;
procedure OnIdle;
begin
if PlayingGame then Graph;
end;
Надо, чтобы в игре скорость игрового процесса не зависела от тормозов графики. Даже когда кадр долго рисуется, звуки и движения делаются строго по таймеру. Создавать лишний поток мне в лом, и вообще я дико боюсь приколов с синхронизациями и так далее. Поэтому сделал такую хрень. Сэмулировал многопоточность банальным однопоточным кодом.
0
$ find ~ -name .git -type d -prune -printf "***\n%p\n***\n" -exec git -C '{}/..' status \;
0
https://tproger.ru/articles/frontend-roadmap-2021/
Как много надо учить ради того, чтобы клепать красивые формочки.
Они там совсем ебанулись?
−1
std::optional<int64_t> readNumber(const wchar_t *&str)
{
const wchar_t *origStr = str;
if (*str == L'-' || *str == L'+') {
str++;
if (!std::iswdigit(*str)) {
str--;
return {};
}
} else {
if (!std::iswdigit(*str)) {
return {};
}
}
while (std::iswdigit(*str)) {
str++;
}
return wcstoll(origStr, NULL, 10);
}
А всё потому, что доки по «wcstoll» надо читать!
−3
Как дела в 2019 году?
Экшскрипт сгнил.
+156
var old = 47;
function getRate() {
$.ajax({
url: "http://query.yahooapis.com/v1/public/yql?q=select%20%2a%20from%20yahoo.finance.xchange%20where%20pair%20in%20%28%22USDRUB%22%29&env=store://datatables.org/alltableswithkeys",
dataType: "text"
}).done(function(msg) {
var value = /<Rate>(.+)<\/Rate>/.exec(msg)[1];
//$("#p-rate").html(/<Rate>(.+)<\/Rate>/.exec(msg)[1]);
$("#p-rate").html(value);
if(value > old) $("#p-message").html("МНЕ ОТ ЭТОГО ТОЛЬКО ЛУЧШЕ! ТОЛЬКО НА ПОЛЬЗУ!");
else if(value < old) $("#p-message").html("СКАЛЕН! СКАЛЕН!");
else $("#p-message").html("МНОГОХОДОВОЧКА!");
old = value;
});
}
setInterval(getRate,1500);
+142
public class PDFVPage
{
....
public int GetX()
{
return m_x;
}
public int GetY()
{
return m_y;
}
Либа Android PDF :)