- 1
- 2
- 3
- 4
- 5
- 6
- 7
- 8
const breakpointChecker = function() {
if ( breakpoint.matches === true ) {
//...
return;
} else if ( breakpoint.matches === false ) {
//...
}
};
Нашли или выдавили из себя код, который нельзя назвать нормальным, на который без улыбки не взглянешь? Не торопитесь его удалять или рефакторить, — запостите его на говнокод.ру, посмеёмся вместе!
0
const breakpointChecker = function() {
if ( breakpoint.matches === true ) {
//...
return;
} else if ( breakpoint.matches === false ) {
//...
}
};
Источник: https://medium.com/@networkaaron/swiper-how-to-destroy-swiper-on-min-width-breakpoints-a947491ddec8
+1
public static <T> Comparator<T> reverseOrder(Comparator<T> cmp) {
if (cmp == null)
return reverseOrder();
if (cmp instanceof ReverseComparator2)
return ((ReverseComparator2<T>)cmp).cmp;
return new ReverseComparator2<>(cmp);
}
кишки стандартной библиотеки йажи продолжают радовать, хорошо хоть нет ReverseComparatorFinal или ReverseComparatorBassBoostedByKirillXXL
−2
using System;
namespace c_2
{
class Program
{
static void Main(string[] args)
{
start:
Console.WriteLine("введите первое число");
var a = Convert.ToDouble(Console.ReadLine());;
Console.WriteLine("введите второе число");
var b = Convert.ToDouble(Console.ReadLine());;
Console.WriteLine("Введите действие(+ - * /)");
string act=Console.ReadLine();
if (act == "+")
{
Console.WriteLine(a+b);
}
else
{
if (act == "-")
{
Console.WriteLine(a - b);
}
else
{
if(act=="*")
{
Console.WriteLine(a*b);
}
else
{
if (act == "/")
{
Console.WriteLine(a/b);
}
}
}
Console.WriteLine("Выйти?(y/n)");
string exit = Console.ReadLine();
if (exit == "y" )
{
Environment.Exit(0);
}
else
{
if (exit == "n")
{
goto start;
}
{
}
}
}
}
}
}
Калькулятор(моя первая прога на шарпе)
+1
$userId = getUser(); //получаем список всех пользователей
$valueArray = array();
$keyArray = array();
$valueArray1 = array();
$keyArray1 = array();
$resultArray = array();
$resultArray1 = array();
for($i=0;$i<count($userId);$i++){
array_push($valueArray,$userId[$i]['user_id']);
array_push($keyArray,$userId[$i]['status']);
}
for ($i = 0; $i<count($keyArray); $i++) {
$resultArray[$valueArray[$i]] = $keyArray[$i];
}
for($i=0;$i<count($userId);$i++){
array_push($valueArray1,$userId[$i]['user_id']);
array_push($keyArray1,$userId[$i]['active']);
}
for ($i = 0; $i<count($keyArray1); $i++) {
$resultArray1[$valueArray1[$i]] = $keyArray1[$i];
}
$array = array();
foreach ($resultArray as $key => $value){
if($value==="finish"){
if($resultArray1[$key]==='Y'){
array_push($array,$key);
}
}
}
Получаем массив пользователей у которых завершен звонок.
0
class std::unordered_map<class std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> >,
enum REG,struct std::hash<class std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> > >,
struct std::equal_to<class std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> > >,
class std::allocator<struct std::pair<class std::basic_string<char,struct std::char_traits<char>,
class std::allocator<char> > const ,enum REG> > > registers"
(?registers@@3V?$unordered_map@V?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@W4REG@@U?$hash@V?$
basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@@2@U?$equal_to@V?$basic_string@DU?$char_traits@D@std@@V?
$allocator@D@2@@std@@@2@V?$allocator@U?$pair@$$CBV?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@W4
REG@@@std@@@2@@std@@A) уже определен в decoder.obj PVC-16 C:\Users\Люда\source\repos\PVC-16\PVC-16\interrupt.obj 1
Похлопаем visual c++ за понятный лог.
+1
Я вот смотрю на Ричарда Столлмана... Вижу, как он всю жизнь рвёт на себе жопчик за халявное ПО...
И думаю: а что сделал ОН? Он написал "Photoshop"? Создал "Windows"? Разработал хоть что-то?
Знает ли он, что такое многочасовой, многодневный, многомесячный, а иногда и многолетний труд разработки?
Всё его достижение - это ТЕКСТ лицензии "GNU". Всё.
В чём смысл Ричарда Столлмана?
И, кстати, нахуй вообще нужны лицензии на халявное ПО?
0
func verbMatches(p abac.Policy, a authorizer.Attributes) bool {
// TODO: match on verb
серёга, задолбал, давай уже в прод катить, потом свою авторизацию сделаешь
https://github.com/kubernetes/kubernetes/blob/master/pkg/auth/authorizer/abac/abac.go#L178
+1
pub struct Vec { x: u32, y: u32, z: u32, }
pub extern "C" fn sum_c(a: &Vec, b: &Vec) -> Vec {
return Vec {x: a.x + b.x, y: a.y + b.y, z: a.z + b.z };
}
pub fn sum_rust(a: &Vec, b: &Vec) -> Vec {
return Vec {x: a.x + b.x, y: a.y + b.y, z: a.z + b.z };
}
Выхлоп:
example::sum_c:
mov eax, dword ptr [rsi]
add eax, dword ptr [rdi]
mov ecx, dword ptr [rsi + 4]
add ecx, dword ptr [rdi + 4]
mov edx, dword ptr [rsi + 8]
add edx, dword ptr [rdi + 8]
shl rcx, 32
or rax, rcx
ret
example::sum_rust:
mov ecx, dword ptr [rdx]
mov r8d, dword ptr [rdx + 4]
add ecx, dword ptr [rsi]
add r8d, dword ptr [rsi + 4]
mov edx, dword ptr [rdx + 8]
add edx, dword ptr [rsi + 8]
mov rax, rdi
mov dword ptr [rdi], ecx
mov dword ptr [rdi + 4], r8d
mov dword ptr [rdi + 8], edx
ret
«Дак йаже как Сишка!», «Даёшь пuтушатню в Ядро!»
https://godbolt.org/z/Tcnz75
rustc 1.46 (latest)
0
#include <cstdlib>
#include <chrono>
#include <iostream>
#include <thread>
int p = 0;
int *q = nullptr;
void g()
{
using namespace std::chrono_literals;
std::cout << "g()" << std::endl;
std::cout << "g(): p = 1" << std::endl;
p = 1;
std::this_thread::sleep_for(1s);
if (q != nullptr) {
std::cout << "g(): *q = 1" << std::endl;
*q = 1;
} else {
std::cout << "g(): q == nullptr" << std::endl;
}
}
void f()
{
using namespace std::chrono_literals;
std::cout << "f()" << std::endl;
if (p == 0) {
std::cout << "f(): first loop start" << std::endl;
while (p == 0) { } // Потенциально конечный
std::cout << "f(): first loop end" << std::endl;
}
int i = 0;
q = &i;
std::cout << "f(): second loop start" << std::endl;
while (i == 0) { } // Потенциально конечный, хотя в условии только автоматическая пельменная
std::cout << "f(): second loop end" << std::endl;
}
int main()
{
using namespace std::chrono_literals;
std::cout << "f() thread start" << std::endl;
auto thr1 = std::thread(f);
thr1.detach();
std::this_thread::sleep_for(1s);
std::cout << "g() thread start" << std::endl;
auto thr2 = std::thread(g);
thr2.detach();
std::this_thread::sleep_for(2s);
std::cout << "Done" << std::endl;
std::_Exit(EXIT_SUCCESS);
}
Ожидание:
f() thread start
f()
f(): first loop start
g() thread start
g()
g(): p = 1
f(): first loop end
f(): second loop start
g(): *q = 1
f(): second loop end
Done
+2
/* https://habr.com/ru/company/piter/blog/491996/
Пусть в Python такая штука и называется генератором, в языке C++ она
называлась бы корутиной. Пример взят с этого сайта: https://masnun.com/2015/11/13/python-generators-coroutines-native-coroutines-and-async-await.html
def generate_nums():
num = 0
while True:
yield num
num = num + 1
nums = generate_nums()
for x in nums:
print(x)
if x > 9:
*/
#include <stdio.h>
#include <stdlib.h>
#include <stdint.h>
#include <stdbool.h>
#define START 0
#define YIELD 1
typedef struct
{
uint8_t jmpto;
int num;
} coroutine_state;
int generate_nums(coroutine_state *state)
{
switch(state->jmpto)
{
case START: break;
case YIELD: goto yield;
}
while (true)
{
state->jmpto = YIELD; return state->num; yield: // какая питушня
state->num = state->num + 1;
}
}
int main(void)
{
int x;
coroutine_state st = {START, 0};
while(true)
{
x = generate_nums(&st);
printf("%d\n", x);
if (x > 9)
{
break;
}
}
return EXIT_SUCCESS;
}
Попробовал переписать эту ко-ко-корутину c питуха на Си - получилась какая-то херня нечитаемая. что еще раз доказывает, что корутины нахуй не нужны
К тому же в крестопарашном говне они требуют хип, а это нахуй не нужно на самом-то деле.