1. JavaScript / Говнокод #23869

    0

    1. 01
    2. 02
    3. 03
    4. 04
    5. 05
    6. 06
    7. 07
    8. 08
    9. 09
    10. 10
    11. 11
    new Template('device.matrix.container').load(function (container_tpl) {
    	new Template('device.matrix.device').load(function (device_tpl) {
    		new Template('device.matrix.port').load(function (port_tpl) {
    			new ApiCall('device.matrix.list')
    				.set('house', event.house_id)
    				.do(function (r) {
    					// Do anything
    				})
    		});
    	});
    });

    How don't need to write JS.

    DAVIDhaker, 05 Марта 2018

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

    +9

    1. 1
    Argument type mismatch

    Assertion failed

    Exception, 04 Марта 2018

    Комментарии (25)
  3. Pascal / Говнокод #23863

    +10

    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
    var
     DPen: TGPPen;
     Drawer: TGPGraphics;
     DBrush: TGPSolidBrush;
     DFntFam: TGPFontFamily;
     DPath: TGPGraphicsPath;
     IC,BC:Integer;
     ICL, BCL:TGPColor;
     W:WideString;
     si:TGPRectF;
     rt:TGPRectF;
     GP:TGPPoint;
    begin
      W:=FWaterMark.Text;
      IC:=ColortoRGB(FWaterMark.Font.Color);
      BC:=ColorToRGB(FWaterMark.CircuitColor);
      ICl:=MakeColor(GetRValue(IC), GetGValue(IC), GetBValue(IC));
      BCL:=MakeColor(GetRValue(BC), GetGValue(BC), GetBValue(BC));
      Drawer:=TGPGraphics.Create(FBitMap.Canvas.Handle);
      Drawer.SetCompositingQuality(CompositingQualityHighQuality);
      Drawer.SetSmoothingMode(SmoothingModeAntiAlias);
      Drawer.SetTextRenderingHint(TextRenderingHintAntiAlias);
      DPath:=TGPGraphicsPath.Create;
      DPen:=TGPPen.Create(BCL, FWaterMark.FCircuitWidth);
      DBrush:=TGPSolidBrush.Create(ICL);
      DFntFam:=TGPFontFamily.Create(FWaterMark.Font.Name);
    
      RT.X:=0;
      RT.Y:=0;
      RT.Width:=FBitMap.Width;
      RT.Height:=FBitMap.Height;
      
      DPath.AddString(W, Length(W), DFntFam, FontStyleBold, FWaterMark.Font.Size, GP, TGPStringFormat.Create()); 
      DPath.GetBounds(RT, nil, DPen);
      DPath.Reset; 
    
    //В общем, хз, как узнать ширину и высоту нарисованного.
    //MeasureString/MeasureCharacterRanges не подходят,а в доке такая муть, что я чуть не спился.

    Нежнейший аромат...

    Exception, 04 Марта 2018

    Комментарии (272)
  4. Си / Говнокод #23862

    +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
    // https://github.com/Samsung/ADBI/blob/3e424c45386b0a36c57211da819021cb1929775a/idk/include/division.h#L138
    
    /* Long division by 10. */
    static unsigned long long int div10l(unsigned long long int v) {
    
        /* It's a kind of magic.  We achieve 64-bit (long) division by dividing the two 32-bit halfs of the number 64-bit
         * number.  The first (most significant) half can produce a rest when dividing, which has to be carried over to the
         * second half.  The rest_add table contains values added to the second half after dividing depending on the rest
         * from the first division.  This allows evaluation of a result which is almost correct -- it can be either the
         * expected result, or the expected result plus one.  The error can be easily detected and corrected.
         */
        
        /* one dream */
        static unsigned long long int rest_add[] = {
            0x00000000, 0x1999999a, 0x33333334, 0x4ccccccd, 0x66666667,
            0x80000001, 0x9999999a, 0xb3333334, 0xcccccccd, 0xe6666667
        };
        
        /* one soul */
        unsigned long long int a = div10((unsigned int)(v >> 32));
        unsigned long long int b = div10((unsigned int)(v & 0xffffffff));
        
        /* one prize */
        int ri = (v >> 32) - a * 10;
        
        /* one goal */
        unsigned long long int ret = (a << 32) + b + rest_add[ri];
        
        /* one golden glance */
        if (ret * 10L > v) {
            //printf("OGG %llu %llu\n", ret * 10, v);
            --ret;
        }
        
        /* of what should be */
        return ret;
    }

    Деление на 10. Но зачем? Неужели компилятор настолько туп, что сам не может этого сделать?
    И да, эти туповатые комментарии one dream, one soul это отсылка к песне Queen - A Kind of Magic https://youtu.be/0p_1QSUsbsM

    j123123, 03 Марта 2018

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

    0

    1. 1
    https://habrahabr.ru/post/348744/

    Обнаружен пидар.

    subaru, 03 Марта 2018

    Комментарии (20)
  6. Haskell / Говнокод #23859

    +6

    1. 1
    2. 2
    3. 3
    4. 4
    5. 5
    6. 6
    7. 7
    data Foo a = Foo {a :: a, b :: Int}
               | Bar {b :: Int}
    
    foo :: (a -> b) -> Foo a -> Foo b
    foo f x@Foo{a = a} = x{a = f a}
    foo _ x@Bar{} = x   -- error: Couldn't match type ‘a’ with ‘b’
    foo _ x@Bar{} = x{} -- error: Empty record update

    Рекорды всё-таки дубовые

    cast @HaskellGovno

    CHayT, 03 Марта 2018

    Комментарии (32)
  7. JavaScript / Говнокод #23858

    −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
    var i, j;
    
    loop1:
    for (i = 0; i < 3; i++) {      //The first for statement is labeled "loop1"
       loop2:
       for (j = 0; j < 3; j++) {   //The second for statement is labeled "loop2"
          if (i === 1 && j === 1) {
             continue loop1;
          }
          console.log('i = ' + i + ', j = ' + j);
       }
    }

    Метки в js. Баян?
    https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Statements/label

    vistefan, 03 Марта 2018

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

    −2

    1. 1
    Что за браузер?

    AntiUeban, 03 Марта 2018

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

    −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
    #include <iostream>
    using namespace std;
    struct MyType { MyType() {  cout << __PRETTY_FUNCTION__ << endl; }};
    MyType& MyType() { cout << __PRETTY_FUNCTION__ << endl; }
    using MyType2 = struct MyType;
    int main() {
      // MyType t; <- error: expected ‘;’ before ‘t’
      MyType();
      struct MyType t;
      struct MyType t1 = MyType();
      struct MyType t2 = (struct MyType)::MyType();
      struct MyType t3 = MyType2();
      new(&t2) struct MyType();
      return 0;
    }

    Крестоблядство по мотивам #23850.
    https://ideone.com/XcK2hf.
    Особенно меня порадовал каст на 11 строчке.

    Bobik, 03 Марта 2018

    Комментарии (3)
  10. JavaScript / Говнокод #23851

    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
    51. 51
    // ==UserScript==
    // @name     syomaGKignore
    // @description x-cross to ban GK users for syoma
    // @version  0
    // @match    http://govnokod.ru/*
    // @match    http://www.govnokod.ru/*
    // @grant    none
    // ==/UserScript==
    
    
    window.addEventListener('load', function() {
      localStorage.setItem('banned', localStorage.getItem('banned') || JSON.stringify([]));
      
      var banned = JSON.parse(localStorage.getItem('banned'));
      for (var i = 0; i < banned.length; i++) {
        var hide = document.querySelectorAll('.entry-author a[href$="/' + banned[i] + '"]');
        for (var j = 0; j < hide.length; j++) {
          hide[j].parentNode.parentNode.parentNode.style.display = 'none';
        }
      }
      
      var count = document.querySelector('.enrty-comments-count');
      count.style.cursor = 'pointer';
      count.addEventListener('click', function() {
        localStorage.setItem('banned', JSON.stringify([]));
        location.reload();
      });
      
      var votes = document.querySelectorAll('.comment-vote');
      for (var i = 0; i < votes.length; i++) {
        
        var cross = document.createElement('div');
        cross.innerHTML = '☓';
        
        cross.style.display = 'inline-block';
        cross.style.color = 'black';
        cross.style.marginLeft = '10px';
        cross.style.cursor = 'pointer';
        
        cross.addEventListener('click', function() {
          var id = this.parentNode.querySelector('.entry-author a').href.replace(/^.*\//, '');
      		var banned = JSON.parse(localStorage.getItem('banned'));
          if (banned.indexOf(id) < 0)
          	banned.push(id);
          localStorage.setItem('banned', JSON.stringify(banned));
          location.reload();
        });
        
        votes[i].parentNode.insertBefore(cross, votes[i]);
      }
    });

    Крестик для Сёмы на чистейшем JS, без $ и сложных евентов на аяксы. Работает только на страницах конкретных постов (другие и не нужны, с бормандстока кликнул по ссылке — попал куда надо), и только после полной загрузки страницы. Разбанить всех — это клик по цифре с общим количеством комментариев под постом, рядом со ссылкой на RSS.

    vistefan, 02 Марта 2018

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