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

    −102

    1. 1
    l.add_xpath('price', '//table[3]/tr/td[2]/table[1]/tr[1]/td[3]/table/tr[3]/td/table/tr[2]/td/text()', lambda x: '.'.join(x))

    kyzi007, 05 Мая 2014

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

    −96

    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
    srp_base64_table = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz./"
    
    def srpb64decode(s):
        ints = [srp_base64_table.index(c) for c in s]
        pad = len(ints) % 4
        if pad != 0:
            pad = 4 - pad
        ints = [0 for i in range(0, pad)] + ints
        notleading = False
        buf = []
    
        pos = 0
        while pos < len(ints):
            b = (ints[pos] << 2) | ((ints[pos+1] & 0x30) >> 4)
            if notleading or b != 0:
                buf.append(b)
                notleading = True
            b = ((ints[pos+1] & 0x0f) << 4) | ((ints[pos+2] & 0x3c) >> 2)
            if notleading or b != 0:
                buf.append(b)
                notleading = True
            b = ((ints[pos+2] & 0x03) << 6) | ints[pos+3]
            if notleading or b != 0:
                buf.append(b)
                notleading = True
            pos += 4
    
        return bytes(buf)
    
    def srpb64encode(b):
        pos = len(b) % 3
        b0 = 0
        b1 = 0
        b2 = 0
        notleading = False
        buf = ""
    
        if pos == 1:
            b2 = b[0]
        elif pos == 2:
            b1 = b[0]
            b2 = b[1]
    
        while True:
            c = (b0 & 0xfc) >> 2
            if notleading or c != 0:
                buf += srp_base64_table[c]
                notleading = True
            c = ((b0 & 3) << 4) | ((b1 & 0xf0) >> 4)
            if notleading or c != 0:
                buf += srp_base64_table[c]
                notleading = True
            c = ((b1 & 0xf) << 2) | ((b2 & 0xc0) >> 6)
            if notleading or c != 0:
                buf += srp_base64_table[c]
                notleading = True
            c = b2 & 0x3f
            if notleading or c != 0:
                buf += srp_base64_table[c]
                notleading = True
            if pos >= len(b):
                break
            b0 = b[pos]
            b1 = b[pos + 1]
            b2 = b[pos + 2]
            pos += 3
    
        return buf

    Кодирование и декодирование блобов для openssl SRP.

    А я построю свой диснейленд с блекджеком и шлюхами! (c) тот, кто пилил SRP в openssl

    bormand, 23 Апреля 2014

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

    −98

    1. 1
    2. 2
    3. 3
    4. 4
    if value is False:
        res = ~res
    elif not value is True:
        raise AnalyzeError("Invalid value {0}".format(condition.value))

    hugr, 22 Апреля 2014

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

    −91

    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
    def dubliSert():                      #Проверка дублей Сертификата
        dsn = cx_Oracle.makedsn(ip, 1521, '###' )
        db = cx_Oracle.connect(LOGIN, PASSWORD, dsn)
    
        f1 = open("text1.txt")
        x = f1.readline()
        x1 = f1.readline()
        x2 = f1.readline()
        x3 = f1.readline()
        x4 = f1.readline()
        x5 = f1.readline()
        x6 = f1.readline()
        x7 = f1.readline()
        x8 = f1.readline()
        x9 = f1.readline()
        x10 = f1.readline()
        x11 = f1.readline()
        x12 = f1.readline()
        x13 = f1.readline()
        x14 = f1.readline()
        x15 = f1.readline()
        x16 = f1.readline()
        x17 = f1.readline()
        x18 = f1.readline()
        x19 = f1.readline()
        x20 = f1.readline()
        #x20 = x20.decode("utf-8")
        x20 = x20[:-1]
        x20 = x20.replace(' ','')
        x20 = int(x20, 16)
        #print x20
        f1.close()
        cu = my_cursor=db.cursor()
        cu.execute((u"select * from {} where dscertificate_serial like '{}'").format(TABLE, x20))

    No comments

    rakovka, 04 Апреля 2014

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

    −98

    1. 1
    2. 2
    3. 3
    String = String.replace("{", "{{")
    String = String.replace("}", "}}")
    self.File.write(("{}" + String).format(" " * self.__Whitespace))

    Это, между прочим, откуда-то из недр blender-a...
    https://developer.blender.org/diffusion/BA/browse/master/io_scene_x/export_x.py$1323-1325

    sqrl, 26 Марта 2014

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

    −102

    1. 1
    is_zipped = not request.args.get('is_zipped', "false") == "false"

    >>> bool("false")
    True
    >>> bool("False")
    True
    почему бы не сделать их ложью

    orion, 12 Марта 2014

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

    −87

    1. 1
    from time import time as time

    В своё время поймал себя на писанине такого кода на Python for s60

    SanchO-SEK, 10 Марта 2014

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

    −95

    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
    # ~*~ coding: utf8 ~*~
    
    def clear_string(str, to_int = None):
        '''
        Чистим строку от "мусора" - нечисловых символов.
        '''
        new_str = ''
        for s in str:
            # сначала ищем точку (вдруг число с плавающей точкой)
            # при этом в новой строке не должно быть больше одной точки
            # и в условии to_int не определен
            if s == '.' and '.' not in new_str and not to_int:
                new_str += s
            else:
                try:
                    i = int(s)
                    new_str += s
                except:
                    pass
        return new_str
    
    def str_to_int(str):
        '''
        Преобразование стоки в целое число
        '''
        # попробуем воспользоваться самым простым методом
        try:
            return int(str)
        except:
            # если не получилось, то проверяем почему? допускаем, что было передано не целое число в строке
            if '.' in str:
                str = str[0:str.find('.')]
                return str_to_int(str)
            else:
                # если уж совсем дела плохи, то возвращаем 0
                return 0
    
    def check_int(str):
        try:
            int(str)
            return True
        except:
            return False
    
    def str_to_float(str):
        '''
        Преобразование стоки в число с плавающей точкой
        '''
        # попробуем воспользоваться самым простым методом
        try:
            return float(str)
        except:
            # других вариантов не осталось. скорее всего функция приняла на входе мусор
            return 0
    
    def check_float(str):
        try:
            float(str)
            return True
        except:
            return False
    
    # есть у нас незатейливая строка
    str = 'a23d.d.5ff6'
    # проверяем функцию чистки строки
    print('Чищеная строка: %s' % clear_string(str))
    print('Чищеная строка с to_int: %s' % clear_string(str, to_int=True))
    # до преобразования строки в число следовало бы почистить ее
    print('Преобразуем мусор в целое число: %s' % str_to_int(str))
    print('Преобразуем чищеную строку в целое число: %s' % str_to_int(clear_string(str)))
    # преобразуем строку в число с плавающей точкой
    print('Преобразуем мусор в число с плавающей точкой: %s' % str_to_float(str))
    print('Преобразуем чищеную строку в число с плавающей точкой: %s' % str_to_float(clear_string(str)))
    
    print('Проверяем, является ли содержимое строки целочисленным: %s' % check_int(str))
    print('Проверяем, является ли содержимое чищеной строки целочисленным: %s' % check_int(clear_string(str, to_int=True)))
    print('Проверяем, является ли содержимое строки числом с плавающей точкой: %s' % check_float(str))
    print('Проверяем, является ли содержимое чищеной строки числом с плавающей точкой: %s' % check_float(clear_string(str)))

    http://www.haikson.com/blogs/hektor/programming/python/python-preobrazovanie-stroki-v-chislo/

    v0ffka, 03 Марта 2014

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

    −99

    1. 01
    2. 02
    3. 03
    4. 04
    5. 05
    6. 06
    7. 07
    8. 08
    9. 09
    10. 10
    11. 11
    12. 12
    >>> max
    <built-in function max>
    >>> max.__call__
    <method-wrapper '__call__' of builtin_function_or_method object at 0x01D72080>
    >>> max.__call__.__call__
    <method-wrapper '__call__' of method-wrapper object at 0x022D2730>
    >>> max.__call__.__call__.__call__
    <method-wrapper '__call__' of method-wrapper object at 0x022D29B0>
    >>> max.__call__.__call__.__call__.__call__
    <method-wrapper '__call__' of method-wrapper object at 0x022D2970>
    >>> max.__call__.__call__.__call__.__call__(1,2,3)
    3

    We need to go deeper.

    Vindicar, 21 Февраля 2014

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

    −99

    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
    for i in range(0,len(m)):
        if i==0:
            f=False
            s += x[m[i]]
        else:
            if i==len(m)-1:
                if not f:
                    f=False
                    s += ',' + x[m[i]]
                else:
                    f=False
                    s += x[m[i]]
                break
            else:
                if m[i]-m[i-1]==1:
                    if m[i+1]-m[i]==1:
                        if not f:
                            f=True
                            s += '-'
                            continue
                        else:
                            continue
                    else:
                        if not f:
                            f=False
                            s += ',' + x[m[i]]
                        else:
                            f=False
                            s += x[m[i]]
                else:
                    f=False
                    s += ','+x[m[i]]

    Была задача: на вход(m) подается массив чисел, например [1,3,5,6,7], а на выходе получаем человекочитаемую строку(s) "пн,ср,пт-вс"
    Вышло такое из меня пару месяцев назад, теперь я никогда не смогу в нем разобраться х_х

    MAaxim91, 05 Февраля 2014

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