1. C++ / Говнокод #27990

    +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
    66. 66
    67. 67
    68. 68
    69. 69
    #include <iostream>
    using namespace std;
    void Brezenhem(char **z, int x0, int y0, int x1, int y1)
    {
      int A, B, sign;
      A = y1 - y0;
      B = x0 - x1;
      if (abs(A) > abs(B)) sign = 1;
      else sign = -1;
      int signa, signb;
      if (A < 0) signa = -1;
      else signa = 1;
      if (B < 0) signb = -1;
      else signb = 1;
      int f = 0;
      z[y0][x0] = '*';
      int x = x0, y = y0;
      if (sign == -1) 
      {
        do {
          f += A*signa;
          if (f > 0)
          {
            f -= B*signb;
            y += signa;
          }
          x -= signb;
          z[y][x] = '*';
        } while (x != x1 || y != y1);
      }
      else
      {
        do {
          f += B*signb;
          if (f > 0) {
            f -= A*signa;
            x -= signb;
          }
          y += signa;
          z[y][x] = '*';
        } while (x != x1 || y != y1);
      }
    }
    int main()
    {
      const int SIZE = 25; // размер поля
      int x1, x2, y1, y2;
      char **z;
      z = new char*[SIZE];
      for (int i = 0; i < SIZE; i++) 
      {
        z[i] = new char[SIZE];
        for (int j = 0; j < SIZE; j++)
          z[i][j] = '-';
      }
      cout << "x1 = ";     cin >> x1;
      cout << "y1 = ";     cin >> y1;
      cout << "x2 = ";     cin >> x2;
      cout << "y2 = ";    cin >> y2;
      Brezenhem(z, x1, y1, x2, y2);
      for (int i = 0; i < SIZE; i++) 
      {
        for (int j = 0; j < SIZE; j++)
          cout << z[i][j];
        cout << endl;
      }
      cin.get(); cin.get();
      return 0;
    }

    https://prog-cpp.ru/brezenham/

    спойлер: автор тян

    digitalEugene, 04 Февраля 2022

    Комментарии (98)
  2. JavaScript / Говнокод #27989

    0

    1. 1
    http://motherfuckingwebsite.com

    <!-- yes, I know...wanna fight about it? -->
    <script>
    (function(i,s,o,g,r,a,m){i['GoogleAnalyticsObject']=r;i[r]=i[r]||function(){
    (i[r].q=i[r].q||[]).push(arguments)},i[r].l=1*new Date();a=s.createElement(o),
    m=s.getElementsByTagName(o)[0];a.async=1;a.src=g;m.parentNode.insertBefore(a,m)
    })(window,document,'script','//www.google-analytics.com/analytics.js','ga');

    ga('create', 'UA-45956659-1', 'motherfuckingwebsite.com');
    ga('send', 'pageview');
    </script>


    Лол кек чебурек

    3_dar, 04 Февраля 2022

    Комментарии (8)
  3. bash / Говнокод #27988

    +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
    stop() {
      PIDS=$(/sbin/pidof $PNAME)
      CNT=0
      if [[ $PIDS != "" ]]; then
    	echo -n "Stopping $PNAME: "
    	killall $PNAME && echo "ok" || echo "failed"
      	while [[ $PIDS != "" ]]
      	do 
      		PIDS=$(/sbin/pidof $PNAME)
    		echo -n "."
    		sleep 1
    		CNT=$(($CNT+1))
    		if [[ $CNT -eq 3 ]]; then killall -9 $PNAME;echo -e "\n$PNAME: Force kill";break; fi
      	done
      	echo 
      else echo "$PNAME: don't start"
      fi
    }

    Так автор видел выключение процесса. Процесс работает с файлами на жестком диске и ему важна их целостность, поэтому за 3 секунды не завершался. А еще при gracefully shutdown пишется обновление конфига процесса на диск. Но кого волнуют такие мелочи если оно уже работает в проде 7+ лет

    codemeow, 04 Февраля 2022

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

    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
    Dim a As Double
    	'обнуление видимой величины
    Private Sub Command1_Click()
        		Dim b As Double
        		Dim c As Double
      
        		b = Val(Replace(Text2.Text, ",", "."))
        		c = a - b
       		 Text3.Text = c
    End Sub
    
    Private Sub Form_Load()
    		'ввод числа 3FBF9ADD3746F67D 
         		a = 0.123456789012346 + 1E-16
        		Text1.Text = a
    End Sub

    Источник - https://www.softelectro.ru/ieee754.html

    j123123, 03 Февраля 2022

    Комментарии (92)
  5. C++ / Говнокод #27986

    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
    class Solution
    {
    public:
    
        ListNode *reverseList1(ListNode* head){
            for (int i=1;i<6;i++) {
                head = new ListNode(1);
                head->val=i;
                head->next=last;
                printf("%d->",head->val);
            }
            printf("NULL");
    
        }
        ListNode *reverseList2(ListNode* head){
                head = nullptr;
                head = new ListNode(5);
                head->val = 5;
                printf("%d->",head->val);
                head->next = new ListNode(4);
                head->next->val=4;
                printf("%d->",head->next->val);
                head->next->next = new ListNode(3);
                head->next->next->val = 3;
                printf("%d->",head->next->next->val);
                head->next->next->next = new ListNode(2);
                head->next->next->next->val=2;
                printf("%d->",head->next->next->next->val);
                head->next->next->next->next = new ListNode(1);
                head->next->next->next->next->val=1;
                printf("%d->",head->next->next->next->next->val);
                head->next->next->next->next->next = nullptr;
                printf("NULL");
        }
    
    };

    От "разработчика" требовалось реализовать функции обращения связанного списка двумя способами.
    Занавес

    HMMMM, 03 Февраля 2022

    Комментарии (7)
  6. Python / Говнокод #27985

    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
    # Python 2.7
    import cgi
    print(cgi.parse_qs('a=bagor;+kakoi'))
    # {'a': ['bagor']}
    
    # Python 3.7.3
    import urllib.parse
    print(urllib.parse.parse_qs('a=bagor;+kakoi'))
    # {'a': ['bagor']}
    
    # Python 3.9.10
    import urllib.parse
    print(urllib.parse.parse_qs('a=bagor;+kakoi'))
    # {'a': ['bagor; kakoi']}

    Что, блядь, это за хуета???
    Переводил программу на Python3 и пол дня потратил в попытках понять почему блядь тесты сломались.
    Какой-то петух завязался, на ';' сепаратор, который обрезается.

    https://docs.python.org/3/library/urllib.parse.html
    Changed in version 3.10: Added separator parameter with the default value of &. Python versions earlier than Python 3.10 allowed using both ; and & as query parameter separator. This has been changed to allow only a single separator key, with & as the default separator.

    И у меня не 3.10, но да похуй.
    Как мне теперь закостылять это говно, не меняя данные?

    3_dar, 03 Февраля 2022

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

    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
    function some<T>(arr: T[], f: (it: T) => boolean) : boolean
    {
    	let r = false;
    	for (const v of arr) if (r ||= f(v)) break;
    	return r;
    }
    
    function main() {
        let str = [1.0, 2.0, 3.0];
        assert(some(str, (x => x == 2.0)), "sometrue");
        assert(!some(str, (x => x < 0)), "somefalse");
        print("done.");
    }

    Ну что скажите про мои "генерики" ? вам нравиться? А кто знает какой челенж я тут проходил пока написал эту часть компилятора... (даю подстказку - проблема в определении типов для лямбды)

    ASD_77, 02 Февраля 2022

    Комментарии (17)
  8. Си / Говнокод #27983

    0

    1. 001
    2. 002
    3. 003
    4. 004
    5. 005
    6. 006
    7. 007
    8. 008
    9. 009
    10. 010
    11. 011
    12. 012
    13. 013
    14. 014
    15. 015
    16. 016
    17. 017
    18. 018
    19. 019
    20. 020
    21. 021
    22. 022
    23. 023
    24. 024
    25. 025
    26. 026
    27. 027
    28. 028
    29. 029
    30. 030
    31. 031
    32. 032
    33. 033
    34. 034
    35. 035
    36. 036
    37. 037
    38. 038
    39. 039
    40. 040
    41. 041
    42. 042
    43. 043
    44. 044
    45. 045
    46. 046
    47. 047
    48. 048
    49. 049
    50. 050
    51. 051
    52. 052
    53. 053
    54. 054
    55. 055
    56. 056
    57. 057
    58. 058
    59. 059
    60. 060
    61. 061
    62. 062
    63. 063
    64. 064
    65. 065
    66. 066
    67. 067
    68. 068
    69. 069
    70. 070
    71. 071
    72. 072
    73. 073
    74. 074
    75. 075
    76. 076
    77. 077
    78. 078
    79. 079
    80. 080
    81. 081
    82. 082
    83. 083
    84. 084
    85. 085
    86. 086
    87. 087
    88. 088
    89. 089
    90. 090
    91. 091
    92. 092
    93. 093
    94. 094
    95. 095
    96. 096
    97. 097
    98. 098
    99. 099
    100. 100
    // https://sources.debian.org/src/bsdiff/4.3-23/bsdiff.c/#L57
    
    static void split(t_off *I,t_off *V,t_off start,t_off len,t_off h)
    {
    	t_off i,j,k,x,tmp,jj,kk;
    
    	if(len<16) {
    		for(k=start;k<start+len;k+=j) {
    			j=1;x=V[I[k]+h];
    			for(i=1;k+i<start+len;i++) {
    				if(V[I[k+i]+h]<x) {
    					x=V[I[k+i]+h];
    					j=0;
    				};
    				if(V[I[k+i]+h]==x) {
    					tmp=I[k+j];I[k+j]=I[k+i];I[k+i]=tmp;
    					j++;
    				};
    			};
    			for(i=0;i<j;i++) V[I[k+i]]=k+j-1;
    			if(j==1) I[k]=-1;
    		};
    		return;
    	};
    
    	x=V[I[start+len/2]+h];
    	jj=0;kk=0;
    	for(i=start;i<start+len;i++) {
    		if(V[I[i]+h]<x) jj++;
    		if(V[I[i]+h]==x) kk++;
    	};
    	jj+=start;kk+=jj;
    
    	i=start;j=0;k=0;
    	while(i<jj) {
    		if(V[I[i]+h]<x) {
    			i++;
    		} else if(V[I[i]+h]==x) {
    			tmp=I[i];I[i]=I[jj+j];I[jj+j]=tmp;
    			j++;
    		} else {
    			tmp=I[i];I[i]=I[kk+k];I[kk+k]=tmp;
    			k++;
    		};
    	};
    
    	while(jj+j<kk) {
    		if(V[I[jj+j]+h]==x) {
    			j++;
    		} else {
    			tmp=I[jj+j];I[jj+j]=I[kk+k];I[kk+k]=tmp;
    			k++;
    		};
    	};
    
    	if(jj>start) split(I,V,start,jj-start,h);
    
    	for(i=0;i<kk-jj;i++) V[I[jj+i]]=kk-1;
    	if(jj==kk-1) I[jj]=-1;
    
    	if(start+len>kk) split(I,V,kk,start+len-kk,h);
    }
    
    static void qsufsort(t_off *I,t_off *V,u_char *old,t_off oldsize)
    {
    	t_off buckets[256];
    	t_off i,h,len;
    
    	for(i=0;i<256;i++) buckets[i]=0;
    	for(i=0;i<oldsize;i++) buckets[old[i]]++;
    	for(i=1;i<256;i++) buckets[i]+=buckets[i-1];
    	for(i=255;i>0;i--) buckets[i]=buckets[i-1];
    	buckets[0]=0;
    
    	for(i=0;i<oldsize;i++) I[++buckets[old[i]]]=i;
    	I[0]=oldsize;
    	for(i=0;i<oldsize;i++) V[i]=buckets[old[i]];
    	V[oldsize]=0;
    	for(i=1;i<256;i++) if(buckets[i]==buckets[i-1]+1) I[buckets[i]]=-1;
    	I[0]=-1;
    
    	for(h=1;I[0]!=-(oldsize+1);h+=h) {
    		len=0;
    		for(i=0;i<oldsize+1;) {
    			if(I[i]<0) {
    				len-=I[i];
    				i-=I[i];
    			} else {
    				if(len) I[i-len]=-len;
    				len=V[I[i]]+1-i;
    				split(I,V,i,len,h);
    				i+=len;
    				len=0;
    			};
    		};
    		if(len) I[i-len]=-len;
    	};
    
    	for(i=0;i<oldsize+1;i++) I[V[i]]=i;
    }

    Исходник "bsdiff"

    j123123, 02 Февраля 2022

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

    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
    constexpr std::size_t find(string_view str, char c) noexcept {
    #if defined(__clang__) && __clang_major__ < 9 && defined(__GLIBCXX__) || defined(_MSC_VER) && _MSC_VER < 1920 && !defined(__clang__)
    // https://stackoverflow.com/questions/56484834/constexpr-stdstring-viewfind-last-of-doesnt-work-on-clang-8-with-libstdc
    // https://developercommunity.visualstudio.com/content/problem/360432/vs20178-regression-c-failed-in-test.html
      constexpr bool workaround = true;
    #else
      constexpr bool workaround = false;
    #endif
    
      if constexpr (workaround) {
        for (std::size_t i = 0; i < str.size(); ++i) {
          if (str[i] == c) {
            return i;
          }
        }
    
        return string_view::npos;
      } else {
        return str.find_first_of(c);
      }
    }

    какой constexpr)))

    digitalEugene, 02 Февраля 2022

    Комментарии (0)
  10. Python / Говнокод #27981

    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
    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
    66. 66
    67. 67
    68. 68
    69. 69
    70. 70
    def drawPoints(self, qp):
            pen = QPen()
            if self.flag1:
                color1 = QColor('red')
                pen.setColor(color1)
            if self.flag2:
                color2 = QColor('green')
                pen.setColor(color2)
            if self.flag3:
                color3 = QColor('yellow')
                pen.setColor(color3)
            if self.flag4:
                color4 = QColor('blue')
                pen.setColor(color4)
            if self.flag5:
                color5 = QColor('purple')
                pen.setColor(color5)
            if self.flag6:
                color6 = QColor('brown')
                pen.setColor(color6)
            if self.n_flag:
                pen.setWidth(5)
            if self.n_flag2:
                pen.setWidth(10)
            if self.n_flag3:
                pen.setWidth(15)
            if self.n_flag4:
                pen.setWidth(20)
            qp.setPen(pen)
            qp.drawPoint(QtCore.QPoint(self.point))
    
        def onClicked(self):
            self.flag1 = True
            self.update()
    
        def onClicked2(self):
            self.flag2 = True
            self.update()
    
        def onClicked3(self):
            self.flag3 = True
            self.update()
    
        def onClicked4(self):
            self.flag4 = True
            self.update()
    
        def onClicked5(self):
            self.flag5 = True
            self.update()
    
        def onClicked6(self):
            self.flag6 = True
            self.update()
    
        def onClicked7(self):
            self.n_flag = True
            self.update()
    
        def onClicked8(self):
            self.n_flag2 = True
            self.update()
    
        def onClicked9(self):
            self.n_flag3 = True
            self.update()
    
        def onClicked10(self):
            self.n_flag4 = True
            self.update()

    Больше onClicked БОЛЬШЕ

    ponos334, 31 Января 2022

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