- 1
Питушня #19
Нашли или выдавили из себя код, который нельзя назвать нормальным, на который без улыбки не взглянешь? Не торопитесь его удалять или рефакторить, — запостите его на говнокод.ру, посмеёмся вместе!
+1
Питушня #19
#1: https://govnokod.ru/26692 https://govnokod.xyz/_26692
#2: https://govnokod.ru/26891 https://govnokod.xyz/_26891
#3: https://govnokod.ru/26893 https://govnokod.xyz/_26893
#4: https://govnokod.ru/26935 https://govnokod.xyz/_26935
#5: (vanished) https://govnokod.xyz/_26954
#6: (vanished) https://govnokod.xyz/_26956
#7: https://govnokod.ru/26964 https://govnokod.xyz/_26964
#8: https://govnokod.ru/26966 https://govnokod.xyz/_26966
#9: https://govnokod.ru/27017 https://govnokod.xyz/_27017
#10: https://govnokod.ru/27045 https://govnokod.xyz/_27045
#11: https://govnokod.ru/27058 https://govnokod.xyz/_27058
#12: https://govnokod.ru/27182 https://govnokod.xyz/_27182
#13: https://govnokod.ru/27260 https://govnokod.xyz/_27260
#14: https://govnokod.ru/27343 https://govnokod.xyz/_27343
#15: https://govnokod.ru/27353 https://govnokod.xyz/_27353
#16: https://govnokod.ru/27384 https://govnokod.xyz/_27384
#17: https://govnokod.ru/27482 https://govnokod.xyz/_27482
#18: https://govnokod.ru/27514 https://govnokod.xyz/_27514
0
const int sum(int a, int b){
return a+b;
}
int a(int x)
{
const std::function<int(int)> sum4 = std::bind(sum,_1, 4);
return sum4(123);
}
int b(int x)
{
puts("bagor");
const std::function<int(int)> sum4 = std::bind(sum,_1, 4);
return sum4(123);
}
int c(int x)
{
const std::function<int(int)> sum4 = std::bind(sum,_1, 4);
puts("bagor");
return sum4(123);
}
// Функции a и b нормально инлайнятся. Ассемблерный выхлоп:
sum(int, int): # @sum(int, int)
lea eax, [rdi + rsi]
ret
a(int): # @a(int)
mov eax, 127
ret
b(int): # @b(int)
push rax
mov edi, offset .L.str
call puts
mov eax, 127
pop rcx
ret
//А вот int c(int x)
c(int): # @c(int)
push rbx
sub rsp, 32
mov edi, 16
call operator new(unsigned long)
mov rbx, rax
mov qword ptr [rax], offset sum(int, int)
mov dword ptr [rax + 8], 4
mov qword ptr [rsp], rax
mov qword ptr [rsp + 24], offset std::_Function_handler<int (int), std::_Bind<int const (*(std::_Placeholder<1>, int))(int, int)> >::_M_invoke(std::_Any_data const&, int&&)
mov qword ptr [rsp + 16], offset std::_Function_handler<int (int), std::_Bind<int const (*(std::_Placeholder<1>, int))(int, int)> >::_M_manager(std::_Any_data&, std::_Any_data const&, std::_Manager_operation)
mov edi, offset .L.str
call puts
mov esi, dword ptr [rbx + 8]
mov edi, 123
call qword ptr [rbx]
mov ebx, eax
mov rax, qword ptr [rsp + 16]
test rax, rax
je .LBB3_3
mov rdi, rsp
mov rsi, rdi
mov edx, 3
call rax
.LBB3_3:
mov eax, ebx
add rsp, 32
pop rbx
ret
mov rdi, rax
call __clang_call_terminate
mov rbx, rax
mov rax, qword ptr [rsp + 16]
test rax, rax
je .LBB3_6
mov rdi, rsp
mov rsi, rdi
mov edx, 3
call rax
.LBB3_6:
mov rdi, rbx
call _Unwind_Resume@PLT
mov rdi, rax
call __clang_call_terminate
__clang_call_terminate: # @__clang_call_terminate
push rax
call __cxa_begin_catch
call std::terminate()
std::_Function_handler<int (int), std::_Bind<int const (*(std::_Placeholder<1>, int))(int, int)> >::_M_invoke(std::_Any_data const&, int&&): # @std::_Function_handler<int (int), std::_Bind<int const (*(std::_Placeholder<1>, int))(int, int)> >::_M_invoke(std::_Any_data const&, int&&)
mov rax, qword ptr [rdi]
mov rcx, qword ptr [rax]
mov edi, dword ptr [rsi]
mov esi, dword ptr [rax + 8]
jmp rcx # TAILCALL
std::_Function_handler<int (int), std::_Bind<int const (*(std::_Placeholder<1>, int))(int, int)> >::_M_manager(std::_Any_data&, std::_Any_data const&, std::_Manager_operation): # @std::_Function_handler<int (int), std::_Bind<int const (*(std::_Placeholder<1>, int))(int, int)> >::_M_manager(std::_Any_data&, std::_Any_data const&, std::_Manager_operation)
Решил попробовать std::bind.
https://godbolt.org/z/eW5eT5oj4
+3
Афганистан заебал.
−2
# Дамп базы хуза
# Постобработка export-а из MySQL
import pandas as pd
import numpy as np
import csv
comments = pd.read_csv('/wp_comments-2.csv', header=None)
comments.head()
##
comments_clean = pd.DataFrame({
'comment_id': comments[0],
'comment_post_id': comments[1],
'comment_parent': comments[13],
'name': comments[2],
'gravatar_hash': comments[3].str.split('@').str[0],
'gravatar_domain': comments[3].str.split('@').str[1],
'profile': comments[4],
'date': comments[6],
'content': comments[8],
})
##
comments_clean[(comments_clean.gravatar_domain != 'lo.ol') & ~comments_clean.gravatar_domain.isna()]
##
comments_clean = comments_clean[(comments_clean.gravatar_domain == 'lo.ol') | comments_clean.gravatar_domain.isna()]
comments_clean.drop(columns=['gravatar_domain'], inplace=True)
comments_clean.head()
##
posts = pd.read_csv('/wp_posts.csv', header=None)
posts = posts[(posts[20] == 'post') & (posts[7] == 'publish') & (posts[11].str.match('^_'))]
posts.head()
##
posts_clean = pd.DataFrame({
'post_id': posts[0],
'date': posts[2],
'content': posts[4],
'description': posts[6],
'original_id': posts[11].str[1:]
})
posts_clean.head()
##
comments_clean.to_csv('~/Downloads/gost/comments.csv', index=False)
posts_clean.to_csv('~/Downloads/gost/posts.csv', index=False)
https://govnokod.xyz/dump/wp_gk_legacy_users.csv
../comments.csv
../posts.csv
+2
Steps to reproduce:
var s = "a huge, huge, huge string...";
s = s.substring(0, 5);
Expected results: s takes five bytes of memory, plus some overhead.
Actual results: s takes a huge, huge, huge amount of memory.
Unfortunately, most String functions use substring() or no-ops internally: concatenating with empty string, trim(), slice(), match(), search(), replace() with no match, split(), substr(), substring(), toString(), trim(), valueOf().
My workaround is:
function unleakString(s) { return (' ' + s).substr(1); }
But it's not satisfying, because it breaks an abstraction and forces me to think about memory allocation.
https://bugs.chromium.org/p/v8/issues/detail?id=2869
Status: Assigned (Open)
Reported on: Sep 3, 2013
+1
function *foo()
{
yield 1;
yield 2;
yield 3;
}
function main()
{
for (const o of foo())
{
console.log (o);
}
}
main();
давайте посмотрим, как TS/JS имплементирует "елды". изначально код выглядит красиво. но заглянем под капот что генерит tsc для выполнение такого кода. мне придется разбить этот ужос
+1
struct file_id
{
uint64_t persistent;
uint64_t volatile_;
static const size_t RAW_LENGTH = 16;
operator std::string() const
{ return std::string(reinterpret_cast<const char*>(&persistent), RAW_LENGTH); }
// Операторы для использования file_id в качестве ключа map и
// unordered_map
struct hash
{
std::size_t operator()(const ntdec_smb2_file_id& file_id) const
{
std::string s_file_id = file_id;
std::hash<std::string> hasher;
return hasher(s_file_id);
}
};
bool operator == (const ntdec_smb2_file_id& other)
{
return std::string(*this) == std::string(other);
}
bool operator < (const ntdec_smb2_file_id& other)
{
return std::string(*this) < std::string(other);
}
bool operator > (const ntdec_smb2_file_id& other)
{
return std::string(*this) > std::string(other);
}
};
operator std::string тоже UB?
+2
class IntIter {
constructor(private i = 0) {}
next() {
type retType = [value: typeof this.i, done: boolean];
if (this.i < 10) {
return <retType>[this.i++, false];
}
return <retType>[this.i, true];
}
}
function main() {
let it = new IntIter();
for (const o of it)
{
print(o);
}
for (const o of "Hello")
{
print(o);
}
}
добавил поддержку ForOf для ES2015 и ES3; причем компилятор сам определяет какой вариант лучше юзать
+1
type a = 1;
type i = a & a;
type j = a | a;
function main() {
let v1: i;
let v2: j;
assert(sizeof(i) != sizeof(j));
print("done.");
}
ну все я понял вам скучно... как насчет такого примера?
+6
Раскрытие покровов. Настя, облачные технологии и Настенька.