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

    −105

    1. 1
    2. 2
    3. 3
    4. 4
    5. 5
    6. 6
    7. 7
    def reverse_govnocode(text):
        rev_str = []
        str_len = len(text) - 1
        while str_len >= 0:
            rev_str.append(text[str_len])
            str_len -= 1
        return ''".join(rev_str)

    stanp, 09 Октября 2014

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

    −102

    1. 1
    2. 2
    3. 3
    4. 4
    class GNUTranslations(NullTranslations):
        # Magic number of .mo files
        LE_MAGIC = 0x950412de
        BE_MAGIC = 0xde120495

    хуита, 07 Октября 2014

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

    −98

    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
    def down_cast_qobject(tp, obj):
        assert obj
        assert isinstance(tp, type)
        assert issubclass(tp, QObject)
        addresses = shiboken.getCppPointer(obj)
        assert isinstance(addresses, collections.Iterable)
        assert len(addresses)
        ptrs = filter(lambda p: p > 0L, addresses)
        assert ptrs
        ptr = ptrs[0]
        assert isinstance(ptr, long)
        wrapped = shiboken.wrapInstance(ptr, tp)
        assert isinstance(wrapped, tp)
        return wrapped

    Paranoid_mode = True

    QBatman, 03 Октября 2014

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

    −99

    1. 1
    2. 2
    def str_to_float(i):
        return int (i) + 0.0

    Так надо!

    zadrot, 16 Сентября 2014

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

    −119

    1. 01
    2. 02
    3. 03
    4. 04
    5. 05
    6. 06
    7. 07
    8. 08
    9. 09
    10. 10
    11. 11
    import sys;
     
    class Cout(object):
        def __lshift__(self, anything):
            sys.stdout.write(str(anything));
            return self;
     
    cout = Cout();
    endl = '\n';
     
    cout << 'Hello, World!' << endl;

    http://lurkmore.to/Обсуждение:Python#.D0.92_.D1.81.D1.82.D0 .B8.D0.BB.D0.B5_.D0.BF.D0.BB.D1.8E.D1.81 .D0.BE.D0.B2

    someone, 11 Сентября 2014

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

    −102

    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
    def booleanize(value):
        """Return value as a boolean."""
    
        true_values = ("yes", "true", "1")
        false_values = ("no", "false", "0")
    
        if isinstance(value, bool):
            return value
    
        if value.lower() in true_values:
            return True
    
        elif value.lower() in false_values:
            return False

    В комментариях не нуждается.

    Niyakiy, 29 Августа 2014

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

    −101

    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
    class ImageAsset(Asset):
     
        def to_xml(self):  
            if self.asset_type == self.VIDEO:
                return self.videoasset.to_xml()
            element = etree.Element("imageAsset")
            if self.mask_key:
                element.set("maskId", self.mask_key)
            if self.image_x:
                element.set("imageX", str(self.image_x))
            if self.image_y:
                element.set("imageY", str(self.image_y))
            if self.image_width:
                element.set("imageWidth", str(self.image_width))
            if self.image_height:
                element.set("imageHeight", str(self.image_height))
            self.set_xml_attrs(element)
            return element
    
    class VideoAsset(ImageAsset):
     
        def to_xml(self):  
            element = etree.Element("videoAsset")
            if self.mask_key:
                element.set("maskId", self.mask_key)
            if self.image_x:
                element.set("imageX", str(self.image_x))
            if self.image_y:
                element.set("imageY", str(self.image_y))
            if self.image_width:
                element.set("imageWidth", str(self.image_width))
            if self.image_height:
                element.set("imageHeight", str(self.image_height))
            self.set_xml_attrs(element)
            return element

    Полиморфизм это вам не шубу в трусы заправлять!

    wvxvw, 26 Августа 2014

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

    −88

    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
    class DataModel(dict):
        _SCHEME_VERSION = 0
        _transform = dict()
        _additional = dict()
        _migration = None
    
        def __init__(self, data=None, network=None, conf=None):
            if network and conf:
                _scheme = map(lambda x: x.strip(), conf.get(network).keys())
                _map =  map(lambda x: x.strip(), conf.get(network).values())
    
                self._scheme = int(conf._scheme)
    
                map(lambda x: setattr(self, x[0], data.get(x[1], None)),
                    [(_scheme[i], _map[i]) for i in xrange(0,len(_map))])
    
                if self._transform.get(network, False):
                    map(lambda x: setattr(self, x, getattr(self._transform[network], x)(getattr(self, x))),
                        [k for k in self._transform[network].__dict__.keys() if not k.startswith('__')])
            else:
                dict.__init__(self, data)
    
            if self.get('_scheme', 0)<self._SCHEME_VERSION and self._migration is not None:
                k = [int(k.split('_')[1]) for k in self._migration.__dict__.keys() if not k.startswith('__')]
                k.sort()
                [k.remove(x) for x in k if x<=self.get('_scheme', 0)]
                map(lambda x: getattr(self._migration, 'scheme_%s' % x)(self), k)
                self._scheme = self._SCHEME_VERSION
    
            map(lambda x: setattr(self, x, getattr(self._additional, x)(self)),
                [k for k in self._additional.__dict__.keys() if not k.startswith('__')])
    
        def __setattr__(self, name, val):
            if name in self.__dict__:
                self.__dict__[name]= val
            else:
                self[name] = val
    
        def __getattr__(self, name):
            if name in self.__dict__:
                return self.__dict__[name]
            else:
                return self[name]

    Mongo migration, written in Python, for human beings.

    vaxxxa, 14 Августа 2014

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

    −89

    1. 1
    2. 2
    3. 3
    4. 4
    5. 5
    6. 6
    7. 7
    8. 8
    9. 9
    def mayakovsky(string):
        splitted = string.split('\n')
        l = [splitted[0]]
        lastSpaces = 0
        
        for i in range(1, len(splitted)):
            l += [' '*(lastSpaces + len(splitted[i - 1]) + 1) + splitted[i]]
            lastSpaces += len(splitted[i - 1]) + 1
        return '\n'.join(l)

    Лол.

    gost, 12 Августа 2014

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

    −102

    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
    def _registerCommands(self, mapping=None, dataMapping=None, commandUpdates=None, dataUpdates=None):
                ...
            for (cmdName, cmdClass) in cMap.iteritems():
                ...
                self._setCommand(cmdObj)
    
        def _setCommand(self, cmdObj):
            if cmdObj.__class__.__name__.find("_") != -1:
                name = unicode(cmdObj.__class__.__name__.split("_", 1)[1])
            else:
                name = unicode(cmdObj.__class__.__name__).lower()
            setattr(self, name.lower(), cmdObj)
            ...

    Fedora, pykickstart. Посоны регистрируют команды в парсере...

    solo1h, 25 Июля 2014

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