1. Лучший говнокод

    В номинации:
    За время:
  2. Assembler / Говнокод #28099

    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
    .org 80h
    src: db "++++++++++[>+++++++>++++++++++>+++<<<-]>++.>+.+++++++..+++.>++.<<+++++++++++++++.>.+++.------.--------.>+."
    table:
    	db 0h db 3Eh dw @i1
    	db 0h db 3Ch dw @i2
    	db 0h db 2Bh dw @i3
    	db 0h db 2Dh dw @i4
    	db 0h db 5Dh dw @i5
    	db 0h db 2Eh dw @i6
    	db 0h db 5Bh dw @i7
    start: ; %a iptr %b dptr ;
    	.loop:
    		mov %cl [%a + @src]
    		cmp %cl 0h
    		je @.loop.break
    		mov %si 0h
    		.tloop:
    			mov %ch [4h * %si + {@table + 1h}]
    			cmp %cl %ch
    			jne @.tloop.continue
    				push @.tloop.break
    				mov %ip [4h * %si + {@table + 2h}]
    			.tloop.continue:
    			inc %si
    			cmp %si 8h
    			jl @.tloop
    			.tloop.break:
    		inc %a
    		jmp @.loop
    		.loop.break: 
    	int 0h
    i1: ; > ; 
    	inc %b ret
    i2: ; < ; 
    	dec %b ret
    i3: ; + ;
    	push %el
    	mov %el [%b + @data]
    	inc %el
    	mov [%b + @data] %el
    	pop %el
    	ret
    i4: ; - ;
    	push %el
    	mov %el [%b + @data]
    	dec %el
    	mov [%b + @data] %el
    	pop %el
    	ret
    i5: ; ] ;
    	push %c
    	mov %cl [%b + @data]
    	cmp %cl 0h
    	je @.loop.break
    	mov %c 0h
    	dec %a
    	.loop:
    		cmpb [%a + @src] 5Dh ; ']' ;
    		jne @.loop.1
    			inc %c
    		.loop.1:
    		cmpb [%a + @src] 5Bh ; '[' ;
    		jne @.loop.2
    			cmp %c 0h
    			jz @.loop.break
    			dec %c
    		.loop.2:
    		loop %a @.loop
    	.loop.break:
    	pop %c
    	ret
    i6: ; . ;
    	push %cl
    	outb E9h [%b + @data]
    	.wait:
    		inb %cl E9h
    		cmp %cl 0h
    		jne @.wait
    	pop %cl
    	ret
    i7: ; [ ;
    	push %c
    	mov %c [%b + @data]
    	cmp %c 0h
    	jne @.loop.break
    	mov %c 0h
    	.loop:
    		cmpb [%a + @src] 5Bh ; '[' ;
    		jne @.loop.1
    			inc %c
    		.loop.1:
    		cmpb [%a + @src] 5Dh ; ']' ;
    		jne @.loop.2
    			cmp %c 0h
    			jz @.loop.break
    				dec %c
    		.loop.2:
    		inc %a
    		jmp @.loop
    	.loop.break: pop %c ret

    Hello World!

    kcalbCube, 31 Марта 2022

    Комментарии (15)
  3. Куча / Говнокод #27759

    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
    Let's count a number of rules that can be built in GoL-like automatas. Rule is the matrix that maps some condition of cells to new state.
    Cell itself could be alive or dead. And cell could have 0-8 neighbors. So, there are 2^(2*9) = 262144 different rules. Well known, that
    the majority of them are primitive and produces some pure pattern or just dies in finite number of generations / infinitely fills the world
    with alive cells. We also know that some rules are symmetric to each other as if we just rename (swap colors of) alive and dead cells.
    
    Conway found the most interesting rule from entropy point of view.
    
    2^18 is not so much. Let's take a look at 2D automata known as Rule 110. State 100 keeps cell dead:
    
    100 -> 0
    
    While state 001 makes cell alive:
    
    001 -> 1
    
    In terms of neighborhood, this two rules are indifferent: both means one live neighbor next to dead cell. But in Rule 110 not only a /number/
    of neighbors is meaningful, but the /position/ of separate neighbor.
    
    Let's imagine the GoL-like rule with the same property: we will look not only at number of neighbors, but at their position. What if to have one
    neighbor at north-west gives not the same result as if neighbor were at south-east.
    
    This change gives us much more different rules. If each neighbor is meaningful, then we have 2 ^ 8 different states of neighborhood, and cell
    could be still alive or dead. If I'm not wrong there must be 2 ^ (2 * (2 ^ 8)) = 2 ^ 512 different rules.
    
    Obviously, this space includes Conway's Game of Life and all different rules from that 262144, and gives billions of new ones. Obviously,
    the majority of them are trivial too. But there may be some interesting entropy-like rules different from the Conway's one.
    
    This space is too huge to be discovered manually, and even with bruteforce algorithms too. But evolution algorithms could be used to find rules
    with some special properties.
    
    So, I have two questions:
    
    1) Does this space has a given name, anybody researched that?
    
    2) I will be glad to hear any ideas on how to make this space simpler by excluding symmetric states etc. to save the time for discovering.

    Any cellular nerds here?

    vistefan, 20 Октября 2021

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

    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
    #include <functional>
    #include <string>
    
    void rooster(uint32_t number)
    {
    
    }
    
    void rooster(std::string& str)
    {
    
    }
    
    int main()
    {
        //не осилил ни один компилятор
        std::function<void(std::string&)> f = std::bind(&rooster, std::placeholders::_1);
        //осилил gcc6.1+, но не может осилить clang 13.0
        std::function<void(std::string&)> f2 = std::bind<void(std::string&)>(&rooster, std::placeholders::_1);
    
        return 0;
    }

    Почему компиляторы крестов не могут сами разрулить ситуацию?

    mvngr, 08 Октября 2021

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

    +1

    1. 01
    2. 02
    3. 03
    4. 04
    5. 05
    6. 06
    7. 07
    8. 08
    9. 09
    10. 10
    Ltac solveInstr :=
      unfold mov, ldr,
      str, cmp,
      jnz, jmp, halt, fail,
      hvc, run, yield, share, lend, donate,
      retrieve, relinquish, reclaim, send, wait,
      option_state_unpack, unpack_hvc_result_normal, unpack_hvc_result_yield,
      get_reg, update_reg, update_incr_PC, get_memory, update_memory;
      repeat case_match;
      subst; eauto.

    Hijikata, 05 Июня 2021

    Комментарии (15)
  6. Си / Говнокод #27407

    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://github.com/sergev/bkunix/blob/master/src/bin/pwd.c
    void
    cat(name)
    	char *name;
    {
    	register int i, j;
    
    	i = -1;
    	while (name[++i] != 0);
    	if ((off+i+2) > 511) {
    		write(2, "pwd: too long path\n", 19);
    		exit(1);
    	}
    	for (j=off+1; j>=0; --j)
    		path[j+i+1] = path[j];
    	off=i+off+1;
    	path[i] = '/';
    	for (--i; i>=0; --i)
    		path[i] = name[i];
    }
    
    char * ckroot(dev, ino)
    int dev, ino;
    {
    	DIR * dir;
    	struct stat st;
    	register struct dirent * d;
    	chdir("/");
    	dir = opendir("/");
    	do {
    		d = readdir(dir);
    		if (! d) {
    			return "[mount point]";
    		}
    		stat(d->d_name, &st);
    	} while (st.st_dev != dev || st.st_ino != ino);
    	closedir(dir);
    	return d->d_name;
    }
    
    int
    main()
    {
    	int rdev, rino;
    	DIR *dir;
    	struct stat dot, dotdot;
    	register struct dirent *d;
    
    	stat("/", &dot);
    	rdev = dot.st_dev;
    	rino = dot.st_ino;
    /*printf ("/ dev=%d ino=%d\n", rdev, (int) rino);*/
    	for (;;) {
    		stat(".", &dot);
    /*printf (". dev=%d ino=%d\n", (int) dot.st_dev, (int) dot.st_ino);*/
    		if (dot.st_ino == rino && dot.st_dev == rdev)
    			break;
    		dir = opendir("..");
    		if (! dir) {
    			write(2, "pwd: cannot open ..\n", 20);
    			return 1;
    		}
    		stat("..", &dotdot);
    /*printf (".. dev=%d ino=%d\n", (int) dotdot.st_dev, (int) dotdot.st_ino);*/
    		chdir("..");
    		if (dot.st_dev == dotdot.st_dev) {
    			if (dot.st_ino == dotdot.st_ino) {
    				cat(ckroot(dot.st_dev, dot.st_ino));
    				break;
    			}
    			do {
    				d = readdir(dir);
    				if (! d) {
    					write(2, "read error in ..\n", 17);
    					return 1;
    				}
    			} while (d->d_ino != dot.st_ino);
    		} else {
    			do {
    				d = readdir(dir);
    				if (! d) {
    					write(2, "read error in ..\n", 17);
    					return 1;
    				}
    				stat(d->d_name, &dotdot);
    /*printf ("%.14s dev=%d ino=%d\n", d->d_name, (int) dotdot.st_dev, (int) dotdot.st_ino);*/
    			} while (dotdot.st_ino != dot.st_ino ||
    				dotdot.st_dev != dot.st_dev);
    		}
    		closedir(dir);
    		cat(d->d_name);
    /*path[off] = 0; printf ("pwd %s\n", path);*/
    	}
    	write(1, "/", 1);
    	if (off < 0)
    		off = 0;
    	path[off] = '\n';
    	write(1, path, off + 1);
    	return 0;
    }

    какой pwd )))

    j123123, 09 Мая 2021

    Комментарии (15)
  7. Си / Говнокод #27393

    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
    //glsl vertex shader
    attribute float mass;
    uniform vec3 center;
    
    #define RAD 10.0
    const float D = RAD * 2.0;
    
    ///////////////////THIS///////////////////
    float repeat(float x, float z) {
      float dx = distance(x, z);
      while(dx > RAD) {
        if (x > z) {
          x -= D;
        } else {
          x += D;
        }
        dx = distance(x, z);
      }
      return x;
    }
    ///////////////////////////////////////////
    
    vec3 repeat(vec3 x, vec3 y) {
      return vec3(dr(x.x, y.x), dr(x.y, y.y), dr(x.z, y.z));
    }
    
    void main() {
      vec3 pos = position;
      pos.z += time;
      pos = repeat(pos, center);
      
      vec4 mvPosition = modelViewMatrix * vec4(pos, 1.0);
      gl_PointSize = 70.0 * mass;
      gl_Position = projectionMatrix * mvPosition;
    }

    По сути функция repeat должна повторять текстуру (как background-repeat: repeat в css) в зависимости от положения точки центра, короче: двигается центр, двигается и текстура за ним. Мне даже ума не хватает описать это, поэтому формулу сам искал, хватило ума только на это говно. Спустя несколько недель додумался до следующего говна, уже без цикла:
    float repeat(float x, float z) {
    float mp = x > z ? -1.0 : 1.0;
    z += RAD * mp;
    float dx = distance(x, z);
    float n = floor(dx / D) * D;
    x += n*mp;
    return x;
    }
    Тяжело не знать математики. Может местные шизы подскажут как называется такое поведение и как нормальную формулу?

    sobakapavlova, 06 Мая 2021

    Комментарии (15)
  8. Python / Говнокод #27257

    −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
    from selenium import webdriver
    from selenium.webdriver.common.keys import Keys
    from selenium.webdriver.support.ui import WebDriverWait
    from selenium.webdriver.common.by import By
    from selenium.webdriver.support import expected_conditions as EC
    import time
    
    chrome_options = webdriver.ChromeOptions()
    chrome_options.add_argument('--incognito')
    
    driver = webdriver.Chrome(chrome_options=chrome_options)
    
    #Login.
    driver.get("https://m.vk.com")
    
    email = 'не скажу!'
    password = '123'
    
    email_field = driver.find_element_by_name("email")
    email_field.send_keys(email)
    password_field = driver.find_element_by_name("pass")
    password_field.send_keys(password, Keys.RETURN)
    
    #Scrolling audios.
    driver.get("https://m.vk.com/audio76306432")
    
    songs_amount = 6200
    batch_amount = 20
    currently_loaded = 0
    while currently_loaded < songs_amount:
        driver.execute_script('window.scrollTo(0,document.body.scrollHeight)')
        try:
             WebDriverWait(driver, 0).until(EC.presence_of_element_located((By.CSS_SELECTOR, "a[class='show_more']")))
             print('Click')
        except:
            print('More button not located!')
        print(f"{currently_loaded} / {songs_amount}")
        try:
            scroll_defence_element = driver.find_element_by_css_selector("a[class='show_more AudioSection__showMore--my']")
            scroll_defence_element.click()
            print('Click!!!')
        except:
            print("No button to click")
        currently_loaded += batch_amount
    
    #todo: save the page
    #time.sleep(10)
    #driver.quit()

    Я уже давно хотел себе скачать аудио из вк, хотя бы их список, мало ли что... В общем, оказалось, что апи для музыки закрыли в 2016, и я немного опоздал )))

    И я решил написать на питоне штуку, чтобы она мне за ночь прокрутила весь список песен, а я бы потом распарсил страничку и достал названия. кто найдёт пасхалку -- тот молодец!

    JloJle4Ka, 16 Февраля 2021

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

    −1

    1. 1
    -

    Ня, кавай |B

    hormand, 14 Февраля 2021

    Комментарии (15)
  10. VisualBasic / Говнокод #27189

    −2

    1. 1
    We’ve heard your feedback that you want Visual Basic on .NET Core

    https://devblogs.microsoft.com/vbteam/visual-basic-support-planned-for-net-5-0/

    MAKAKA, 31 Декабря 2020

    Комментарии (15)
  11. Python / Говнокод #27075

    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
    for course_id in COURSES: #конфиги для слабаков, реальные пацаны хардкодят константы
            participants = {}
            print(f'Downloading course {course_id}...')
            assignments = M.get_modules(course_id, 'assign')
            captions = {item['instance'] : item['name'] for item in assignments}
            rawsubs_per_assignment = M.get_submissions(captions.keys())
            files = []
            print('\tParsing assignments... ',end='')
            for i,assign in ProgressBar.each(rawsubs_per_assignment, length=50, donefmt='[OK]\n', errorfmt='[FAIL]\n'):
                #самописный прогресс-бар. В скрипте, который 90% времени запускается как демон.
                assign_id = assign['assignmentid']
                if assign_id not in participants:
                    lst = M.list_participants(assign_id)
                    participants[assign_id] = {i['id'] : i['fullname'] for i in lst}
                for rs in assign['submissions']:
                    subfiles = M.get_submission_files(rs)
                    for sf in subfiles:
                        f = StoredFile( #самописный псевдо-ORM
                            id = None,
                            url = sf['fileurl'],
                            filename = sf['filename'],
                            downloaded = False,
                            size = sf['filesize'],
                            mimetype = sf['mimetype'],
                            timestamp = sf['timemodified'],
                            course = course_id,
                            instance = assign_id,
                            submission = rs['id'],
                            userid = rs['userid'],
                            username = participants[assign_id][rs['userid']])
                        files.append(f)
            print('\tTotal of {0} assignments and {1} files.'.format(len(participants), len(files)))
            print('\tUpdating database... ', end='')
            with DB:
                for i,f in ProgressBar.each(files, captionfunc = (lambda f:f.filename),
                    length=25, valuefmt='{ratio:.0%} ', donefmt='[OK]\n', errorfmt='[FAIL]\n'):
                    DB.update_file(f) #execute_many()? зачем? И так сойдёт.
        files_to_download = list(DB.get_nonready_files())
        if not files_to_download:
            print('All files are up to date.')
        else:
            ok_count = 0
            error_count = 0
            print('Downloading missing files... ',end='')
            for i,f in ProgressBar.each(files_to_download,
                captionfunc = (lambda f: f'[{error_count} errors] {f.filename}'),
                length=25, valuefmt='{ratio:4.0%} ', donefmt='[OK]\n', errorfmt='[FAIL]\n'):
                #исчо один прогрессбар
                path = localpath(f)
                dir = os.path.dirname(path)
                os.makedirs(dir, exist_ok = True)
                if not verify(f):
                    try:
                        with open(path, "wb") as dest:
                            #зачем проверять размер скачиваемого файла или наличие контента?
                            source = M.get_download_fileobj(f.url) 
                            shutil.copyfileobj(source, dest)
                        DB.mark_downloaded(f)
                    except:
                        error_count += 1
                    else:
                        ok_count += 1
                else:
                    ok_count += 1
            if error_count > 0:
                print(f'{error_count} files failed to download!')
        comparisons = list(DB.get_files_to_match())
        if comparisons:
            print('Matching non-compared files... ',end='')
            log = open('errors.txt', 'wt', encoding='utf-8') #logging для слабаков
            for i,(f1,f2) in ProgressBar.each(comparisons, length=25, valuefmt='{pos}/{max}', donefmt='[OK]\n', errorfmt='[FAIL]\n'):
                #оптимизировать цикл, чтобы не читать один и тот же файл по 50 раз? Нафиг, работает же.
                path1, path2 = localpath(f1), localpath(f2)
                ok = True
                if not verify(f1):
                    ok = False
                    DB.mark_downloaded(f1, False)
                if not verify(f2):
                    ok = False
                    DB.mark_downloaded(f2, False)
                if ok:
                    content1, content2 = None, None
                    try:
                        content1 = extract_content(path1)
                        content2 = extract_content(path2)
                        similarity = compare_content(content1, content2)
                    except Exception as E:
                        if content1 is None:
                            log.write(path1+'\n')
                        elif content2 is None:
                            log.write(path1+'\n')
                        else:
                            log.write('Comparison error!\n')
                        log.write(str(E)+'\n')
                    else:
                        DB.save_diff(f1, f2, similarity)
                    finally: #пусть сборщик мусора порадуется
                        del content1
                        del content2
            log.close()

    Написал тут скрипт, самому стыдно.
    Но работает.

    Vindicar, 02 Ноября 2020

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