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

    +156

    1. 1
    2. 2
    if( SITE == 'http://dev.example.com' ) die( file_get_contents( 'http://www.example.com/error.php?error=xml' ) );
    die( file_get_contents( SITE.'/error.php?error=xml' ) );

    некоторые 404-ую выводят вот так

    dead_star, 22 Марта 2013

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

    +119

    1. 1
    <button type="button"

    Пятница в моей голове...

    nonamez, 22 Марта 2013

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

    −103

    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 show_vlans(self):
            """Magic people/Voodoo people. All code in this func should be refactored/rewrited."""
            self.read_very_eager()#flush
            output=self.wr_cmd_sh('sho vlan')
            time.sleep(.1)
            vlans={}
            vlan=''
            for string in output:
                if re.search(r"VID[\s]*:",string):
                   vlan=string[re.search(r"[\d]+",string).start():re.search(r"[\d]+",string).end()]
                   vlans[vlan]={'Member':[], 'Tagged':[], 'Untagged':[]}
                if re.search(r"Member Port[s]*[\s]*:[\s]*[\d]+[[-]*[\d]*]*",string):
                   if '-' in string[re.search(r"[\d]+[[-]*[\d]*]*",string).start():re.search(r"[\d]+[[-]*[\d]*]*",string).end()]:
                      for port in xrange(int(string[re.search(r"[\d]+[[-]*[\d]+]*",string).start():re.search(r"[\d]+[[-]*[\d]+]*",string).end()].split('-')[0]),int(string[re.search(r"[\d]+[[-]*[\d]+]*",string).start():re.search(r"[\d]+[[-]*[\d]+]*",string).end()].split('-')[1])+1):
                          vlans[vlan]['Member'].append(port)
                   else:
                        vlans[vlan]['Member'].append(string[re.search(r"[\d]+[[-]*[\d]*]*",string).start():re.search(r"[\d]+[[-]*[\d]*]*",string).end()])
                if re.search(r"Current Tagged Port[s]*[\s]*:[\s]*[\d]+[[-]*[\d]*]*",string):
                   if '-' in string[re.search(r"[\d]+[[-]*[\d]*]*",string).start():re.search(r"[\d]+[[-]*[\d]*]*",string).end()]:
                      for port in xrange(int(string[re.search(r"[\d]+[[-]*[\d]+]*",string).start():re.search(r"[\d]+[[-]*[\d]+]*",string).end()].split('-')[0]),int(string[re.search(r"[\d]+[[-]*[\d]+]*",string).start():re.search(r"[\d]+[[-]*[\d]+]*",string).end()].split('-')[1])+1):
                          vlans[vlan]['Tagged'].append(port)
                   else:
                        vlans[vlan]['Tagged'].append(string[re.search(r"[\d]+[[-]*[\d]*]*",string).start():re.search(r"[\d]+[[-]*[\d]*]*",string).end()])
                if re.search(r"Current Untagged Port[s]*[\s]*:[\s]*[\d]+[[-]*[\d]*]*",string):
                   if '-' in string[re.search(r"[\d]+[[-]*[\d]*]*",string).start():re.search(r"[\d]+[[-]*[\d]*]*",string).end()]:
                      for port in xrange(int(string[re.search(r"[\d]+[[-]*[\d]+]*",string).start():re.search(r"[\d]+[[-]*[\d]+]*",string).end()].split('-')[0]),int(string[re.search(r"[\d]+[[-]*[\d]+]*",string).start():re.search(r"[\d]+[[-]*[\d]+]*",string).end()].split('-')[1])+1):
                          vlans[vlan]['Untagged'].append(port)
                   else:
                        vlans[vlan]['Untagged'].append(string[re.search(r"[\d]+[[-]*[\d]*]*",string).start():re.search(r"[\d]+[[-]*[\d]*]*",string).end()])
            if vlans=={}:
               vlans=self.show_vlans()
    
            #####
            return vlans

    Императивненько) регекспотренировка при отсутствии group() да и вообще...

    voiper, 21 Марта 2013

    Комментарии (0)
  4. PHP / Говнокод #12777

    +146

    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
    getInsideText($part1[0],'<string>','</string>',1,true);
    
    function getInsideText($str,$fstr,$lstr,$limit=0,$trim=true){
        $temp_arr=array();
        $lcnt=0;
        while(strpos($str,$fstr)!==false && ($limit ? $lcnt<$limit : true)){
            $fpos=($fstr ? strpos($str,$fstr)+strlen($fstr) : 0);
            $str=substr($str,$fpos);
            $lpos=strpos($str,$lstr);
            $val=($lpos!==false ? substr($str,0,$lpos) : $str);
            $temp_arr[]=($trim ? trim($val) : $val);
            $str=substr($str,$lpos+strlen($lstr));
            $lcnt++;
        }
        return ($limit==1 ? (isset($temp_arr[0]) ? $temp_arr[0] : '') : $temp_arr);
    }

    Конечный автомат своими силами.

    alexx, 21 Марта 2013

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

    +136

    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
    private void StatusMsg(string message, int delay = 1000)
     {
          lock (_msgQueue)
          {
            if (_msgQueue.ContainsKey(message))
            {
              int i = 1;
              message = String.Format("{0} {1}", message, i);
              while (_msgQueue.ContainsKey(message))
              {
                message = String.Format("{0} {1}", message.Substring(0, message.LastIndexOf(' ')), i++);
              }
            }
            _msgQueue.Add(message, delay);
          }
     }

    Чёто я не понимаю

    taburetka, 21 Марта 2013

    Комментарии (31)
  6. Java / Говнокод #12775

    +119

    1. 1
    2. 2
    3. 3
    if (request.getDate() != null && request.getDate().after(new Date())) {
    	throw new ApiException(HttpStatus.SC_BAD_REQUEST, "Great Scott! Time machine not invented yet");
    }

    someone, 21 Марта 2013

    Комментарии (24)
  7. JavaScript / Говнокод #12774

    +161

    1. 01
    2. 02
    3. 03
    4. 04
    5. 05
    6. 06
    7. 07
    8. 08
    9. 09
    10. 10
    11. 11
    12. 12
    function printf(format, value) {
          return format.replace(/%s/, value.toString());
        }
    
        return {
    
          updateProgressBar: function (percentage) {
            console.log("update \"progressBar\" status");
            progressBar.innerHTML = printf("<p>%s %</p>", percentage);
          }
    
        };

    __proto__, 21 Марта 2013

    Комментарии (15)
  8. Java / Говнокод #12772

    +71

    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
    public static Connection getDBConnectionReader() throws Exception {
            Connection conn = null;
            try {
                conn = enrollmentsDataSource.getConnection();
            } catch (SQLException e) {
                LOGGER.warn("SQL Exception: get DB connection reader", e);
                resetConnectionReader();
                try {
                    conn = enrollmentsDataSource.getConnection();
                } catch (SQLException e1) {
                    throw new Exception("Exception: get DB connection reader", e1);
                }
            }
            return conn;
    }

    Фрактал...

    amarfey, 20 Марта 2013

    Комментарии (20)
  9. PHP / Говнокод #12771

    +149

    1. 1
    2. 2
    $ev = '$atHtml[] = template::translateTemplate('.$atArr[0].'::getHTML($atArr[1]));';
    eval($ev);

    Самый простой способ заставить работать статический метод класса из переменной в PHP ниже 5.3.

    Lander, 20 Марта 2013

    Комментарии (15)
  10. C++ / Говнокод #12770

    +19

    1. 1
    2. 2
    3. 3
    4. 4
    5. 5
    6. 6
    struct BufInfo 
    {
    	const tbal::Bitmap &src, &dst;
    	int y1, y2;
    	BufInfo (const tbal::Bitmap &scr, const tbal::Bitmap &dst, int y1, int y2) : src(src), dst(dst), y1(y1), y2(y2) {}
    };

    Как можно проебать час жизни...

    TarasB, 20 Марта 2013

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