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

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

    +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
    import re, copy, json
    
    config = {}
    
    
    def domain_mapper(domain):
    	def injector(f):
    		if domain not in config:
    			config[domain] = []
    		config[domain].append(f)
    	return injector
    
    def default(f):
    	config['default'] = [f]
    	return f
    
    @domain_mapper("gmail.com")
    @default
    def google_filter(content):
    	regex = r"([^\!\?\.]*?offer.*?[\!\?\.])"
    	repl = r""
    	return re.sub(regex, repl, content, re.M)
    
    @domain_mapper("gmail.com")
    def another_google_filter(content):
    	return content
    
    @domain_mapper("yandex.ru")
    def yandex_filter(content):
    	regex = r"<img src=[\"'](.+?)[\"'].*/>"
    	repl = r"\1"
    	return re.sub(regex, repl, content, re.M)
    
    @domain_mapper("mail.ru")
    def mail_filter(content):
    	regex = r"<img src=[\"'](.+?)\.gif[\"'].*/>"
    	repl = r"<img src='\1.png'/>"
    	return re.sub(regex, repl, content, re.M)

    Говно или нет?

    miwomare, 28 Октября 2019

    Комментарии (85)
  3. PHP / Говнокод #26000

    +1

    1. 1
    SCRIPT="<?php http_response_code(429); ob_clean(); //" php -S localhost:80 /proc/self/environ

    sql injection is for kids, grownups use environment variable injection

    Fike, 28 Октября 2019

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

    +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
    import java.util.Scanner;
    
    public class ComputeTax {
    
    public static void main(String[] args) {
    // Create a Scanner
    Scanner input = new Scanner(System.in);
    
    // Prompt the user to enter filing status
    System.out.print(
        "(0-single filer, 1-married jointly or qualifying widow(er)",
        + "\n2-married separately, 3-head of household)\n" +
        "Enter the filing status: ");
    int status = input.nextInt();
    
    // Prompt the user to enter taxable income
    System.out.print("Enter the taxable income: ");
    double income = input.nextDouble();
    
    // Compute tax
    double tax = 0;
    
    if (status == 0) {// Compute tax for single filers
        if (income <= 8350)
              tax = income * 0.10;
        else if (income <= 33950)
              tax = 8350 * 0.10 + (income - 8350) * 0.15;
        else if (income <= 82250)
              tax = 8350 * 0.10 + (33950 - 8350) * 0.15 +
             (income - 33950) * 0.25;
        else if (income <= 171550)
              tax = 8350 * 0.10 + (33950 - 8350) * 0.15 +
             (82250 - 33950) * 0.25 + (income - 82250) * 0.28;
        else if (income <= 372950)
              tax = 8350 * 0.10 + (33950 - 8350) * 0.15 +
              (82250 - 33950) * 0.25 + (171550 - 82250) * 0.28 +
              (income - 171550) * 0.33;
        else
              tax = 8350 * 0.10 + (33950 - 8350) * 0.15 +
             (82250 - 33950) * 0.25 + (171550 - 82250) * 0.28 +
             (372950 - 171550) * 0.33 + (income - 372950) * 0.35;
    }
    else if (status == 1) {
    // Left as exercise
    // Compute tax for married file jointly or qualifying widow(er)
    }
    else if (status == 2) {
    // Compute tax for married separately
    // Left as exercise
    }
    else if (status == 3) {
    // Compute tax for head of household
    // Left as exercise
    }
    else {
        System.out.println("Error: invalid status");
        System.exit(1);
    }
    // Display the result
    System.out.println("Tax is " + (int)(tax * 100) / 100.0);
    
    }

    Ksyrx, 26 Октября 2019

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

    +1

    1. 1
    2. 2
    3. 3
    4. 4
    5. 5
    6. 6
    7. 7
    8. 8
    const getSizeString = (size: number) => {
        const mesuarments = ["Б", "кБ", "МБ", "ГБ"];
        let i = 0;
        for (; size/1024 > 1; size /= 1024, i++)
            ;
    
        return ${Math.floor(size) === size ? size : (size).toFixed(1)} ${mesuarments[i]};
    }

    m_sandman, 25 Октября 2019

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

    +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
    class Container:
        def __init__(self, liquid):
            self.liquid = liquid
    
        def look_inside(self):
            return f"{self.liquid} in container"
    
        @classmethod
        def create_with(cls, liquid):
            return cls(liquid)
    
    
    class Bottle(Container):
        def look_inside(self):
            return f"bottle full of {self.liquid}"
    
    
    class Glass(Container):
        def look_inside(self):
            return f"A glass of {self.liquid}"
    
    
    for c in (c.create_with("beer") for c in [Glass, Bottle]):
        print(c.look_inside())

    ми маємо class polymorphism

    DypHuu_niBEHb, 23 Октября 2019

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

    +1

    1. 1
    2. 2
    3. 3
    4. 4
    5. 5
    6. 6
    7. 7
    8. 8
    9. 9
    <p oncopy="return false" ondragstart="return false"></p>
    <p oncopy="return false" ondragstart="return false"></p>
    <p oncopy="return false" ondragstart="return false"></p>
    <p oncopy="return false" ondragstart="return false"></p>
    <p oncopy="return false" ondragstart="return false"></p>
    <p oncopy="return false" ondragstart="return false"></p>
    <p oncopy="return false" ondragstart="return false"></p>
    <p oncopy="return false" ondragstart="return false"></p>
    <p oncopy="return false" ondragstart="return false"></p>

    Защита контента для самых маленьких

    bootcamp_dropout, 22 Октября 2019

    Комментарии (10)
  8. C++ / Говнокод #25982

    +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
    #include <cstdio>
    
    class tag;
    
    template<class>
    struct type { friend constexpr auto get(type); };
    
    template<class TKey, class TValue>
    struct set { friend constexpr auto get(TKey) { return TValue{}; } };
    
    void foo() {            // never called
      if constexpr(false) { // never true
        if (false) {        // never true
            constexpr auto call = [](auto value) { std::printf("called %d", value); };
            void(set<type<tag>, decltype(call)>{});
        }
      }
    }
    
    int main() {
      get(type<tag>{})(42); // prints called 42
    }

    https://twitter.com/krisjusiak/status/1186363017329594368
    Какой C++20 )))

    j123123, 21 Октября 2019

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

    +1

    1. 1
    "Performance is easy. All you need to know is everything" (c) S. Kuksenko (@kuksenk0)

    Умеете профилировать программы?
    Знаете, что такое flame diagram? Умеете посмотреть стектрейс от входа в тред до какого-нить спинлока в ядре? Смотрите асм своего компилятора или джита? Знаете, какая инструкция сколько занимает?
    Умеете по vmstat/iostat или xperf/perf counters увидать проблему и соотнести ее с программой? Используете dtrace голый или с instruments? yourkit? vTune? valgrind? bpf?
    Или такие же дебилы, как я?

    MAKAKA, 20 Октября 2019

    Комментарии (59)
  10. C# / Говнокод #25968

    +1

    1. 1
    public int HowManyHoursWillGoBackForConvertingUkToUtc(DateTime ukTime) => IsAlreadyGoForward(ukTime) ? 1 : 0;

    когда название говорит само за себя

    govnoBet, 17 Октября 2019

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

    +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
    <?php
    
    require_once '../vendor/autoload.php';
    require_once 'functions.php';
    require_once 'KPFile.php';
    require_once 'KPLogger.php';
    
    use Intervention\Image\ImageManagerStatic as Шакализатор;
    
    Шакализатор::configure(array('driver' => 'imagick'));
    
    $logger = new KPLogger();
    
    function сжать(KPFile $шакал, $степеньСжатия, Array $ебучесть, $output) {
        $индексЕбучести = 0;
        if (!is_null($ебучесть[0])) {
            $индексЕбучести = $ебучесть[0];
        }
        if (!is_null($ебучесть[1]) && ($ебучесть[1] > $ебучесть[0])) {
            $индексЕбучести = $ебучесть[1];
        }
    
        $img = Шакализатор::make($шакал->path);
        $img->resize($ебучесть[0], $ебучесть[1], function ($constraint) {
            $constraint->aspectRatio();
            $constraint->upsize();
        });
        if ($img->mime() !== 'image/jpeg') {
            $img->encode('jpg', 100);
        }
        $img->save($output."$шакал->name-$индексЕбучести.jpg", $степеньСжатия);
    }
    
    function сжатьВсехШакалов($path, $степеньСжатия, $ебучестьШакалов, $output) {
        global $logger;
        $files = scandir($path);
        foreach($files as $key => $file) {
            $logger->colorLogWithFiles('blue', $file, $key);
            try {
                $шакал = new KPFile($path.$file);
                if ($шакал->type !== KPFile::FILE_TYPE_IMAGE) {
                    continue;
                }
                if (trim($шакал->name) == '') {
                    throw new Exception("file=$file, kpFileName=$шакал->name");
                }
                foreach ($ебучестьШакалов as $ебучесть) {
                    сжать($шакал, $степеньСжатия, $ебучесть, $output);
                }
            } catch (Exception $e) {
                $logger->exception($e, $key);
            }
        }
    }
    
    $степеньСжатия = 22;
    $ебучестьШакалов = [
        [60, 60],
        [38, 38]
    ];
    сжатьВсехШакалов('dataHeavy/carsOrig/', $степеньСжатия, $ебучестьШакалов, "../public/img/cars/");
    
    
    $logger->colorLogWithFiles('blue', '10/10 *** еб/шакалов', null, "\n");

    shakal of jpeg-street

    raduloh, 17 Октября 2019

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