1. Python / Говнокод #26017

    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
    Building on that example, the new syntax for function definitions would look like:
    
    def name(positional_only_parameters, /, positional_or_keyword_parameters,
             *, keyword_only_parameters):
    
    Therefore the following would be valid function definitions:
    
    def name(p1, p2, /, p_or_kw, *, kw):
    def name(p1, p2=None, /, p_or_kw=None, *, kw):
    def name(p1, p2=None, /, *, kw):
    def name(p1, p2=None, /):
    def name(p1, p2, /, p_or_kw):

    https://www.python.org/dev/peps/pep-0570

    3.14159265, 07 Ноября 2019

    Комментарии (201)
  2. Python / Говнокод #26010

    +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
    x = 0; y = 0
     
    def gcd(a, b):
    #{
        global x, y
        if (a == 0):
        #{
            x = 0; y = 1;
            return b;
        #}
        d = gcd(b%a, a);
        t = x
        x = y - (b // a) * x;
        y = t;
        return d;
    #}
     
    #int main()
    #{
    #ios_base::sync_with_stdio(0); in.tie(0);
    #I n, p, w, d, dd, ww;
    #in >> n >> p >> w >> d;
    n, p, w, d = map(int, input().split())
    gc = gcd(d, w);
    dd = x; ww = y
    g = w * d // gc;
    if (p % gc):
        print(-1); exit(0)
    dd *= p // gc;
    ww *= p // gc;
    if (ww < 0):
    #{
        di = (-ww + g // w - 1) // (g // w);
        ww += g // w * di;
        dd -= g // d * di;
        if (dd < 0):
            print(-1); exit(0)
    #}
    elif (dd < 0):
    #{
        di = (-dd + g // d - 1) // (g // d);
        dd += g // d * di;
        ww -= g // w * di;
        if (dd < 0):
            print(-1); exit(0)
    #}
    if (ww < 0 or dd < 0):
        print(-1); exit(0)
    di = dd // (g // d);
    dd -= g // d * di;
    ww += g // w * di;
    if (ww + dd <= n):
        print(ww, dd, n - ww - dd)
    else:
        print(-1);
    #}

    Когда на соревновании по спортивному программированию пишешь код на C++ и внезапно понимаешь, что int64_t тебе недостаточно.

    fyodor95, 04 Ноября 2019

    Комментарии (52)
  3. 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)
  4. 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)
  5. Python / Говнокод #25909

    −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
    with open("test.bmp","w+b") as f:
        f.write(b'BM')#ID field (42h, 4Dh)
        f.write((154).to_bytes(4,byteorder="little"))#154 bytes (122+32) Size of the BMP file
        f.write((0).to_bytes(2,byteorder="little"))#Unused
        f.write((0).to_bytes(2,byteorder="little"))#Unused
        f.write((122).to_bytes(4,byteorder="little"))#122 bytes (14+108) Offset where the pixel array (bitmap data) can be found
        f.write((108).to_bytes(4,byteorder="little"))#108 bytes Number of bytes in the DIB header (from this point)
        f.write((4).to_bytes(4,byteorder="little"))#4 pixels (left to right order) Width of the bitmap in pixels
        f.write((2).to_bytes(4,byteorder="little"))#2 pixels (bottom to top order) Height of the bitmap in pixels
        f.write((1).to_bytes(2,byteorder="little"))#1 plane Number of color planes being used
        f.write((32).to_bytes(2,byteorder="little"))#32 bits Number of bits per pixel
        f.write((3).to_bytes(4,byteorder="little"))#3 BI_BITFIELDS, no pixel array compression used
        f.write((32).to_bytes(4,byteorder="little"))#32 bytes Size of the raw bitmap data (including padding)
        f.write((2835).to_bytes(4,byteorder="little"))#2835 pixels/metre horizontal Print resolution of the image,
        f.write((2835).to_bytes(4,byteorder="little"))#2835 pixels/metre vertical   72 DPI × 39.3701 inches per metre yields 2834.6472
        f.write((0).to_bytes(4,byteorder="little"))#0 colors Number of colors in the palette
        f.write((0).to_bytes(4,byteorder="little"))#0 important colors 0 means all colors are important
        f.write(b'\x00\x00\xFF\x00')#00FF0000 in big-endian Red channel bit mask (valid because BI_BITFIELDS is specified)
        f.write(b'\x00\xFF\x00\x00')#0000FF00 in big-endian Green channel bit mask (valid because BI_BITFIELDS is specified)
        f.write(b'\xFF\x00\x00\x00')#000000FF in big-endian Blue channel bit mask (valid because BI_BITFIELDS is specified)
        f.write(b'\x00\x00\x00\xFF')#FF000000 in big-endian Alpha channel bit mask
        f.write(b' niW')#little-endian "Win " LCS_WINDOWS_COLOR_SPACE
        f.write((0).to_bytes(36,byteorder="little"))#CIEXYZTRIPLE Color Space endpoints	Unused for LCS "Win " or "sRGB"
        f.write((0).to_bytes(4,byteorder="little"))#0 Red Gamma Unused for LCS "Win " or "sRGB"
        f.write((0).to_bytes(4,byteorder="little"))#0 Green Gamma Unused for LCS "Win " or "sRGB"
        f.write((0).to_bytes(4,byteorder="little"))#0 Blue Gamma Unused for LCS "Win " or "sRGB"
        f.write(b'\xFF\x00\x00\x7F')#255 0 0 127 Blue (Alpha: 127), Pixel (1,0)
        f.write(b'\x00\xFF\x00\x7F')#0 255 0 127 Green (Alpha: 127), Pixel (1,1)
        f.write(b'\x00\x00\xFF\x7F')#0 0 255 127 Red (Alpha: 127), Pixel (1,2)
        f.write(b'\xFF\xFF\xFF\x7F')#255 255 255 127 White (Alpha: 127), Pixel (1,3)
        f.write(b'\xFF\x00\x00\xFF')#255 0 0 255 Blue (Alpha: 255), Pixel (0,0)
        f.write(b'\x00\xFF\x00\xFF')#0 255 0 255 Green (Alpha: 255), Pixel (0,1)
        f.write(b'\x00\x00\xFF\xFF')#0 0 255 255 Red (Alpha: 255), Pixel (0,2)
        f.write(b'\xFF\xFF\xFF\xFF')#255 255 255 255 White (Alpha: 255), Pixel (0,3)
        f.close()

    https://habr.com/ru/sandbox/125382/

    OCETuHCKuu_nemyx, 06 Октября 2019

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

    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
    from xml.sax.saxutils import unescape
    
    HEADERS = {'User-Agent': 'Mozilla/5.0 (Windows NT 6.1) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/49.0.2623.87 Safari/537.36',
               'Accept': 'text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,*/*;q=0.8',
               'Accept-Charset': 'ISO-8859-1,utf-8;q=0.7,*;q=0.7',
               'Accept-Language': 'ru-RU,ru;q=0.8,en-US;q=0.5,en;q=0.3'}
    
    GOOGLE_RE = re.compile(r'<h3 class="r"><a href="([^"]+)" ')
    YANDEX_RE = re.compile(r'<span class="serp-url__mark">.</span><a class="link serp-url__link" target="_blank" href="([^"]+)"')
    PROXY_RE = re.compile(r'(\d+\.\d+\.\d+\.\d+)[:\s]+(\d+)')
    
    def search_google(requests_list, qdr=None, interval=2):
        res = []
        qdr = 'd' if qdr is None or not qdr in ['w', 'd'] else qdr
        REQ_FORMAT = 'https://www.google.com/search?q={0}&num=100&tbs=qdr:' + qdr
        i = 0
    
        for term in requests_list:
            req = REQ_FORMAT.format(term)
            response = requests.get(req, headers=HEADERS)
            if response.status_code != 200:
                print ('Google returned {0}'.format(response.status_code))
                time.sleep(interval)
                continue
    
            txt = response.text
            found = GOOGLE_RE.findall(txt)
            res += found
            print ('done term {0}, found {1} URLs'.format(i, len(found)))
            i += 1
    
            time.sleep(interval)
    
        map(unescape, res)
        
        return res

    Древняя граббилка открытых прокси при помощи поисковых систем. Когда-то даже работала.

    gost, 01 Октября 2019

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

    0

    1. 1
    2. 2
    3. 3
    4. 4
    def __repr__(self):
        return 'environ({{{}}})'.format(', '.join(
            ('{!r}: {!r}'.format(self.decodekey(key), self.decodevalue(value))
            for key, value in self._data.items())))

    {{впечатляйте{с{GNU/Python}}}}

    Stallman, 26 Сентября 2019

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

    +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
    num = 600851475143
    i = 1
    numbers = []
    result = []
    for i in range(1, num):
        if i % 1 == 0:
            if i % i == 0:
                if i % 2 != 0:
                    if i % 3 != 0:
                        if i % 4 != 0:
                            if i % 5 != 0:
                                if i % 6 != 0:
                                    if i % 7 != 0:
                                        if i % 8 != 0:
                                            if i % 9 != 0:
                                                numbers.append(i)
                                                print(numbers)
    
    for c in range (numbers):
        if num % c == 0:
            result.append(c)
    num_2 = max(result)

    Кококой багор )))

    CkpunmoBbIu_nemyx, 09 Сентября 2019

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

    −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
    38. 38
    39. 39
    hxStr = []
    for x in range(256):
        hxStr.append('{:02X}'.format(x))
    ascChr = []
    for i in range(32, 128):
        ascChr.append(chr(i))
    data = [
        0xBE, 0xEF, 0xDE, 0xAD
    ]
    lines = (len(data)//16)
    if len(data)%16 != 0:
        lines += 1
    i = 0
    pr = ''
    for x in range(lines):
        pr += "{:000000008X}{:1}|{:1}".format(x*16,'','')
        btes = []
        symbs = []
        for y in range(i,i+16,1):
            if y >= len(data):
                for x in range((lines*16)-y):
                    symbs.append(' ')
                    btes.append(' ')
                break
            if chr(data[y]) in ascChr:
                symbs.append(chr(data[y]))
            else:
                symbs.append('∙')
            btes.append(hxStr[data[y]])
        i = y+1
        for y in range(len(btes)):
            pr += "{:3}".format(btes[y])
        pr += '|{:1}'.format('')    
        for y in range(len(symbs)):
            pr += "{:1}".format(symbs[y])
        pr += '\r\n'    
    print("{:9}|{:1}0{:2}1{:2}2{:2}3{:2}4{:2}5{:2}6{:2}7{:2}8{:2}9{:2}A{:2}B{:2}C{:2}D{:2}E{:2}F{:2}|\
    {:1}0123456789ABCDEF".format('Offset','','','','','','','','','','','','','','','','','','',''))    
    print(pr)

    наваял типа 16ричный вьювер

    MegaCrap, 05 Сентября 2019

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

    −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
    connect_attempt = 0
    		while True:
    			try:
    				r = requests_method(**kwargs)
    			except Exception as e:
    				if connect_attempt < cls.CONNECT_ATTEMPT_MAX:
    					connect_attempt += 1
    				else:
    					connect_attempt = 0
    					switchNext('Bad proxy')
    				
    				continue
    			
    			connect_attempt = 0
    			if cls.re_captcha.search(r.text):
    				switchNext('Capthca')
    				continue
    			return r

    Отрывок из прокси свитчера для моего парсера.
    try except в цикле - это плохо?

    OlegUP, 04 Сентября 2019

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