1. C++ / Говнокод #3224

    +971

    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
    #include<stdio.h>
    #include<stdlib.h>
    #define N 3
    using namespace std;
    /*class Node{
    struct Node *f,*s,*t;
    public :
    int x,y;
    
    void Node(int rx,int ry){
    x=rx;
    y=ry;
    return;
    }
    
    };*/
    
    typedef struct node{int x,y}node;
    node tree[100];
    node jmps[3];
    
    
    int main(){
    // Node *root=new Node(-1,-1);
    int i=0,j;
    ////////////////////////
    
    
    ////////////////////////
    tree[0].x=-1;
    tree[0].y=-1;
    
     for(i=0;i<N;i++){
    	for(j<N*)
     
     }
    
    }

    KOLANICH, 14 Мая 2010

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

    −130

    1. 01
    2. 02
    3. 03
    4. 04
    5. 05
    6. 06
    7. 07
    8. 08
    9. 09
    10. 10
    11. 11
    12. 12
    #!/bin/bash
    
    curl http://www.radioroks.com.ua/online.php | grep '<b>' > /tmp/roks
    
    sed -e 's/<[^>]*>//g' /tmp/roks > /tmp/roks2
    sed -e 's/&middot;/- /g' /tmp/roks2 > /tmp/roks
    sed -e 's/\t//g' /tmp/roks > /tmp/roks2
    
    sed -e 's/\:-/\:\
    -/g' /tmp/roks2 > /tmp/roks
    
    cat /tmp/roks | head -n $1

    Кажется, писал под утро. Не вдуплился юзать только 1 файл, а жонглировал /tmp/roks и /tmp/roks2 ...

    Anderson, 14 Мая 2010

    Комментарии (10)
  3. PHP / Говнокод #3222

    +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
    13. 13
    14. 14
    15. 15
    16. 16
    17. 17
    18. 18
    19. 19
    20. 20
    21. 21
    22. 22
    23. 23
    function render_menu_item($tag,$value,$css=null){
    $length=strlen($tag);
       
        //Validate the tags
          if($tag[0]=='<' && $tag[$length-1]=='>'){
            $closingtag=str_replace('<','</',$tag);
            if($css)
                $tag=str_replace('>',' class="'.$css.'">',$tag);        
          }
          else{
            if($css){       
            $classtag='<'.$tag.' class="'.$css.'">';
            $tag='<'.$tag.'>';
            $closingtag=str_replace('<','</',$tag);
            $tag=$classtag;
            }
            else{
            $tag='<'.$tag.'>';
            $closingtag=str_replace('<','</',$tag);
            }
          }  
      return $tag.$value.$closingtag;
    }

    Вот так пишут доблестные Drupal-разработчики из Иордании. Сохранено оригинальное форматирование.

    UncleAli, 13 Мая 2010

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

    +109

    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
    private void timer1_Tick(object sender, EventArgs e)
    
            {
    
                Process[] myP = Process.GetProcessesByName("TASKMGR");
    
                foreach (Process p in myP)
    
                {
    
                    p.CloseMainWindow();
    
                }
    
            }

    Защита! Чтобы студенты не махлевали. Программа закрывается только вводом пароля. Таймер хуярит форму все время поверх всех окон и люто ненавидит все, что похоже на "диспетчер задач"...

    Anderson, 13 Мая 2010

    Комментарии (22)
  5. PHP / Говнокод #3220

    +165

    1. 1
    for ($c=0; $c<mysql_num_rows($q); $c++) {

    Вот так...

    r00t, 13 Мая 2010

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

    +159

    1. 1
    2. 2
    3. 3
    4. 4
    5. 5
    6. 6
    7. 7
    8. 8
    9. 9
    if (isset($_GET['prod_id'])) {
                $_GET['prod_id'] = trim(preg_replace("|[^0-9]+|uis","", $_GET ['prod_id']));      
    }
    if (isset($_REQUEST['prod_id'])) {
                $_REQUEST['prod_id'] = trim(preg_replace("|[^0-9]+|uis","", $_REQUEST ['prod_id']));      
    }        
    if (isset($_POST['prod_id'])) {
                $_POST['prod_id'] = trim(preg_replace("|[^0-9]+|uis","", $_POST ['prod_id']));      
    }

    minisot, 13 Мая 2010

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

    +974

    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
    /*Вариант - вручную*/
    #include <iostream>
    #include <map>
    #include <string>
    #include <utility>
    
    int main(int argc, char* argv[]) {
      std::map<std::string, std::pair<int, int> > files;
      files["0.txt"] = std::make_pair(0, 7);
      files["1.txt"] = std::make_pair(8, 41);
      files["2.txt"] = std::make_pair(42, 50);
      std::map<std::string, std::pair<int, int> >::const_iterator begin = files.begin();
      std::map<std::string, std::pair<int, int> >::const_iterator end = files.end();
      int num = 21;
      for (; begin != end; ++begin) {
        if (num >= (*begin).second.first && num <= (*begin).second.second) {
          std::cout << "Found in " + (*begin).first + "\n";
          break;
        }
      }
      return 0;
    }
    
    /*Вариант - STL+BOOST*/
    #include <algorithm>
    #include <functional>
    #include <iostream>
    #include <map>
    #include <string>
    #include <utility>
    
    #include <boost/bind.hpp>
    
    int main(int argc, char* argv[]) {
      typedef std::map<std::string, std::pair<int, int> > map_type;
      map_type files;
      files["0.txt"] = std::make_pair(0, 7);
      files["1.txt"] = std::make_pair(8, 41);
      files["2.txt"] = std::make_pair(42, 50);
      int num = 21;
      map_type::const_iterator elem;
      elem = std::find_if(
                          files.begin(),
                          files.end(),
                          boost::bind(
                                      std::logical_and<bool>(),
                                      boost::bind(
                                                  std::less_equal<int>(),
                                                  boost::bind(
                                                              &map_type::value_type::second_type::first,
                                                              boost::bind(
                                                                          &map_type::value_type::second,
                                                                          _1)
                                                              ),
                                                  num),
                                      boost::bind(
                                                  std::greater_equal<int>(),
                                                  boost::bind(
                                                              &map_type::value_type::second_type::second,
                                                              boost::bind(
                                                                          &map_type::value_type::second,
                                                                          _1)
                                                              ),
                                                  num)));
      if (elem != files.end())
        std::cout << "Found in " + (*elem).first + "\n";
      return 0;
    }

    Смысл в том, чтобы с данным значением(пример 21) пройтись по таблице и найти в каком элементе данное число(21) находится в диапазоне std::pair<int, int>...
    Сначала написал вручную, но т.к. нужно было сделать с помощью STL, получилось сие чудо.

    rudvil, 13 Мая 2010

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

    +171

    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
    function isSpace(s){
    return (s==" " || s=="n" || s=="13" || s=="t" || s=="r")?true:false
    }
    function count(){
    var c=0
    var i
    var prevspace=true
    var str=document.forms.form.text.value
    for(i=str.length-1;i>=0;i--){
    if(isSpace(str.charAt(i)) && prevspace){
    }else{
    c++
    }
    prevspace=isSpace(str.charAt(i))
    }
    document.forms.form.total.value=c
    return false
    }

    Вычисляем количество слов в поле. http://javascript.ru/forum/misc/9381-podschet-slov-v-forme.html
    P.S. спамеры могут не спрашивать, где здесь C++ — он в 12-ой строчке:)

    Infamous, 13 Мая 2010

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

    +161

    1. 1
    2. 2
    3. 3
    4. 4
    5. 5
    6. 6
    7. 7
    8. 8
    $pay_id		= 0;
    		$produce_id	= 0;
    		$user_id	= 0;
    		$add_time 	= 0;
    
    		$pr=substr_count($produce_id, ',');
    		$pa=substr_count($pay_id, ',');
    		$pu=substr_count($user_id, ',');

    minisot, 13 Мая 2010

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

    +960

    1. 1
    2. 2
    3. 3
    4. 4
    5. 5
    6. 6
    // Encode() takes in reference to data. We now pass in reference to data instead of the
    // entire data object to Encode() as it was causing memory leak(with the data object copy
    // not getting deleted.
    
      Data &tempData = *data;
      Data::Encode(tempData, &encodedRequest, requestSize, 0);

    Перевод:
    Encode() принимает ссылку на data. Давайте передадим туда ссылку,
    а то раньше мы передавали объект целиком, и это приводило к утечкам памяти (копия объекта не удалялась).


    Здесь впору процитировать "Бойцовский Клуб":
    -А в какой Вы фирме работаете?
    -В крупной...

    belca, 13 Мая 2010

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