- 1
Зачем простенькие проги, написанные на MASM коннектятся к ip адресу Microsoft 20.99.133.109:443?
Нашли или выдавили из себя код, который нельзя назвать нормальным, на который без улыбки не взглянешь? Не торопитесь его удалять или рефакторить, — запостите его на говнокод.ру, посмеёмся вместе!
−4
Зачем простенькие проги, написанные на MASM коннектятся к ip адресу Microsoft 20.99.133.109:443?
−2
cli
a: jmp a
0
int main() {
ifstream input_file;
input_file.open("DATA");
string line;
while (getline(input_file, line)) {
size_t i = 0, j = 0;
string fname, sname;
float score;
char c = line[0];
while((c != ' ') && (j < line.size())) {
c = line[j];
j++;
}
fname = line.substr(i, j - i - 1);
i = j;
j += 1;
c = line[i];
while((c != ' ') && (j < line.size())) {
c = line[j];
j++;
}
sname = line.substr(i, j - i - 1);
i = j;
j += 1;
score = stof(line.substr(i, line.size()));
Data dat;
dat.fname = fname;
dat.sname = sname;
dat.score = score;
vec.push_back(dat);
}
const auto comp_fname = [](Data a, Data b){return a.fname >= b.fname;};
const auto comp_sname = [](Data a, Data b){return a.sname >= b.sname;};
const auto comp_score = [](Data a, Data b){return a.score >= b.score;};
const auto dcomp_fname = [](Data a, Data b){return a.fname < b.fname;};
const auto dcomp_sname = [](Data a, Data b){return a.sname < b.sname;};
const auto dcomp_score = [](Data a, Data b){return a.score < b.score;};
print(vec);
char choice = 0, order = 0;
cout << "Как сортировать (0 - Fфмилия, 1 - Iмя, 2 - CpegHuu_6aJlJl): ";
cin >> choice;
cout << "А в какмо порядке?7? (0 - по убыванию, 1 - по возрастанию)Ж ";
cin >> order;
if (choice == '0') {
if (order == '0') {
sort(vec.begin(), vec.end(), comp_fname);
} else {
sort(vec.begin(), vec.end(), dcomp_fname);
}
} else if (choice == '1') {
if (order == '0') {
sort(vec.begin(), vec.end(), comp_sname);
} else {
sort(vec.begin(), vec.end(), dcomp_sname);
}
} else if (choice == '2') {
if (order == '0') {
sort(vec.begin(), vec.end(), comp_score);
} else {
sort(vec.begin(), vec.end(), dcomp_score);
}
}
// и т.д. ...
Как вам? Зачёт? Незачёт? Удовлетворительно?
−1
class Node<T> {
v: T;
k: string;
next: Node<T>;
}
class Map<T> {
head: Node<T>;
getElt(k: string): T {
return mapGet(this, k)
}
setElt(k: string, v: T) {
mapSet(this, k, v)
}
}
function mapSet<T>(m: Map<T>, k: string, v: T) {
for (let p = m.head; p != null; p = p.next) {
if (p.k == k) {
p.v = v
return
}
}
let n = new Node<T>()
n.next = m.head
n.k = k
n.v = v
m.head = n
}
function mapGet<T>(m: Map<T>, k: string): T {
for (let p = m.head; p != null; p = p.next) {
if (p.k == k) {
return p.v
}
}
return null
}
function search_array<T>(a: T[], item: T): number {
for (let i = 0; i < a.length; i++) {
if (a[i] == item) {
return i
}
}
return -1 // NOT FOUND
}
class MyMap<K, V> {
keys: K[]
values: V[]
constructor() {
this.keys = []
this.values = []
}
push(key: K, value: V) {
this.keys.push(key)
this.values.push(value)
}
value_for(key: K): V {
let i = search_array(this.keys, key)
if (i == -1) {
return null
}
return this.values[i]
}
key_for(value: V): K {
let i = search_array(this.values, value)
if (i == -1) {
return null
}
return this.keys[i]
}
set(key: K, value: V): void {
let i = search_array(this.keys, key)
if (i == -1) {
this.keys.push(key)
this.values.push(value)
} else {
this.values[i] = value
}
}
has_key(key: K): boolean {
return search_array(this.keys, key) != -1
}
has_value(value: V): boolean {
return search_array(this.values, value) != -1
}
}
Срочно нужна помощь... не могу решить что делать с функцией mapGet .. когда T - number я не могу использовать "null" .. должен я хакнуть компилятор или изменить тестовый пример?
0
class Node<T> {
v: T;
k: string;
next: Node<T>;
}
function main()
{
let n = new Node<number>()
n.next = n
n.k = "Hello";
n.v = 10.0;
print("done.");
}
Вы не поверите как сложно сделать простые вещи в LLVM. встречаем рекурсивные типы :)
+3
template<typename T>
static ALWAYS_INLINE void FormatLogMessageAndPrintW(
const char* channelName,
const char* functionName,
LOGLEVEL level,
const char* message,
bool timestamp,
bool ansi_color_code,
bool newline,
const T& callback)
{
char buf[512];
char* message_buf = buf;
int message_len;
if ((message_len = FormatLogMessageForDisplay(message_buf,
sizeof(buf), channelName, functionName,
level,
message, timestamp,
ansi_color_code, newline)) > (sizeof(buf) - 1))
{
message_buf = static_cast<char*>(std::malloc(message_len + 1));
message_len = FormatLogMessageForDisplay(message_buf,
message_len + 1, channelName, functionName,
level, message, timestamp, ansi_color_code, newline);
}
if (message_len <= 0)
return;
// Convert to UTF-16 first so unicode characters display correctly.
// NT is going to do it anyway...
wchar_t wbuf[512];
wchar_t* wmessage_buf = wbuf;
int wmessage_buflen = countof(wbuf) - 1;
if (message_len >= countof(wbuf))
{
wmessage_buflen = message_len;
wmessage_buf = static_cast<wchar_t*>
(std::malloc((wmessage_buflen + 1) * sizeof(wchar_t)));
}
wmessage_buflen = MultiByteToWideChar(CP_UTF8, 0, message_buf,
message_len, wmessage_buf, wmessage_buflen);
if (wmessage_buflen <= 0)
return;
wmessage_buf[wmessage_buflen] = '\0';
callback(wmessage_buf, wmessage_buflen);
if (wmessage_buf != wbuf)
{
std::free(wbuf); // <=
}
if (message_buf != buf)
{
std::free(message_buf);
}
}
Отсюда:
https://pvs-studio.com/ru/blog/posts/cpp/0880/
+5
private static String getMargin(final int size) {
return " ".substring(0, 6 * size);
}
Как создать пустую строку с заданной длиной...
0
#include <stdio.h>
#include <stdlib.h>
#include <inttypes.h>
int main(void)
{
uint32_t uint32max = UINT32_MAX;
int32_t int32_minus_one = -1;
printf("uint32_max = %" PRIu32 "\n", uint32max);
printf("int32_minus_one = %" PRIi32 "\n", int32_minus_one);
if (uint32max > int32_minus_one)
{
puts("uint32max > int32_minus_one");
}
else if (uint32max < int32_minus_one)
{
puts("uint32max < int32_minus_one");
}
else
{
puts("uint32max == int32_minus_one");
}
return EXIT_SUCCESS;
}
Почему в Си нет особого правила при сравнении signed и unsigned типов, ну типа если значение в signed типе отрицательно, то он полюбасу будет меньше любого unsigned значения? А то говно какое-то.
(нет, я понимаю почему так происходит, но все равно говно)
+2
namespace test
{
//public record P(double D);
class Program1
{
static void Main(string[] args)
{
//The differences between Double.Equals and Double==
Console.WriteLine(double.NaN.Equals(double.NaN)); //True
Console.WriteLine(double.NaN == double.NaN); // False
//The same is true for tuples!
Console.WriteLine((double.NaN, 1).Equals((double.NaN, 1))); // True
Console.WriteLine((double.NaN, 1) == (double.NaN, 1)); // False
//But records in C# 9 behave differently!
Console.WriteLine(new P(double.NaN).Equals(new P(double.NaN))); // True
Console.WriteLine(new P(double.NaN) == new P(double.NaN)); // True
}
}
}
https://twitter.com/STeplyakov/status/1333831742134779904
0
def neuro_anec():
group_id = '85443458'
random.seed()
_vk_session = vk_api.VkApi(token=config.service)
_vk = _vk_session.get_api()
max_num = _vk.wall.get(owner_id=-int(group_id), count=0)['count']
try:
anec_base = ''
while len(anec_base.split('\n')) < 1 or anec_base == '':
num = random.randint(1, max_num)
anec_base = '\n'.join(
_vk.wall.get(owner_id=-int(group_id), count=1, offset=num)['items'][0]['text'].split('\n')[:-1])
num = random.randint(1, max_num)
anec_booter = _vk.wall.get(owner_id=-int(group_id), count=1, offset=num)['items'][0]['text'].split('\n')[-1]
return anec_base + '\n' + anec_booter
except:
return 'А хуй тебе'
Представляю вашему вниманию: ней(гей)росеть, генерирующая анеки категории Б