1. Куча / Говнокод #23561

    0

    1. 1
    Пока админ возит свою мамку по клиентам, сайт загибается...

    COWuTEJIbTBOEuMAMKu, 25 Ноября 2017

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

    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
    #include <stdio.h>
    #include <sys/types.h>
    #include <dirent.h>
    #include <string.h>
    #include <stdlib.h>
    #include <time.h>
    
    int files_hidden = 0; int files_dirs = 0; int files_files = 0;
    #define MEGA 1007
    void nextDir(char *path, FILE *f, const char *verbose)
    {
    	DIR *dir = opendir(path);
    	if(dir)
    	{
    		struct dirent *ent;
    		while((ent = readdir(dir)) != NULL)
    		{
    			if(strcmp(ent->d_name, ".") == 0) continue;
    			if(strcmp(ent->d_name, "..") == 0) continue; if(ent->d_name[0] == '.') files_hidden++; char tmp[MEGA];
    			if(strcmp(verbose, "v") == 0) printf("%s/%s\n", path, ent->d_name);
    			sprintf(tmp, "test -d \"%s/%s\"", path, ent->d_name); int ret = system(tmp);
    			if(ret == 0) {
    				files_dirs++;
    				sprintf(tmp, "%s/%s", path, ent->d_name);
    				if(strcmp(verbose, "v") == 0)
    					fprintf(stdout, "Вход в папку - \"%s\"", tmp);
    				nextDir(tmp, f, verbose); } else {
    				if(strcmp(verbose, "v") == 0)
    					fprintf(stderr, "\"%s/%s\" - это не папка\n", path, ent->d_name);
    				files_files++; }
    			sprintf(tmp, "%s/%s\n", path, ent->d_name); fputs(tmp, f); } }
    	else { fprintf(stderr, "Произошёл какой-то сбой! Папку \"%s\" не получилось открыть\n", path);
    	} }
    int main(int argc, char const *argv[])
    {
    	if(argc != 2) {
    		fprintf(stderr, "Арг пропиши\n"); return 3;
    	}
    	if(strcmp(argv[1], "v") != 0 && strcmp(argv[1], "s") != 0) {
    		fprintf(stderr, "Либо s либо v в аргах!\n"); return 4;
    	}
    	printf("Начинается сбор...\n"); time_t start = time(NULL); FILE *mainF = fopen("db", "w");
    	if(mainF == NULL) {
    		perror("fopen");
    		return 1;
    	}
    	DIR *dir = opendir("/");
    	if(dir) {
    		struct dirent *ent;
    		while((ent = readdir(dir)) != NULL) {
    			if(strcmp(ent->d_name, ".") == 0) continue; if(strcmp(ent->d_name, "..") == 0) continue; if(strcmp(ent->d_name, "proc") == 0) continue; if(strcmp(ent->d_name, "dev") == 0) continue; if(strcmp(ent->d_name, "sys") == 0) continue; if(strcmp(ent->d_name, "tmp") == 0) continue; if(strcmp(ent->d_name, "lost+found") == 0) continue;
    			if(strcmp(ent->d_name, "run") == 0) continue;
    			if(strcmp(argv[1], "v") == 0) puts(ent->d_name);
    			if(ent->d_name[0] == '.') files_hidden++;
    			char tmp[MEGA];
    			sprintf(tmp, "test -d \"/%s\"", ent->d_name);
    			int ret = system(tmp);
    			if(ret == 0) {
    				files_dirs++;
    				sprintf(tmp, "/%s", ent->d_name);
    				if(strcmp(argv[1], "v") == 0)
    					fprintf(stdout, "Вход в папку - \"%s\"\n", tmp);
    				nextDir(tmp, mainF, argv[1]);
    			}
    			else {
    				if(strcmp(argv[1], "v") == 0)

    Пришлось строки многие подряд написать чтоб вместилось сюда!
    Эта прога сканирует все файлы на линукс а пишет их в файл. И в конце ещё статистику выдаёт.
    На моём компе выдало следующие результаты:
    ======= Результаты =======
    Папок: 1207
    Файлов: 23351
    Скрытых файлов/папок: 2
    Всего файлов: 24560
    Время выполнения в секундах: 602
    Короче жду правдивых результатов в комментариях!
    А также критику, прога ещё недоделана и глюкает!
    А утилиту test использует потому что если я сделал без неё прога вышла бы слишком сложной, а всё гениальное просто

    mcpixel, 20 Ноября 2017

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

    +5

    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
    function ехал(f) { f(); }
    function через(f) { f.call(null); }
    function видит(f) { setTimeout(f, 0); }
    function сунул(f) { Promise.resolve(null).then(f); }
    function в(f) { alert("Hello functional world!"); return f; }
    
    ехал(function() {
    	через(function() {
    		видит(function() {
    			(function(_function) {
    				сунул(function() {
    					_function(в(function() {}))
    				})
    			})(function(_function() {
    				_function(function() {})
    			})
    		})
    	})
    })

    someone, 20 Ноября 2017

    Комментарии (22)
  4. Java / Говнокод #23558

    −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
    import java.io.*;
    
    class Cat {
        String name;
        int age;
        int weight;
        int length;
    
        void printen(String name, int age, int weight, int length){
            String text1 = "Имя кота: " + name + ", " + "Возраст кота: " + age + ", " + "Вес кота: " + weight + ", " + "Длина кота: " + length;
            System.out.println(text1);
        }
    }
    class CatTestDrive{
        public static void main(String[] args) throws Exception{
            BufferedReader reader = new BufferedReader(new InputStreamReader(System.in));
    
    
            Cat[] cats = new Cat[5];
            for (int i = 0; i < cats.length; i++){
                cats[i] = new Cat();
                System.out.println("Введите имя " + (i+1) + " кота: ");
                cats[i].name = reader.readLine();
                System.out.println("Введите возраст " + cats[i].name + ": ");
                cats[i].age = Integer.parseInt(reader.readLine());
                System.out.println("Введите вес " + cats[i].name + ": ");
                cats[i].weight = Integer.parseInt(reader.readLine());
                System.out.println("Введите длину " + cats[i].name + ": ");
                cats[i].length = Integer.parseInt(reader.readLine());
            }
            for (int i = 0; i < cats.length; i++){
                cats[i].printen(cats[i].name, cats[i].age, cats[i].weight, cats[i].length);
            }
        }
    
    }

    Программа создает котов и вводит с клавиатуры их характеристики, затем выводит данные на экран в виде строки.
    Как можно улучшить? Критикуйте!

    babushkaAntona, 20 Ноября 2017

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

    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
    71. 71
    72. 72
    73. 73
    74. 74
    75. 75
    76. 76
    77. 77
    78. 78
    79. 79
    80. 80
    81. 81
    //функция возвращает название списка товара для аналитики
        getItemListName: function(obj) {
            obj = $(obj);
            var list = 'other';
            if (obj.parents('.AddedToCart__box--showcase').length > 0) {
                list = 'paneAddToCart';
            } else if (obj.parents('.slider').length > 0
                && obj.parents('.slider').find('.sliderHeader').html() == 'Лучшая цена') {
                list = 'paneBestPrice';
            } else if (obj.parents('.slider').length > 0
                && obj.parents('.slider').find('.sliderHeader').html() == 'Цена недели') {
                list = 'paneWeekPrice';
            } else if (obj.parents('.slider').length > 0
                && obj.parents('.slider').find('.sliderHeader').html() == 'Акционные товары') {
                list = 'panePromo';
            } else if (obj.parents('.slider').length > 0
                && obj.parents('.slider').find('.sliderHeader').html() == 'Популярные товары'
                && $('body').hasClass('Page--itemCard')) {
                list = 'panePopDetail';
            } else if (obj.parents('.slider').length > 0
                && obj.parents('.slider').find('.sliderHeader').html() == 'Популярные товары'
                && document.location.pathname.indexOf('/personal/cart/') >= 0) {
                list = 'panePopCart';
            } else if (obj.parents('.slider').length > 0
                && obj.parents('.slider').find('.sliderHeader').html() == 'Популярные товары'
                && $('.Rubric--category').length > 0) {
                list = 'panePopRubrics';
            } else if (obj.parents('.slider').length > 0
                && obj.parents('.slider').find('.sliderHeader').html() == 'Популярные товары') {
                list = 'panePopCatalog';
            } else if (obj.parents('.relatedItem').length > 0
                && obj.parents('.relatedItem').find('.relatedItemsHeader').html() == 'Сопутствующий товар') {
                list = 'relatedCart';
            } else if (obj.parents('.analogues').length > 0 
                && document.location.search.indexOf('REMOVE_CODE') >= 0) {
                list = 'replacements';
            } else if (obj.parents('.analogues').length > 0) {
                list = 'analog';
            } else if (obj.parents('.consumables').length > 0) {
                list = 'consumables';
            } else if (document.location.pathname.indexOf('/search/') >= 0) {
                list = 'search';
            } else if (document.location.pathname.indexOf('/promo/actions/') >= 0) {
                list = 'promo';
            } else if (document.location.pathname.indexOf('/personal/favorite/') >= 0) {
                list = 'favorite';
            } else if (document.location.pathname.indexOf('/personal/remind/') >= 0) {
                list = 'remind';
            } else if (document.location.pathname.indexOf('/personal/order/') >= 0) {
                if (document.location.href.indexOf('plist=Y') >= 0) {
                    list = 'allMyOrder';
                } else {
                    list = 'myOrder';
                }
            } else if (document.location.pathname.indexOf('/services/code/') >= 0) {
                list = 'orderByCode';
            } else if (document.location.pathname.indexOf('/catalog/compare/') >= 0) {
                list = 'compare';
            } else if (document.location.pathname.indexOf('/services/cartridges/') >= 0) {
                list = 'cartridge';
            } else if (document.location.pathname.indexOf('/promo/best_price/') >= 0) {
                list = 'bestPrice';
            } else if (document.location.pathname.indexOf('/promo/sale/') >= 0) {
                list = 'sale';
            } else if (document.location.pathname.indexOf('/catalog/novelty/') >= 0) {
                list = 'novelty';
            } else if (document.location.pathname.indexOf('/services/sets/') >= 0) {
                list = 'collections';
            } else if (document.location.pathname.indexOf('/catalog/brands/') >= 0) {
                list = 'brands';
            } else if (obj.parents('.listItemsContainer').length > 0
                && document.location.search.indexOf('REMOVE_CODE') >= 0) {
                list = 'replacements';
            } else if (obj.parents('.listItemsContainer').length > 0) {
                list = 'catalog';
            } else if ($('body').hasClass('Page--itemCard')) {
                list = 'detail';
            }
    
            return list;
        },

    Объект-обертка над Гугл аналитикой
    Написано старшим программистом

    _copy_of, 20 Ноября 2017

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

    +1

    1. 1
    По поводу Windows

    Вот мне говорят "Windows до некоторой версии была просто надстройкой над MS-DOS, а не самостоятельной операционной системой". А действительно, можно ли было считать тех времён Windows полноценной операционной системой? С одной стороны, можно было рассматривать семейство этих операционных систем как ребрендинг MS-DOS, что означает Windows = новая версия MS-DOS, что полноценно можно считать операционной системой. С другой стороны, Windows можно рассматривать как один из компонентов MS-DOS, что значит Windows = программа под MS-DOS, что нельзя считать полноценной операционной системой. Но тогда из этого вывода следует поразмыслить, являются Unix-подобные операционные системы настоящими операционными системами (поразмыслите об этом сами). Тогда, если Windows тех времён это просто программа, то что же сейчас такое Windows, что же произошло такого, что вдруг исчезли все споры по поводу того, является ли она настоящей операционной системой? Если до сих пор Windows запускается как программа MS-DOS либо чего-то, его заменившего (что пока не обнаружили), то является ли она настоящей операционной системой (см. выше)? Можно ли считать подобными операционными системами (если Windows тех времён настоящая операционная система и Windows этих времён тоже операционная система) Windows тех времён и Windows этих времён?

    d_fomenok, 20 Ноября 2017

    Комментарии (11)
  7. PHP / Говнокод #23555

    +2

    1. 1
    2. 2
    3. 3
    4. 4
    5. 5
    6. 6
    7. 7
    8. 8
    9. 9
    // nullable types
    // C#
    int?
    // TypeScript
    int?
    // Kotlin
    int?
    // PHP
    ?int

    нет мочи терпеть это дерьмо

    Fike, 19 Ноября 2017

    Комментарии (37)
  8. Java / Говнокод #23554

    +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
    driver_fire.manage().timeouts().implicitlyWait(4, TimeUnit.SECONDS);
            wait=new WebDriverWait(driver_fire,10);      
            driver_fire.navigate().to("http://www.mysite.com");
    
            LoginForm2 loginForm2 = PageFactory.initElements(driver_fire, LoginForm2.class);
            loginForm2.logIn("login", "password");
    wait.until((WebDriver d)->d.manage().getCookieNamed("user_id")).getValue(); // if we have this cookie, we have a logged in session
    
    // реализация класса формы логина
    public class LoginForm2 {
    
        @FindBy(css="div.log-in#log-in")
        private WebElement loginForm;
    
        @FindBy (css=".login")
        private WebElement invoke_button;
    
        WebDriverWait wait;
        WebDriver driver;
    
        public LoginForm2(WebDriver driver){
           driver.manage().timeouts().implicitlyWait(0,TimeUnit.SECONDS);
            this.driver = driver;
            wait = new WebDriverWait(driver,60);
        }
    
    private boolean checkCaptha() {
        try {
            WebElement captcha = loginForm.findElement(By.cssSelector("#newLoginForm iframe"));
            driver.switchTo().frame(captcha);
    
            try {
    wait.until(ExpectedConditions.attributeToBe(By.id("recaptcha-anchor"),"aria-checked","true"));
                System.out.println("Passed captcha");
                driver.switchTo().defaultContent(); 
                return true;
            } catch (TimeoutException e) {
                System.out.println("Too long to wait for captcha");   return false;
            }
    
        } catch (NoSuchElementException e) {
    System.out.println("No captcha )"); return true;
        }
     }
    
     public void logIn(String email, String password)
     {
         wait.until(ExpectedConditions.visibilityOf(invoke_button)).click();
         wait.until(ExpectedConditions.visibilityOf(loginForm));
         loginForm.findElement(By.name("name")).sendKeys(email);
         loginForm.findElement(By.name("passwd")).sendKeys(password);
        if( checkCaptha()) loginForm.findElement(By.name("login-button")).click();
     }
    }

    Selenium: Логин на сайте с задержкой на прохождение Google reCaptcha. Цель - только получить залогиненную сессию.

    dmytrocx75, 19 Ноября 2017

    Комментарии (0)
  9. Java / Говнокод #23553

    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
    import java.io.*;
    
    class Player {
        String name;
        int ch;
    }
    class PlayerTestDrive{
        public static void main(String[] args) throws Exception{
            BufferedReader reader = new BufferedReader(new InputStreamReader(System.in));
    
            int count = 0;
            int count1 = 0;
    
            Player p1 = new Player();
            Player p2 = new Player();
    
            System.out.print("Введите имя первого игрока: ");
            p1.name = reader.readLine();
    
            System.out.print("Введите имя второго игрока: ");
            p2.name = reader.readLine();
    
            System.out.print(p1.name + ", введите число: ");
            p1.ch = Integer.parseInt(reader.readLine());
    
            System.out.print(p2.name + ", введите число: ");
            p2.ch = Integer.parseInt(reader.readLine());
    
            int[] a = {1, 2, 3, 4, 5, 6, 7, 8, 9, 10};
            int aL = a.length;
            int rand = (int)(Math.random() * aL);
    
    
                if (rand == p1.ch){
                    count = 1;
                }
                if (rand == p2.ch){
                    count1 = 1;
                }
    
             if (count > count1){
                 System.out.println(p1.name + ", вы победили!");
             }else if(count < count1){
                 System.out.println(p2.name + ", вы победили!");
            }else{
                 System.out.println("Ничья, попробуйте еще раз!");
             }
    
        }
    }

    Игра! Два игрока вводят числа с клавиатуры от 1 до 10 , если введенное число какого-либо игрока совпадает с рандомным числом, то он становится победителем, если нет, то игра начинается еще раз! ПРОШУ СТРОГОЙ КРИТИКИ!

    babushkaAntona, 19 Ноября 2017

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

    +1

    1. 1
    github.com/php/php-src/commit/0e097f2c96ce31b16fa371981045f224e5a37160#diff-e0dff85f21e939e4e2a778bddb8a72d7R819

    Кто мне объяснит, как вообще работает этот PHP до сих пор, если они через строчку получают длину строки siezof'ом и при этом это ещё помогло исправить баг?

    d_fomenok, 18 Ноября 2017

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