- 1
IT Оффтоп #135
Нашли или выдавили из себя код, который нельзя назвать нормальным, на который без улыбки не взглянешь? Не торопитесь его удалять или рефакторить, — запостите его на говнокод.ру, посмеёмся вместе!
+2
IT Оффтоп #135
#105: https://govnokod.ru/27544 https://govnokod.xyz/_27544
#106: https://govnokod.ru/27552 https://govnokod.xyz/_27552
#107: https://govnokod.ru/27554 https://govnokod.xyz/_27554
#108: https://govnokod.ru/27557 https://govnokod.xyz/_27557
#109: https://govnokod.ru/27581 https://govnokod.xyz/_27581
#110: https://govnokod.ru/27610 https://govnokod.xyz/_27610
#111: https://govnokod.ru/27644 https://govnokod.xyz/_27644
#112: https://govnokod.ru/27648 https://govnokod.xyz/_27648
#113: https://govnokod.ru/27652 https://govnokod.xyz/_27652
#114: https://govnokod.ru/27659 https://govnokod.xyz/_27659
#115: https://govnokod.ru/27665 https://govnokod.xyz/_27665
#116: https://govnokod.ru/27671 https://govnokod.xyz/_27671
#117: https://govnokod.ru/27675 https://govnokod.xyz/_27675
#118: https://govnokod.ru/27685 https://govnokod.xyz/_27685
#119: https://govnokod.ru/27701 https://govnokod.xyz/_27701
#120: https://govnokod.ru/27703 https://govnokod.xyz/_27703
#121: https://govnokod.ru/27710 https://govnokod.xyz/_27710
#122: https://govnokod.ru/27728 https://govnokod.xyz/_27728
#123: https://govnokod.ru/27729 https://govnokod.xyz/_27729
#124: https://govnokod.ru/27730 https://govnokod.xyz/_27730
#125: https://govnokod.ru/27732 https://govnokod.xyz/_27732
#126: https://govnokod.ru/27733 https://govnokod.xyz/_27733
#127: https://govnokod.ru/27737 https://govnokod.xyz/_27737
#128: https://govnokod.ru/27742 https://govnokod.xyz/_27742
#129: https://govnokod.ru/27747 https://govnokod.xyz/_27747
#130: https://govnokod.ru/27755 https://govnokod.xyz/_27755
#131: https://govnokod.ru/27766 https://govnokod.xyz/_27766
#132: https://govnokod.ru/27790 https://govnokod.xyz/_27790
#133: https://govnokod.ru/27828 https://govnokod.xyz/_27828
#134: https://govnokod.ru/27834 https://govnokod.xyz/_27834
+2
#include <stdio.h>
#include <stdlib.h>
#include <inttypes.h>
#include <limits.h>
typedef unsigned __int128 uint128_t;
typedef __int128 int128_t;
// в чем тут по-вашему баг ?
uint64_t add1bit_left_1_bug(const uint64_t a, int shift)
{
return ~(~(a << shift) >> shift);
}
uint64_t add1bit_left_1(const uint64_t a, int shift)
{
return ~((uint128_t)~(uint64_t)((uint128_t)a << shift) >> shift);
}
// или тут ?
uint64_t add1bit_left_2_bug(const uint64_t a, int shift)
{
return a | (uint64_t)(UINT64_MAX << (CHAR_BIT * sizeof(uint64_t) - shift));
}
uint64_t add1bit_left_2(const uint64_t a, int shift)
{
return a | (uint64_t)((uint128_t)-1 << (CHAR_BIT * sizeof(uint64_t) - shift));
}
uint64_t add1bit_left_3(const uint64_t a, int shift)
{
if (shift == 0) return a;
return (uint64_t)((int64_t)((a << (shift-1)) | ((uint64_t)1 << (CHAR_BIT * sizeof(uint64_t) - 1)) ) >> (shift-1)); // а тут вообще UB
}
int main(void)
{
// tests
for (int i = 0; i <= 64; i++) // пробуем сдвигать от 0 до 64 включительно.
{
// for (uint128_t j = 0; j < UINT64_MAX+1; j++) - какая формальная верификация )))
for (uint64_t j = 0; j < 100; j++)
{
if (add1bit_left_1(j,i) != add1bit_left_2(j,i))
{
printf("error1\n");
printf("%" PRIu64 " %d\n", j,i);
return EXIT_FAILURE;
}
if (add1bit_left_1(j,i) != add1bit_left_3(j,i))
printf("error2\n");
if (add1bit_left_2(j,i) != add1bit_left_3(j,i))
printf("error3\n");
}
}
printf("%" PRIX64 "\n", add1bit_left_1(0,0));
printf("%" PRIX64 "\n", add1bit_left_2(0,0));
printf("%" PRIX64 "\n", add1bit_left_3(0,0));
printf("%" PRIX64 " - bug\n", add1bit_left_1_bug(0,0));
printf("%" PRIX64 " - bug\n", add1bit_left_2_bug(0,0));
puts("");
printf("%" PRIX64 "\n", add1bit_left_1(0,1));
printf("%" PRIX64 "\n", add1bit_left_2(0,1));
printf("%" PRIX64 "\n", add1bit_left_3(0,1));
printf("%" PRIX64 " - bug\n", add1bit_left_1_bug(0,1));
printf("%" PRIX64 " - bug\n", add1bit_left_2_bug(0,1));
puts("");
printf("%" PRIX64 "\n", add1bit_left_1(0,2));
printf("%" PRIX64 "\n", add1bit_left_2(0,2));
printf("%" PRIX64 "\n", add1bit_left_3(0,2));
printf("%" PRIX64 " - bug\n", add1bit_left_2_bug(0,2));
printf("%" PRIX64 " - bug\n", add1bit_left_2_bug(0,2));
puts("");
printf("%" PRIX64 "\n", add1bit_left_1(0,64));
printf("%" PRIX64 "\n", add1bit_left_2(0,64));
printf("%" PRIX64 "\n", add1bit_left_3(0,64));
printf("%" PRIX64 " - bug\n", add1bit_left_1_bug(0,64));
printf("%" PRIX64 " - bug\n", add1bit_left_2_bug(0,64));
return EXIT_SUCCESS;
}
Вореанты говнофункции, которая сдвигает влево uint64_t но набрасывает единички вместо ноликов.
+2
let checks: boolean[] = [];
languages.value.map((language) => {
checks.push(name.value.hasOwnProperty(language.locale) && !!name.value[language.locale]);
checks.push(description.value.hasOwnProperty(language.locale) && !!description.value[language.locale]);
});
return !checks.includes(false);
+2
uint16_t Mnemonic::describeMnemonics(void) const
{
uint16_t result = 0;
size_t i = 0;
for (auto&& m : mnemonics)
result += m.index() << i++ * 4;
return result;
}
...
switch(mnemonic.describeMnemonics())
{
case constructDescription(REGISTER, REGISTER):
{
...
}
break;
case constructDescription(REGISTER, CONSTANT):
{
...
}
break;
case constructDescription(REGISTER, LABEL):
{
...
}
break;
case constructDescription(REGISTER, INDIRECT_ADDRESS):
{
...
}
break;
case constructDescription(INDIRECT_ADDRESS, REGISTER):
{
...
}
break;
default:
break;
}
спасибо папочка за паттерн матчинг
+2
// a.h
inline struct $q1 {unsigned a;} $q1i;
// main.cpp
#include "a.h"
int main(int argc, char** args)
{
$q1i.a = argc;
return $q1i.a;
};
у некоторых линукс-юзеров может упасть на этапе линковки
+2
% Totoro sitting in the snow
% By Noa Hoffmann and Pascal Günthner, 21.12.2020
\documentclass[tikz,11pt]{{standalone}}
\usepackage{calligra}
\usepackage[T1]{fontenc}
\usetikzlibrary{%
shapes, shadows, patterns, calc,
decorations.shapes,
decorations.fractals,
decorations.markings,
decorations.pathmorphing
}
\colorlet{bodycolor}{black!35!gray!60!brown!98!green}
\colorlet{bellycolor}{yellow!70!white!92!green}
\tikzset{
furspot/.pic = {
\path [draw = black, thick, fill] (0,0)
.. controls +(0.3,0) and +(0.25,-0.05) .. ++(0.35,-.45)
.. controls +(-0.45,0.25) and +(0.1,0) .. ++(-0.85,-0.05)
.. controls +(-0.3,0.1) and +(-0.4, 0) .. cycle;
},
claw/.pic = {
\path [fill = bodycolor!70, draw] (0,0) arc (0:45:0.2 and 0.8)
arc (135:180:0.2 and 0.8)
arc (180:360:0.059) -- cycle;
},
whiskers/.pic = {
\path [fill = bodycolor!70,draw] (0,0) arc (0:45:0.05 and 2.3)
arc (135:180:0.3 and 2.3)
to[out=-90,in=-90] cycle;
},
snowflake/.pic = {
\fill [decoration = Koch snowflake, white] decorate{ decorate{
decorate{ (-0.5,-0.3) -- ++(60:1) -- ++(-60:1) -- cycle }}};
\foreach \i in {30, 90, 150, 210, 270, 330} {
\draw[blue!50!white,very thin] (0,0) -- +(\i:0.3);
}
\draw[decoration = Koch snowflake, blue!50!white, very thin]
decorate{($(0,0)+(60:0.2)$) -- ($(0,0)+(300:0.2)$) --
($(0,0)+(180:0.2)$) -- cycle};
}
}
\tikzset{
snow/.style = {decoration = {random steps, segment length = 2mm,
amplitude = 0.4mm}, decorate},
plush/.style = {decoration = {random steps, segment length = 1mm,
amplitude = 0.5mm},decorate}
}
\begin{document}
\begin{tikzpicture}[color = bodycolor, draw = black, thick]
%---------------------background and tail----------------------
% blue sky
\fill[blue!30!white] (-8cm,-11cm) rectangle (8cm,10cm);
% random snowflakes
\foreach \i in {0.1,0.11,...,1}{
\pic [scale = \i, opacity = 0.9] at (rand*7.5, rnd*18-10.5) {snowflake};}
% more tiny snowflakes
%\foreach \i in {0.1,0.11,...,0.5}{
%\pic [scale = \i, opacity = 0.9] at (rand*7.5, rnd*18-10.5) {snowflake};}
% cloud with merry christmas
\node [cloud,aspect = 6.5, cloud puff arc = 120, cloud puffs = 12.9, fill = white,
color = white] at (0,7) {\Huge M \hspace{9.8cm}.};
\node [color = red] at (0,7) {\fontsize{50}{80}
\textbf{Merry Christmas \quad }};
% tail
\path [draw, fill, rotate = 50] (-4,-7.5) circle (1.5 and 2.2);
% snowhill
\fill [draw, gray!6, snow] (-8,-11) to[in=200, out=0] (-3,-7.5) to (3,-7.5)
to[out=-20, in=180] (8,-11);
%--------------------body-----------------------------------------
% right ear
\path [fill, draw] (0.6,2.3)+(-45:1) arc (-60:35:1 and 1.5)
arc (115:210:1 and 1.5);
% left ear
\path [fill, draw] (-0.6,2.3)+(-135:1) arc (-120:-215:1 and 1.5)
arc (65:-30:1 and 1.5);
% head
\path [draw, fill] ($(0,0)+(170:2.5 and 2)$) arc (170:10:2.5 and 2)
arc(35:-20: 3 and 2)
-- ($(0,-0.8)+(200:3 and 2)$) arc (200:145:3 and 2) -- cycle;
% body
\path[fill] ($(0,-4)+(200:4 and 4.5)$) arc (200:-20:4 and 4.5);
%----------------------face----------------------------------------
% left eye
\path [draw, fill = white] (-1.4,0.7) circle (0.45 and 0.4);
\fill [black] (-1.2,0.7) circle (0.16);
\fill [white] (-1.24,0.74) circle (0.03);
% right eye
\path [draw, fill = white, thick] (1.4,0.7) circle (0.4);
\fill [black] (1.25,0.7) circle (0.16);
\fill [white] (1.20,0.74) circle (0.03);
% nose
\path [draw] (0.35, 0.7) .. controls (0.2,0.8) and (-0.2, 0.8)
.. (-0.35, 0.7);
Какое аниме ))) https://texample.net/tikz/examples/totoro/
+2
if($response == null){
echo "<pre>";
var_dump($response);
echo "</pre>";
die();
}
Таким способом выводится на экран надпись NULL
+2
(* https://coq.inria.fr/library/Coq.Init.Datatypes.html *)
(* Basic boolean operators *)
Definition andb (b1 b2:bool) : bool := if b1 then b2 else false.
Definition orb (b1 b2:bool) : bool := if b1 then true else b2.
Definition implb (b1 b2:bool) : bool := if b1 then b2 else true.
Definition xorb (b1 b2:bool) : bool :=
match b1, b2 with
| true, true => false
| true, false => true
| false, true => true
| false, false => false
end.
Definition negb (b:bool) := if b then false else true.
Infix "||" := orb : bool_scope.
Infix "&&" := andb : bool_scope.
На первый взгляд этот ваш Coq (питух) выглядит как очередной ML-язычок.
+2
(format t "~A~%" (*) )
https://ideone.com/oO7f4I
+2
https://codeforwin.org/2018/05/10-cool-bitwise-operator-hacks-and-tricks.html
10 cool bitwise operator hacks and tricks every programmer must know
Right shift (>>) operator is equivalent to division by 2
Want to divide a number by 2 quicky. Here you go, use bitwise right shift operator to divide an integer by 2. Each right shift operation reduces the number (operand) to its half.
Просто напомню, что Jawa-петушки вручную заменяют деление/умножение на 2 на сдвиг, потому что анскильный компилятор так не умеет.