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

    −100

    1. 01
    2. 02
    3. 03
    4. 04
    5. 05
    6. 06
    7. 07
    8. 08
    9. 09
    10. 10
    11. 11
    12. 12
    def del_space_both(t):
            return del_space_end(del_space_begin(t))
    
    def del_space_begin(text):
            if len(text):
                    while text[:1] == ' ': text = text[1:]
            return text
     
    def del_space_end(text):
            if len(text):
                    while text[-1:] == ' ': text = text[:-1]
            return text

    религия не позволяет использовать strip(), lstrip() и rstrip

    lebutirate, 09 Апреля 2012

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

    −97

    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
    for digest in li:
    
        s = 1
        i = 0
        j = 1
    
        while i <= 4:
    
            s = int(digest[i:j]) * s
    
            i += 1
            j += 1
    
        li2.append(s)

    Вычисление произведения пяти чисел
    li = список строк вида "01234"

    Yurik, 04 Апреля 2012

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

    −86

    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
    def password_generator(count = 8):
        import random
        i = 0
        password = ''
        symbols = ['q','w','e','r','t','y','u','i','o','p','s','a','d','f','g','h','j','k','l','z','x','c','v','b','n','m','1','2','3','4','5','6','7','8','9','0']
        while i<count:
            tempsymbol = ''
            tempsymbol += random.choice(symbols)
            temp = random.randint(0,1)
            if temp == 1:
                password += tempsymbol.upper()
            else:
                password += tempsymbol
            i += 1
        return password

    Белорусские питонисты генерируют пароль.

    sickuenser, 30 Марта 2012

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

    −89

    1. 1
    columns = [col for col in self.load_column_data()['columns']]

    Вот так мы копируем списки.

    zealotous, 30 Марта 2012

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

    −90

    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
    def runRidor():
    	isDirty = 0
    	#Except (DebugSize <= 14) and (ImageVersion <= 760) and (VirtualSize2 > 992) and (ExportSize <= 80.5) => isDirty = 1  (1702.0/16.0) [855.0/5.0]
    	if input.DebugSize <= 14 and input.ImageVersion <= 760 and input.VirtualSize2 > 992 and input.ExportSize <= 80.5:
    		isDirty = 1
    #Except (DebugSize <= 14) and (ImageVersion <= 4525) and (ExportSize <= 198.5) and (ResourceSize <= 37532) and (VirtualSize2 <= 6) and (ResourceSize <= 7348) and (ResourceSize > 1773) => isDirty = 1  (106.0/0.0) [48.0/0.0]
    	elif input.DebugSize <= 14 and input.ImageVersion <= 4525  and input.ExportSize <= 198.5 and input.ResourceSize <= 7348 and input.VirtualSize2 <=6 and input.ResourceSize > 1773:
    		isDirty = 1
    #Except (DebugSize <= 14) and (ImageVersion <= 4950) and (ExportSize <= 192) and (IatRVA > 256) and (VirtualSize2 > 42) and (ExportSize <= 56) and (NumberOfSections > 3.5) => isDirty = 1  (193.0/0.0) [91.0/0.0]
    	elif input.DebugSize <= 14 and input.ImageVersion <= 4950 and input.ExportSize <= 56 and input.IatRVA > 256 and input.VirtualSize2 > 42 and input.NumberOfSections > 3.5:
    		isDirty = 1
    #Except (DebugSize <= 14) and (ImageVersion <= 4950) and (VirtualSize2 <= 6) and (ResourceSize <= 37532) and (ResourceSize <= 17302) => isDirty = 1  (388.0/0.0) [216.0/7.0]
    	elif input.DebugSize <= 14 and input.ImageVersion <= 4950 and input.VirtualSize2 <= 6 and input.ResourceSize > 17302:
    		isDirty = 1
    #Except (DebugSize <= 14) and (NumberOfSections > 2.5) and (ResourceSize > 1776) and (IatRVA <= 6144) and (ExportSize <= 219.5) and (VirtualSize2 > 2410) and (VirtualSize2 <= 61224) => isDirty = 1  (238.0/0.0) [116.0/0.0]
    	elif input.DebugSize <= 14 and input.NumberOfSections >= 2.5 and input.ResourceSize <= 1776 and input.IatRVA <= 6144 and input.ExportSize <= 219.5 and input.VirtualSize2 > 2410 and input.VirtualSize2 <= 61224:
    		isDirty = 1

    Пример того, как не надо писать на питоне, показывает Adobe. Полная версия: http://voxel.dl.sourceforge.net/project/malclassifier.adobe/AdobeMalwareClassifier.py

    SvartalF, 30 Марта 2012

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

    −95

    1. 1
    2. 2
    3. 3
    4. 4
    try:
        ix, iy, image = im.size[0], im.size[1], im.tostring("raw", "RGBA", 0, -1)
    except SystemError:
        ix, iy, image = im.size[0], im.size[1], im.tostring("raw", "RGBX", 0, -1)

    "Ну пожалуйста!"
    Нашел здесь:
    http://pyopengl.sourceforge.net/context/tutorials/nehe6.xhtml

    Vindicar, 23 Марта 2012

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

    −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
    x = str(x)                                            # x == '987.654'
    dot = x.find('.')                                  # dot == 3
    whole = x[:dot]                                 # whole == '987'
    nums = '0123456789'                     # 
    tenths = x[(dot + 1):(dot + 2)]         # tenths == '6'
    max_digits = 6                                  # Directions say x is not > 100,000
    filler = max_digits - dot                   # filler == 3 (dot is equal to the number of digits in whole)
    big_num = ('0' * filler) + whole       # big_num == '000987'
    
    e5 = (nums.find(big_num[0:1])) * 100000   # e5 == 0
    e4 = (nums.find(big_num[1:2])) * 10000     # e4 == 0
    e3 = (nums.find(big_num[2:3])) * 1000       # e3 == 0
    e2 = (nums.find(big_num[3:4])) * 100         # e2 == 900
    e1 = (nums.find(big_num[4:5])) * 10           # e1 == 80
    e0 = (nums.find(big_num[5:6]))                   # e0 == 7
    
    the_decider = '9'.find(tenths) + '8'.find(tenths) + '7'.find(tenths) + '6'.find(tenths) + '5'.find(tenths) + 5
    
    rounded = (e5 + e4 + e3 + e2 + e1 + e0) + the_decider
    print rounded

    Эта, кхм, программа предназначается для округления положительных натуральных чисел величиной до 100000.

    aibo, 13 Марта 2012

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

    −100

    1. 1
    2. 2
    3. 3
    @type('inline hack', (object,), {'__new__':lambda cls, fnc: wraps(lambda request, *args, **kwargs: setattr(request, 'holder', None) and fnc(request, *args, **kwargs))})
    def create_receiver(request, id):
        pass

    Отсутствие инлайновых декораторов предыдущему фрилансеру не помеха

    nvbn, 05 Марта 2012

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

    −97

    1. 1
    2. 2
    3. 3
    get_params = dict(context['request'].GET.copy())
    
    query = "&".join(map(lambda item : "%s=%s"%(item[0],item[1][0]), zip(get_params,get_params.values())))

    Используйте возможности стандартных библиотек, сучечки!

    SvartalF, 05 Марта 2012

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

    −174

    1. 1
    2. 2
    3. 3
    4. 4
    5. 5
    6. 6
    7. 7
    8. 8
    def plus_year(date):
        """
        Прибавляем к полученной дате 1 год.
        """
        try:
            return date.replace(year=date.year+1)
        except ValueError:  # 29 февраля.
            return date.replace(month=2, day=28, year=date.year+1)

    ir4y, 05 Марта 2012

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