1. PHP / Говнокод #17288

    +157

    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
    //full video url
    define("VideoUrl","https://www.youtube.com/watch?v=XbGs_qK2PQA");
    //extract ID
    $videoID=get_youtube_id(VideoUrl);
    echo $videoID; // will output : XbGs_qK2PQA
    //extract function
    function get_youtube_id($url,$debug='N'){
      $res = parse_url($url);
      if($debug=='Y'){
        print_r($res);
      }
      $query = $res['query'];
      $explode = explode('&',$query);
      $explode2 = explode('=',$explode[0]);
      return $explode2[1];
    }

    http://www.youtubemp3pro.com/api/
    самый оптимальный код на извлечение id видео с тытуба

    samuel1ee, 10 Декабря 2014

    Комментарии (1)
  2. JavaScript / Говнокод #17287

    +158

    1. 1
    $scope.pageCount = (newValue / $scope.pageSize | 0) || +!!newValue;

    Кратскость - сестра таланта

    dr_abstract, 10 Декабря 2014

    Комментарии (3)
  3. Си / Говнокод #17286

    +136

    1. 1
    2. 2
    /* To the unenlightened: This sets the 20 MSBs to 0 for sanity's sake. */
    return four_bytes_to_uint32(four_byte_array) & ~(~0 << 12);

    Так приказали K&R.

    codemonkey, 10 Декабря 2014

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

    +76

    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
    public  String bufer (int k) {
            String bufer = "";
            switch (k) {
                case 1:
                    for (int i = 0; i < 10; i++) {
                        if (i == 6)
                            bufer += " ";
                        bufer += Characters[random.nextInt(Characters.length)];
    
                    }
                    break;
                case 2:
                    for (int i = 0; i < 10; i++) {
                        if (i == 4 || i == 8)
                            bufer += " ";
                        bufer += Characters[random.nextInt(Characters.length)];
    
                    }
                    break;
                case 3:
                    for (int i = 0; i < 10; i++) {
                        if (i == 6)
                            bufer += "@";
                        if (i == 8)
                            bufer += ".";
                        bufer += Characters[random.nextInt(Characters.length)];
                    }
                    break;
                case 4:
                    for (int i = 0; i < 10; i++) {
                        bufer += Characters[random.nextInt(Characters.length)];
    
                    }
                    break;
    
            }
            return bufer;
        }

    Вот он, рандом, от тестировщика в selenium

    Android991, 10 Декабря 2014

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

    +127

    1. 01
    2. 02
    3. 03
    4. 04
    5. 05
    6. 06
    7. 07
    8. 08
    9. 09
    10. 10
    11. 11
    # Path for asterisk
    # Default Value: /usr/sbin/asterisk
    WHICH_asterisk=/usr/sbin/asterisk
    
    # Path for rm
    # Default Value: /bin/rm
    WHICH_rm=/bin/rm
    
    # Path for tail
    # Default Value: /usr/bin/tail
    WHICH_tail=/usr/bin/tail

    Конфигурационный файл amportal.conf в freepbx :)

    shinespb, 10 Декабря 2014

    Комментарии (2)
  6. PHP / Говнокод #17282

    +157

    1. 01
    2. 02
    3. 03
    4. 04
    5. 05
    6. 06
    7. 07
    8. 08
    9. 09
    10. 10
    $AgencyID = $arrData['agency_id'];
                    if($AgencyID == $arrData['agency_id']) {
                       
                        get_offerts($xml);
                                                
                    }else {
                        
                        $title = "...
                        $msg = "...
                        ...

    rax, 10 Декабря 2014

    Комментарии (1)
  7. C++ / Говнокод #17281

    +57

    1. 1
    http://pastebin.ru/IvyLrrEr

    так и живём, реализация "зоопарка" на С++ после прочтения "банды четырёх"

    bitchboy, 10 Декабря 2014

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

    +160

    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
    var someThing = new Object({
        isVariant1: function() {
            return (this._type() == "var1") ? true : false;
        },
        isVariant2: function() {
            return (this._type() == "var2") ? true : false;
        },
        isVariant3: function() {
            return (this._type() == "var3") ? true : false;
        },
        isVariant4: function() {
            return ((this._type().indexOf("vvvar") >= 0)) ? true : false;
        }
    });

    Легаси код одного известного проекта.
    Все имена функций и содержимое строк изменены.

    pater, 09 Декабря 2014

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

    −118

    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
    from os import walk
    from time import time
    
    from abc import ABCMeta, abstractmethod
    
    class Reporter(object):
        __metaclass__=ABCMeta
        
        @abstractmethod
        def report(self, catalogs_cntr, files_ctnr, speed):
            """ output catalogs_cntr, files_ctnr, speed to somewhere """
            #pass
        
    class ConsoleIndicator(Reporter):
        def __init__(self, out_splitter):
            self.__out_splitter=out_splitter
            
        def report(self, catalogs_cntr, files_ctnr, speed):
            if self.__out_splitter and self.__out_splitter.pipes:
                _result = "\rcataloges:" + repr(catalogs_cntr).rjust(8) 
                _result += "\tfiles:" + repr(files_ctnr).rjust(13) 
                _result += "\tspeed: %12.3f"%speed + " files/s"
                
                self.__out_splitter.write(_result)
                self.__out_splitter.flush()        
                    
    class CatalogsWalker(object):
        """ """
        
        def __init__(self, catalogs, reporter=None):
            """ """
            
            self.__files_cntr, self.__catalogs_cntr, self.__start_time, self.__speed = 0, 0, 0, 0
            self.__reporter = reporter 
            self.__catalogs = catalogs if hasattr(catalogs, "__iter__") else [catalogs]
    
            
        def __iter__(self):
            self.__files_cntr, self.__catalogs_cntr, self.__start_time, self.__speed = 0, 0, 0, 0
            self.__start_time=time()
            for catalog in self.__catalogs:
                print catalog
                for p,d,ns in walk(catalog): 
                    _ = d;
                    self.__catalogs_cntr+=1
                    for n in ns:
                        self.__files_cntr+=1
                        self.__speed=self.__files_cntr/(time()-self.__start_time)
                        if self.__reporter:
                            self.__reporter.report(self.__catalogs_cntr, self.__files_cntr, self.__speed)
                        yield p,n
                        
        @property
        def reporter(self):
            return self.__reporter
        
        @property
        def catalog_counter(self):
            return self.__catalogs_cntr    
        
        @property
        def file_counter(self):
            return self.__files_cntr
        
        @property
        def start_time(self):
            return self.__start_time
        
        @property
        def speed(self):
            return self.__speed

    По мотивам http://govnokod.ru/17181 Учтены замечания некого Анонимус http://govnokod.ru/17181#comment256577. Надеюсь что будут еще замечания, такие же конструктивные и полезные.

    apgurman, 08 Декабря 2014

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

    −121

    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
    #!/usr/bin/env python
    # encoding: utf-8
    
    import os
    import sys
    
    from sets import Set
    
    class OutputSplitter(object):
        """ splitter """
        
        def __init__(self, out_splitter):
            self.__pipes=None
            if isinstance(out_splitter, OutputSplitter):
                    self.__pipes = Set(out_splitter.pipes)
            elif out_splitter:
                print out_splitter
                if type(out_splitter) == list : #
                    for pn in out_splitter:
                        self.add_pipe(pn)
                else:
                    self.add_pipe(out_splitter)
                       
        @property
        def pipes(self):
            return self.__pipes
        
        def add_pipe(self, pn):
            if isinstance(pn, basestring):
                if pn == 'stderr': x = sys.stderr
                elif pn == 'stdout': x = sys.stdout
                else: 
                    p = os.path.dirname(pn)
                    if p and not os.path.exists(p):
                        os.makedirs(p)
                    try: 
                        x = open(pn,'w+')
                    except IOError:
                        raise
                        
            else: x = pn
            
            if hasattr(x, 'write') and hasattr(x, 'flush'):
                if self.__pipes is None:
                    self.__pipes=Set()
                self.__pipes.add(x)
        
        def write(self,s):
            if self.__pipes:
                for p in self.__pipes:
                    p.write(s)
        
        def flush(self):
            if self.__pipes:
                for p in self.__pipes:
                    p.flush()
        
        #def __enter__(self):
        #    pass         
        #def __exit__(self, exc_type, exc_value, traceback):
        #    pass
    
    if __name__ == '__main__':
        cout=sys.stdout if True else sys.stderr
        o=OutputSplitter(cout)
        pass

    Испаравленная версия по монивам http://govnokod.ru/17181. Учтены замечания некого Анонимус http://govnokod.ru/17181#comment256577. Надеюсь что будут еще замечания, такие же конструктивные и полезные.

    apgurman, 08 Декабря 2014

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