1. Pascal / Говнокод #27793

    −2

    1. 01
    2. 02
    3. 03
    4. 04
    5. 05
    6. 06
    7. 07
    8. 08
    9. 09
    10. 10
    11. 11
    12. 12
    13. 13
    14. 14
    15. 15
    16. 16
    17. 17
    18. 18
    19. 19
    20. 20
    21. 21
    22. 22
    23. 23
    24. 24
    25. 25
    26. 26
    27. 27
    28. 28
    29. 29
    30. 30
    31. 31
    32. 32
    33. 33
    34. 34
    35. 35
    36. 36
    37. 37
    38. 38
    // Подгрузка аватаров пользователей.
        Bmp:=TBitMap.Create; // Нет более изящного спооба узнать тип изображения, не колупаясь в заголовках. Расширение файлов картинок зачастую фиктивное.
        try                  // Зная, что ава может быть только двух типов - jpg и png, я решил пойти конём.
          Bmp.PixelFormat:=pf32Bit;
          Bmp.Width:=16;
          Bmp.Height:=16;
          ImgConv:=True;
          Png:=TPngObject.Create;
          try
            try
              Comm.RawAvatar.Position:=0;
              Png.LoadFromStream(Comm.RawAvatar);
              Bmp.Canvas.StretchDraw(Bmp.Canvas.ClipRect, Png);
            except
              ImgConv:=False;     // Ошибка конвертирования. Не совпал формат - идем дальше, пробуем jpg...
            end;
          finally
            Png.Free;             // нет смысла раскручивать стек, ибо исключение в любом случае отловится try..except
          end;
          if not ImgConv then
          begin
            Jpg:=TJPEGImage.Create;
            try
              try
                Comm.RawAvatar.Position:=0;
                Jpg.LoadFromStream(Comm.RawAvatar);
                Bmp.Canvas.StretchDraw(Bmp.Canvas.ClipRect, Jpg);
              except
              end;
            finally
              Jpg.Free;
            end;
          end;
          CommentList.Items[I].ImageIndex:=Images.AddMasked(Bmp, clWhite);
        finally
          Bmp.Free;
        end;
      end;

    "Тут всюду густая вонь, то жаркая и приятная, то теплая и противная, но одинаково волнующая, особая, пароходная, мешающаяся с морской свежестью"

    @ Бунин.

    Теперь минусатор умеет подгружать авы.
    https://dropmefiles.com/USQKW

    Support, 05 Ноября 2021

    Комментарии (0)
  2. Си / Говнокод #27792

    0

    1. 01
    2. 02
    3. 03
    4. 04
    5. 05
    6. 06
    7. 07
    8. 08
    9. 09
    10. 10
    11. 11
    12. 12
    13. 13
    14. 14
    15. 15
    16. 16
    17. 17
    18. 18
    19. 19
    20. 20
    21. 21
    22. 22
    23. 23
    24. 24
    25. 25
    26. 26
    27. 27
    28. 28
    29. 29
    30. 30
    31. 31
    32. 32
    33. 33
    34. 34
    35. 35
    36. 36
    37. 37
    38. 38
    39. 39
    40. 40
    41. 41
    42. 42
    43. 43
    44. 44
    45. 45
    46. 46
    47. 47
    48. 48
    49. 49
    50. 50
    // https://github.com/dxFeed/dxfeed-c-api/blob/8f24055298c9751344db72da03ab8eb37dfeb6a5/src/DXAlgorithms.h#L63
    
    #define CHECKED_CALL(func, param) \
    	do { \
    		if (!func(param)) { \
    			return false; \
    		} \
    	} while (false)
    
    #define CHECKED_CALL_0(func) \
    	do { \
    		if (!func()) { \
    			return false; \
    		} \
    	} while (false)
    
    #define CHECKED_CALL_1(func, param1) \
    	do { \
    		if (!func(param1)) { \
    			return false; \
    		} \
    	} while (false)
    
    #define CHECKED_CALL_2(func, param1, param2) \
    	do { \
    		if (!func(param1, param2)) { \
    			return false; \
    		} \
    	} while (false)
    
    #define CHECKED_CALL_3(func, param1, param2, param3) \
    	do { \
    		if (!func(param1, param2, param3)) { \
    			return false; \
    		} \
    	} while (false)
    
    #define CHECKED_CALL_4(func, param1, param2, param3, param4) \
    	do { \
    		if (!func(param1, param2, param3, param4)) { \
    			return false; \
    		} \
    	} while (false)
    
    #define CHECKED_CALL_5(func, param1, param2, param3, param4, param5) \
    	do { \
    		if (!func(param1, param2, param3, param4, param5)) { \
    			return false; \
    		} \
    	} while (false)

    Мокроебства

    j123123, 05 Ноября 2021

    Комментарии (11)
  3. C++ / Говнокод #27787

    +1

    1. 01
    2. 02
    3. 03
    4. 04
    5. 05
    6. 06
    7. 07
    8. 08
    9. 09
    10. 10
    11. 11
    12. 12
    13. 13
    14. 14
    15. 15
    16. 16
    17. 17
    18. 18
    19. 19
    20. 20
    21. 21
    22. 22
    23. 23
    24. 24
    25. 25
    26. 26
    27. 27
    28. 28
    29. 29
    30. 30
    31. 31
    32. 32
    33. 33
    34. 34
    35. 35
    36. 36
    37. 37
    38. 38
    39. 39
    40. 40
    41. 41
    42. 42
    43. 43
    44. 44
    45. 45
    46. 46
    47. 47
    48. 48
    49. 49
    50. 50
    51. 51
    52. 52
    53. 53
    54. 54
    55. 55
    56. 56
    57. 57
    58. 58
    59. 59
    60. 60
    61. 61
    62. 62
    63. 63
    64. 64
    65. 65
    #include <string>
    #include <type_traits>
    #include <iostream>
    
    template<int N> struct tag {};
    
    template<typename T, int N>
    struct loophole_t
    {
        friend auto loophole(tag<N>) { return T{}; };
    };
    
    #define BA(c) auto loophole(tag< (c) >);
    #define Cb(c) BA(c) BA(c+1) BA(c+2) BA(c+3) BA(c+4)
    #define KA(c) Cb(c) Cb(c+5) Cb(c+10) Cb(c+15) Cb(c+20)
    #define ZDES(c) KA(c) KA(c+20) KA(c+40) KA(c+60) KA(c+80)
    #define BACbKAZDES ZDES(0) ZDES(80) ZDES(160) ZDES(240) ZDES(300)
    
    BACbKAZDES
    
    template<int I>
    struct wrp
    {
        int a;
    };
    int main(void)
    {
        sizeof(loophole_t<wrp<67>, 0>);
        sizeof(loophole_t<wrp<66>, 1>);
        sizeof(loophole_t<wrp<68>, 2>);
        sizeof(loophole_t<wrp<99>, 3>);
        sizeof(loophole_t<wrp<76>, 4>);
        sizeof(loophole_t<wrp<66>, 5>);
        sizeof(loophole_t<wrp<33>, 6>);
        sizeof(loophole_t<wrp<73>, 7>);
        sizeof(loophole_t<wrp<66>, 8>);
        sizeof(loophole_t<wrp<68>, 9>);
        sizeof(loophole_t<wrp<85>, 10>);
        sizeof(loophole_t<wrp<70>, 11>);
        sizeof(loophole_t<wrp<79>, 12>);
        sizeof(loophole_t<wrp<99>, 13>);
        sizeof(loophole_t<wrp<76>, 14>);
        sizeof(loophole_t<wrp<66>, 15>);
        sizeof(loophole_t<wrp<33>, 16>);
        sizeof(loophole_t<wrp<109>, 17>);
        sizeof(loophole_t<wrp<112>, 18>);
        sizeof(loophole_t<wrp<119>, 19>);
        sizeof(loophole_t<wrp<102>, 20>);
    
        std::string nactenbka;
    #define L(c, i) if(std::is_same< wrp< (c) >, decltype( loophole(tag< (i) >{}) )>::value) nactenbka.push_back((char)( c-1 ) );
    #define O(c, i) L(c, i) L(c+1, i) L(c+2, i) L(c+3, i) L(c+4, i)
    #define V(c, i) O(c, i) O(c+5, i) O(c+10,i) O(c+15,i) O(c+20,i)
    #define E(c, i) V(c, i) V(c+20,i) V(c+40,i) V(c+60,i) V(c+80,i)
    #define LOVE(c, i) E(c, i) V(c+80, i) V(c+100, i)
    
    #define FORE(i) LOVE(0, i)
    #define VER(i) FORE(i) FORE(i+1) FORE(i+2) FORE(i+3) FORE(i+4)
    #define FOREVER VER(0) VER(5) VER(10) VER(15) FORE(20)
        FOREVER
    
        std::cout << nactenbka << std::endl;
        return 0;
    
    }

    <3

    BACbKA, 04 Ноября 2021

    Комментарии (9)
  4. C++ / Говнокод #27785

    +3

    1. 01
    2. 02
    3. 03
    4. 04
    5. 05
    6. 06
    7. 07
    8. 08
    9. 09
    10. 10
    11. 11
    12. 12
    13. 13
    14. 14
    15. 15
    16. 16
    17. 17
    18. 18
    19. 19
    20. 20
    21. 21
    22. 22
    23. 23
    24. 24
    25. 25
    26. 26
    27. 27
    28. 28
    29. 29
    30. 30
    31. 31
    32. 32
    33. 33
    34. 34
    35. 35
    36. 36
    37. 37
    38. 38
    39. 39
    40. 40
    41. 41
    42. 42
    43. 43
    44. 44
    45. 45
    46. 46
    47. 47
    48. 48
    49. 49
    50. 50
    51. 51
    52. 52
    53. 53
    54. 54
    55. 55
    56. 56
    57. 57
    58. 58
    59. 59
    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/

    HO9I6PbCKuu_neTyx, 03 Ноября 2021

    Комментарии (31)
  5. JavaScript / Говнокод #27784

    0

    1. 01
    2. 02
    3. 03
    4. 04
    5. 05
    6. 06
    7. 07
    8. 08
    9. 09
    10. 10
    11. 11
    interface Surface {
    	n: number;
    }
    
    let shiny: Surface = {
    	n: 10.0
    }
    
    function main() {
    	print(shiny.n);
    }

    шах и мат С/C++ девелоперам :) (постов не будет - сайт все блокирует)

    ASD_77, 02 Ноября 2021

    Комментарии (3)
  6. Assembler / Говнокод #27782

    0

    1. 01
    2. 02
    3. 03
    4. 04
    5. 05
    6. 06
    7. 07
    8. 08
    9. 09
    10. 10
    11. 11
    12. 12
    13. 13
    14. 14
    15. 15
    16. 16
    17. 17
    18. 18
    19. 19
    20. 20
    21. 21
    .org 80h
    data:
    	db "Hello, world!\n"
    	db 0
    start:
    	mov %c 1h
    	mov %bp @data
    	mov %si 0
    	.loop:
    		mov %al [%si + %bp]
    		inc %si
    		cmp %al 0h
    		jz @.exit
    		int 5h
    		jmp @.loop
    	.exit:
    	int 0h
    
      0080  48 65 6C 6C 6F 20 77 6F 72 6C 64 21 0A 00 02 02
      0090  01 00 02 06 80 00 02 05 00 00 03 0A 38 09 05 0C
      00A0 0A 00 00 0E AB 00 0B 05 0D 9A 00 0B 00 00 00 00

    накодил виртуальную машину, заспидранил Hello World за четыре дня. рекорд.
    https://github.com/kcalbSphere/PVC-16

    digitalEugene, 01 Ноября 2021

    Комментарии (26)
  7. C++ / Говнокод #27781

    +2

    1. 01
    2. 02
    3. 03
    4. 04
    5. 05
    6. 06
    7. 07
    8. 08
    9. 09
    10. 10
    11. 11
    12. 12
    13. 13
    14. 14
    15. 15
    16. 16
    17. 17
    18. 18
    19. 19
    20. 20
    21. 21
    22. 22
    23. 23
    24. 24
    25. 25
    26. 26
    27. 27
    28. 28
    29. 29
    30. 30
    31. 31
    32. 32
    33. 33
    34. 34
    35. 35
    36. 36
    37. 37
    38. 38
    39. 39
    40. 40
    41. 41
    42. 42
    43. 43
    44. 44
    45. 45
    46. 46
    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;
    
    }

    спасибо папочка за паттерн матчинг

    digitalEugene, 01 Ноября 2021

    Комментарии (9)
  8. Куча / Говнокод #27780

    +1

    1. 01
    2. 02
    3. 03
    4. 04
    5. 05
    6. 06
    7. 07
    8. 08
    9. 09
    10. 10
    11. 11
    12. 12
    13. 13
    14. 14
    15. 15
    16. 16
    17. 17
    18. 18
    19. 19
    20. 20
    21. 21
    22. 22
    23. 23
    24. 24
    25. 25
    26. 26
    27. 27
    28. 28
    (** Set of all possible interleaving of two traces is a trace
      ensemble. As we later prove in [interleaving_to_permutation], this
      definition is dual to [Permutation]. *)
      Inductive Interleaving : list TE -> list TE -> TraceEnsemble :=
      | ilv_cons_l : forall te t1 t2 t,
          Interleaving t1 t2 t ->
          Interleaving (te :: t1) t2 (te :: t)
      | ilv_cons_r : forall te t1 t2 t,
          Interleaving t1 t2 t ->
          Interleaving t1 (te :: t2) (te :: t)
      | ilv_nil : Interleaving [] [] [].
    
    Попытка оптимизации:
    
      (* Left-biased version of [Interleaving] that doesn't make
      distinction between schedulings of commuting elements: *)
      Inductive UniqueInterleaving : list TE -> list TE -> TraceEnsemble :=
      | uilv_cons_l : forall l t1 t2 t,
          UniqueInterleaving t1 t2 t ->
          UniqueInterleaving (l :: t1) t2 (l :: t)
      | uilv_cons_r1 : forall l r t1 t2 t,
          ~trace_elems_commute l r ->
          UniqueInterleaving (l :: t1) t2 (l :: t) ->
          UniqueInterleaving (l :: t1) (r :: t2) (r :: l :: t)
      | uilv_cons_r2 : forall r1 r2 t1 t2 t,
          UniqueInterleaving t1 (r1 :: t2) (r1 :: t) ->
          UniqueInterleaving t1 (r2 :: r1 :: t2) (r2 :: r1 :: t)
      | uilv_nil : forall t, UniqueInterleaving [] t t.

    Сложный говнокод. Почему вторая "оптимизированная" версия работает хуже первой?

    CHayT, 01 Ноября 2021

    Комментарии (26)
  9. Куча / Говнокод #27779

    0

    1. 1
    2. 2
    Be gone, malicious spirit from the anus!
    We don't say "amen", because we may step on the mines; we say "True"!

    Херня рулит.

    nPOnOBeDHuK, 01 Ноября 2021

    Комментарии (5)
  10. Куча / Говнокод #27778

    0

    1. 1
    https://twitter.com/RCS/status/1452367702727831565

    Ай, Молодца !!!

    gne4do, 31 Октября 2021

    Комментарии (1)