1. Ruby / Говнокод #9493

    −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
    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
    # ищем позиции в гугле
       def search(request, keyword, p = nil)
          proxy = nil
       # инициализация прокси
          if p # обьект с прокси-серверами
             proxy = "http://#{p.proxy}/" # случайный прокси
             proxy_working = false 
             while not proxy_working
                begin
                   timeout(5) { open(request, :proxy => proxy) }
                rescue Timeout::Error
                   $log.put "bad broxy #{proxy}"
                   proxy = "http://#{p.proxy}/"
                   next
                rescue Errno::ECONNREFUSED
                   $log.put "bad broxy #{proxy}"
                   proxy = "http://#{p.proxy}/"
                   next
                rescue OpenURI::HTTPError
                   $log.put "bad broxy #{proxy}"
                   proxy = "http://#{p.proxy}/"
                   next
                else
                   $log.put "working #{proxy}"
                   proxy_working = true
                end
             end
          end
    # код

    baldrs, 20 Февраля 2012

    Комментарии (0)
  2. C++ / Говнокод #9492

    +141

    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
    #include <iostream>
    using namespace std;
    
    int main()
    {
        int n, m, c, b, f = 0;
        cin >> n >> m;
        int A[n][m];
        for(int i = 0; i < n; i++ )
        {
            for(int j = 0; j < m; j++)
            {
                cin >> A[i][j];
            }
        }
    
            for(int i = 0; i < n; i++ )
            {
                b = A[i][0];
                for(int j = 0; j < m; j++)
                {
                c = A[0][j];
                for(int a = 0; a < n; a++)
                 {
    
                     if(c < A[0][a])
                     {
                         c = A[0][a];
                     }
                 }
                 for(int k = 0; k < m; k++)
                 {
    
                     if(b > A[k][0])
                     {
                        b = A[k][0];
                     }
                 }
    
    
                 if(b == c)
                 {
                     f++;
                 }
                }
            }
                cout << f;
                return 0;
    }

    Задана матрица K, содержащая n строк и m столбцов. Седловой точкой этой матрицы назовем элемент, который одновременно является минимумом в своей строке и максимумом в своем столбце.

    Найдите количество седловых точек заданной матрицы.
    Вроде всё правильно, а выдаёт, что есть необработаное исключение.Что не так?

    alexsid13, 20 Февраля 2012

    Комментарии (20)
  3. C# / Говнокод #9491

    +950

    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
    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Text;
    using System.Windows;
    using System.Windows.Controls;
    using System.Windows.Data;
    using System.Windows.Documents;
    using System.Windows.Input;
    using System.Windows.Media;
    using System.Windows.Media.Imaging;
    using System.Windows.Navigation;
    using System.Windows.Shapes;
    
    namespace bibl2
    {
        public class DBS_BUTTON : Button
        {
            static DBS_BUTTON()
            {
            }
            protected void OnClick(object sender, EventArgs e)
            {
                Click(sender, e);
            }
        }
    }

    Rusmikle, 20 Февраля 2012

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

    +166

    1. 1
    2. 2
    3. 3
    4. 4
    5. 5
    // сколько сегодня зарегестрировалось по приглашению
        public function getTodayCount() {
    	$query = self::select("select * from invites where date='" . date("Y.m.d") . "'");
    	return count($query);
        }

    просто нет слов, одни эмоции :)

    CRRaD, 20 Февраля 2012

    Комментарии (13)
  5. Java / Говнокод #9489

    +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
    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
    @Override
        public boolean equals(Object o) {
            if (this == o) return true;
            if (o == null || getClass() != o.getClass()) return false;
    
            Sdbankpd sdbankpd = (Sdbankpd) o;
    
            if (bjbank != null ? !bjbank.equals(sdbankpd.bjbank) : sdbankpd.bjbank != null) return false;
            if (bjbvpd != null ? !bjbvpd.equals(sdbankpd.bjbvpd) : sdbankpd.bjbvpd != null) return false;
            if (bjcncd != null ? !bjcncd.equals(sdbankpd.bjcncd) : sdbankpd.bjcncd != null) return false;
            if (bjcust != null ? !bjcust.equals(sdbankpd.bjcust) : sdbankpd.bjcust != null) return false;
            if (bjcycd != null ? !bjcycd.equals(sdbankpd.bjcycd) : sdbankpd.bjcycd != null) return false;
            if (bjdfin != null ? !bjdfin.equals(sdbankpd.bjdfin) : sdbankpd.bjdfin != null) return false;
            if (bjdnwd != null ? !bjdnwd.equals(sdbankpd.bjdnwd) : sdbankpd.bjdnwd != null) return false;
            if (bjefmt != null ? !bjefmt.equals(sdbankpd.bjefmt) : sdbankpd.bjefmt != null) return false;
            if (bjeyd != null ? !bjeyd.equals(sdbankpd.bjeyd) : sdbankpd.bjeyd != null) return false;
            if (bjhocy != null ? !bjhocy.equals(sdbankpd.bjhocy) : sdbankpd.bjhocy != null) return false;
            if (bjlccy != null ? !bjlccy.equals(sdbankpd.bjlccy) : sdbankpd.bjlccy != null) return false;
            if (bjlcd != null ? !bjlcd.equals(sdbankpd.bjlcd) : sdbankpd.bjlcd != null) return false;
            if (bjmdel != null ? !bjmdel.equals(sdbankpd.bjmdel) : sdbankpd.bjmdel != null) return false;
            if (bjmodt != null ? !bjmodt.equals(sdbankpd.bjmodt) : sdbankpd.bjmodt != null) return false;
            if (bjmrdt != null ? !bjmrdt.equals(sdbankpd.bjmrdt) : sdbankpd.bjmrdt != null) return false;
            if (bjpcfq != null ? !bjpcfq.equals(sdbankpd.bjpcfq) : sdbankpd.bjpcfq != null) return false;
            if (bjpcfu != null ? !bjpcfu.equals(sdbankpd.bjpcfu) : sdbankpd.bjpcfu != null) return false;
            if (bjpeyd != null ? !bjpeyd.equals(sdbankpd.bjpeyd) : sdbankpd.bjpeyd != null) return false;
            if (bjrdnb != null ? !bjrdnb.equals(sdbankpd.bjrdnb) : sdbankpd.bjrdnb != null) return false;
            if (bjsbrc != null ? !bjsbrc.equals(sdbankpd.bjsbrc) : sdbankpd.bjsbrc != null) return false;
            if (bjslcd != null ? !bjslcd.equals(sdbankpd.bjslcd) : sdbankpd.bjslcd != null) return false;
            if (bjsuc != null ? !bjsuc.equals(sdbankpd.bjsuc) : sdbankpd.bjsuc != null) return false;
            if (bjtylc != null ? !bjtylc.equals(sdbankpd.bjtylc) : sdbankpd.bjtylc != null) return false;
            if (bjurpt != null ? !bjurpt.equals(sdbankpd.bjurpt) : sdbankpd.bjurpt != null) return false;
            if (bjzone != null ? !bjzone.equals(sdbankpd.bjzone) : sdbankpd.bjzone != null) return false;
    
            return true;
        }

    Обработка резальтов селекта

    timmson666, 20 Февраля 2012

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

    +163

    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
    $textb = Db::getInstance()->ExecuteS("SELECT * FROM "._DB_PREFIX_."productotzyv WHERE `id_product` = ".$idProduct);
    		$count_otz = count($textb);
    		if ($p==0) $p = 1;
    		$limit = 99;
    		$texta = get("SELECT *, date_format(data, '%d.%m.%Y') as data_ FROM "._DB_PREFIX_."productotzyv WHERE `id_product` = ".$idProduct." LIMIT ".$limit);
    		$ed = count(Db::getInstance()->ExecuteS("SELECT * FROM "._DB_PREFIX_."productotzyv WHERE `id_product`=".intval($_GET['id_product'])." and `rating`=1"));
    		$dva = count(Db::getInstance()->ExecuteS("SELECT * FROM "._DB_PREFIX_."productotzyv WHERE `id_product`=".intval($_GET['id_product'])." and `rating`=2"));
    		$tri = count(Db::getInstance()->ExecuteS("SELECT * FROM "._DB_PREFIX_."productotzyv WHERE `id_product`=".intval($_GET['id_product'])." and `rating`=3"));
    		$four = count(Db::getInstance()->ExecuteS("SELECT * FROM "._DB_PREFIX_."productotzyv WHERE `id_product`=".intval($_GET['id_product'])." and `rating`=4"));
    		$five = count(Db::getInstance()->ExecuteS("SELECT * FROM "._DB_PREFIX_."productotzyv WHERE `id_product`=".intval($_GET['id_product'])." and `rating`=5"));
            $uri = $_SERVER['REQUEST_URI'];
            $i = strrpos($uri, "/");
            $uri1 = substr($uri, 0, $i);
            $i = strrpos($uri1, "/");
            $uri = substr($uri1, 0, $i);
            $uri = $uri."/";
            $monUrl = "http://".$_SERVER['HTTP_HOST'].$uri;
    		foreach ($textb as $s => $a){
    			$text += $a['rating'];
    		}
    
    		$smarty->assign('ed', $ed);
    		$smarty->assign('dva', $dva);
    		$smarty->assign('tri', $tri);
    		$smarty->assign('four', $four);
    		$smarty->assign('five', $five);
    		$smarty->assign('ed_proc', $ed/$count_otz*100);
    		$smarty->assign('dva_proc', $dva/$count_otz*100);
    		$smarty->assign('tri_proc', $tri/$count_otz*100);
    		$smarty->assign('four_proc', $four/$count_otz*100);
    		$smarty->assign('five_proc', $five/$count_otz*100);
    		$smarty->assign('rating2', round($text/$count_otz, 0));
    		$smarty->assign('countotz', $count_otz.' '.endingsForm($count_otz,"отзыв","отзыва","отзывов"));
    		$smarty->assign('monUrl',$monUrl);
    		$smarty->assign('text',$texta);

    Prestashop, реализация отображения отзывов и рейтига товара

    uint, 19 Февраля 2012

    Комментарии (12)
  7. PHP / Говнокод #9487

    +158

    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
    function get($sel, $od='', $show_error=1)
    {
      global $__DB_CONN;
      $select=$sel;
      //echo $select.'<br>';
      if($od=="")
      {
        $res=sql_execute($select, $show_error);
        if(!$res)
          return array();
        $mc_runtime=get_magic_quotes_runtime();
        set_magic_quotes_runtime(0);
        $mas=array();
        while($v=@mysql_fetch_assoc($res))
          array_push($mas, $v);
        set_magic_quotes_runtime($mc_runtime);
        return $mas;
      }
    ... //тоже самое еще пару раз
      if($od=="by id")
      {
        $res=sql_execute($select, $show_error);
        if(!$res)
          return array();
        $mc_runtime=get_magic_quotes_runtime();
        set_magic_quotes_runtime(0);
        $mas=array();
        while($v=mysql_fetch_assoc($res))
          $mas[$v["id"]]=$v;
        set_magic_quotes_runtime($mc_runtime);
        return $mas;
      }
      if($od=="ins")
      {
        $res=sql_execute($select, $show_error);
        return mysql_insert_id($__DB_CONN);
      }
      return;
    }
    
    function get2($sel, $od='', $show_error=1)
    {
      global $__DB_CONN2;
      $select=$sel;
      //echo $select.'<br>';
      if($od=="")
      {
        $res=sql_execute2($select, $show_error);
        if(!$res)
          return array();
        $mc_runtime=get_magic_quotes_runtime();
        set_magic_quotes_runtime(0);
        $mas=array();
        while($v=@mysql_fetch_assoc($res)) {
    	foreach($v as $ii=>$vv)
            $v[$ii] = iconv('windows-1251','utf-8' ,$vv);
       array_push($mas,$v);
      }
        set_magic_quotes_runtime($mc_runtime);
        return $mas;
      }
    ... //тоже самое еще пару раз
      if($od=="ins")
      {
        $res=sql_execute2($select, $show_error);
        return mysql_insert_id($__DB_CONN2);
      }
      return;
    }

    Функции для работы с бд!

    uint, 19 Февраля 2012

    Комментарии (4)
  8. C++ / Говнокод #9486

    +1000

    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
    void drawFigure()
    {
    	for(int i=0;i<figMaxI;i++)
    		for(int j=0;j<figMaxY;j++)
    			if(figure.space[i][j].wut==1)
    			{
    				if(figure.y+i>=2)
    					if(figureEffekt == 1)
    					{
    						engine->drawTexture2D(figure.picture.texID, gameSpace.x+((figure.x+j)*34)-effekt[0].x, gameSpace.y+((figure.y+i)*34)-effekt[0].y, 34, 34, 0.4, 0, 0);
    						engine->drawTexture2D(figure.picture.texID, gameSpace.x+((figure.x+j)*34)+effekt[0].y, gameSpace.y+((figure.y+i)*34)+effekt[0].x, 34, 34, 0.8, 0, 0);
    						engine->print(fontAlphabet,0, figure.space[i][j].letter , gameSpace.x+((figure.x+j)*34)+6+effekt[0].y,gameSpace.y+((figure.y+i)*34)+4+effekt[0].x,1,0,2);
    					}
    					else
    					{
    						engine->drawTexture2D(figure.picture.texID, gameSpace.x+((figure.x+j)*34), gameSpace.y+((figure.y+i)*34), 34, 34, 1, 0, 0);
    						engine->print(fontAlphabet,0, figure.space[i][j].letter , gameSpace.x+((figure.x+j)*34)+6,gameSpace.y+((figure.y+i)*34)+4,1,0,2);
    					}
    			}
    }

    великое и могучее ООП в действии

    -ggorky, 19 Февраля 2012

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

    +154

    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
    <?php
    iconv_set_encoding("input_encoding", "UTF-8");
    iconv_set_encoding("internal_encoding", "UTF-8");
    iconv_set_encoding("output_encoding", "UTF-8");
    
    $curl = curl_init();
    $curl_set = array(
            CURLOPT_COOKIESESSION => 0,
            CURLOPT_VERBOSE => 1,
            CURLOPT_USERAGENT => 'Opera/9.60 (J2ME/MIDP; Opera Mini/4.2.14912/812; U; ru) Presto/2.4.15',
            CURLOPT_RETURNTRANSFER => 1
        );
    
    curl_setopt_array($curl, $curl_set);
    
    for($i=1;$i<50;$i++){
        $url = 'http://utemplate.ru/load/19-1-0-'.$i;
        curl_setopt($curl, CURLOPT_URL ,$url);
        $data = curl_exec($curl);
        preg_match_all('#<div class="entrytitle">(.*)</div>(.*)<hr>#isU', $data, $matches);
        $content[title] = $matches[1][0];
        $content[desc] = $matches[2][0];
        unset($matches);
        preg_match_all('#<img src\="http://utemplate.ru/_ld/0/(.*)"/>#isU', $data, $matches);
        $content[img] = $matches[1][0];
        if($content[title] AND $content[desc] AND $content[img]){
            unset($matches);
            mkdir($content[title], 0777);
            curl_setopt($curl, CURLOPT_URL ,'http://utemplate.ru/_ld/0/'.$content[img]);
            $image = curl_exec($curl);
            curl_setopt($curl, CURLOPT_URL ,'http://utemplate.ru/load/0-0-0-'.$i.'-20');
            $file_inf = curl_exec($curl);
            preg_match_all('#<A HREF="(.*)"#isU', $file_inf, $matches);
            $ext_file = substr($matches[1][0], -4);
            $ext_img = substr($content[img], -4);
            curl_setopt($curl, CURLOPT_URL , $matches[1][0]);
            $file = curl_exec($curl);
            file_put_contents($content[title].'/'.$content[title].$ext_file, $file);
            file_put_contents($content[title].'/'.$content[title].$ext_img, $image);
            file_put_contents($content[title].'/'.$content[title].'.txt', $content[title]."\n".$content[desc]);
        }
    
    };

    Злобный самописный, рабочий граббер uCoz сайта

    __construct, 19 Февраля 2012

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

    +964

    1. 1
    2. 2
    3. 3
    4. 4
    private static int CompareWidgetsByOrder(Widget x, Widget y)
    {
          return x == null ? y == null ? 0 : 1 : y == null ? 0 : x.order > y.order ? -1 : x.order < y.order ? 1 : 0;
    }

    Вот до чего доводит стремление к компактности кода.

    nomad99111, 19 Февраля 2012

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