1. Лучший говнокод

    В номинации:
    За время:
  2. Си / Говнокод #11433

    +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
    50. 50
    51. 51
    static struct passwd *pd=getpwuid(st->st_uid);
      if(pd==NULL){
        fprintf(stderr, "no correspound user!\n");
      }
      char *perm=(char*)malloc(16);
      if(perm==NULL){fprintf(stderr, "out of memory!\n");return -1;}
       memset( perm,'\0',16); 
      if(st->st_mode & S_ISUID){perm[0]='s';} else perm[0]='-';
      if(st->st_mode & S_IRUSR){perm[1]='r';} else perm[1]='-';
      if(st->st_mode & S_IWUSR){perm[2]='w';} else perm[2]='-';
      if(st->st_mode & S_IXUSR){perm[3]='x';} else perm[3]='-';
      if(st->st_mode & S_IRGRP){perm[4]='r';} else perm[4]='-';
      if(st->st_mode & S_IWGRP){perm[5]='w';} else perm[5]='-';
      if(st->st_mode & S_IXGRP){perm[6]='x';} else perm[6]='-';
      if(st->st_mode & S_IROTH){perm[7]='r';} else perm[7]='-';
      if(st->st_mode & S_IWOTH){perm[8]='w';} else perm[8]='-';
      if(st->st_mode & S_IXOTH){
        if(st->st_mode & S_ISVTX){
          perm[9]='t';
        }
       else perm[9]='x';
        
      } else perm[9]='-';
      if(st->st_mode & S_ISUID){
       if(st->st_mode & S_IXUSR){
         perm[4]='s';
       } else perm[4]='S';
      }
       if(st->st_mode & S_ISGID){
        if(st->st_mode & S_IXGRP){
        perm[7]='s';
        } else perm[7]='S';
      }
      if(st->st_mode & S_ISVTX){
        if(st->st_mode & S_IXOTH){perm[9]='t';} else {
        perm[9]='T';
        }
      }
       if((st->st_mode & S_IFMT) == S_IFDIR) { perm[0]='d';}
       if((st->st_mode & S_IFMT)==S_IFSOCK){ perm[0]='s';}
       if((st->st_mode & S_IFMT) == S_IFCHR) { perm[0]='c';}
       if((st->st_mode & S_IFMT)==S_IFCHR){perm[0]='c';} else if(st->st_mode & S_IFBLK){perm[0]='b';} else
       if((st->st_mode & S_IFMT)== S_IFREG){ perm[0]='-';}
       if((st->st_mode &S_IFMT)==S_IFBLK) { perm[0]='b';}
       if((st->st_mode & S_IFMT)==S_IFIFO) { perm[0]='p';}
       if((st->st_mode & S_IFMT)== S_IFLNK){ perm[0]='l';}
      if(!S_ISDIR(st->st_mode)){
          if(S_ISREG(st->st_mode)){
    	printf("<file type=\"regular file\" permissions=\"%s\" owner=\"%s\" group=\"%d\" size=\"%d\">%s</file>\n",perm,pd->pw_name,st->st_gid,st->st_size,dir);
    	return 0;
          };

    Права доступа

    AliceGoth, 17 Июля 2012

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

    +168

    1. 1
    2. 2
    3. 3
    4. 4
    5. 5
    <script>
        var ROOT = '/';
        if (ROOT == '/')
            ROOT = '';
    </script>

    larikov, 15 Июля 2012

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

    +31

    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
    #include <iostream>
    using namespace std;
    
    struct RefStruct {
        RefStruct(int &ref) :
            m_ref(ref)
        {}
        
        int getRefValue() const {
            return m_ref;
        }
    
    private:
        int &m_ref;
    };
    
    int main(int argc, char *argv[]) {
        int a = 0xa;
        int b = 0xb;
    
        RefStruct s(a);
        RefStruct *p = &s;
        
        *(reinterpret_cast<int **>(p)) = &b;
        
        cout << "RefValue: " << hex << s.getRefValue() << endl;
    
        return 0;
    }

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

    Как вы думаете, что будет на выхлопе?

    Elvenfighter, 15 Июля 2012

    Комментарии (10)
  5. Pascal / Говнокод #11378

    +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
    procedure TForm1.Timer1Timer(Sender: TObject);
    begin
            if ((Edit1.Text <> '') or (Edit4.Text <> '')) then
                    begin
                    Button1.Enabled:=true;
                    end;
    
            if ((Edit1.Text = '') or (Edit4.Text = '')) then
                    begin
                    Button1.Enabled:=false;
                    end;
    end;

    Таким образом настоящий ветеран говнокода защищает свое детище от "кривых" рук.

    CyberKiller, 08 Июля 2012

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

    +23

    1. 1
    2. 2
    if(this==NULL)
      return;

    HaskellGovno, 04 Июля 2012

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

    +155

    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
    switch(navigator.appName) {
       case "Microsoft Internet Explorer":
          Key = "event.ctrlKey && event.keyCode == 13";
          document.onkeydown = get_key;
          break;
       case "Netscape":
          Key = "(e.modifiers == 2 && e.which == 10) || (e.ctrlKey && e.which == 13)";
          document.captureEvents(Event.KEYDOWN);
          document.onkeydown = get_key;
          break;
    }
    }
    
    function get_key(e) {
    if (eval(Key)) {
    	if (check_postform()){
    		check_submit();
    		document.postform.submit();
    		submit_once(document.postform);
    	} else {return false}
    }

    http://forum.ixbt.com/

    jQuery, 03 Июля 2012

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

    +41

    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
    72. 72
    73. 73
    74. 74
    75. 75
    76. 76
    77. 77
    78. 78
    79. 79
    80. 80
    81. 81
    82. 82
    83. 83
    84. 84
    85. 85
    86. 86
    87. 87
    88. 88
    89. 89
    90. 90
    91. 91
    92. 92
    93. 93
    94. 94
    95. 95
    96. 96
    <?php
    ini_set('display_errors','On');
    error_reporting('E_ALL');
    mysql_connect("localhost","MySQL","satanus") or die(mysql_error());
    echo "Connected to mysql<br>";
    mysql_select_db("myurl") or die(mysql_error());
    echo "Connected to Database";
    $ms=mysql_info();
    echo $ms;
    
    function isValidURL($url)
    {
    return preg_match('|^(http)(s)?://([a-z0-9-]+\.[a-z-]+)?(localhost)?(\.[a-z0-9-_/&+?=%]+)*(:[0-9]+)?(/[^.]+)?$|i', $url);
    }
    function parse_secure($arg){
      $txt=preg_replace('/((<[^>]*>(.*)<\/[^>]*>|\'|")|(<[^>]*>)|(?:(\s+|>|<|\d+)(?:SELECT|FROM|UNION|ORDER BY|GROUP BY|UPDATE|DELETE|INSERT|OR|AND|NOT)(\s+|>|<|\d+))|<)/i','',$arg);
      return $txt;
    }
    
    if(isset($_GET['pid'])){
        $pid=$_GET['pid'];
        $pid=parse_secure($pid);
        $options=array('options'=>array('min_range'=>0,'max_range'=>1000001));
          if(filter_var($pid,FILTER_VALIDATE_INT,$options)){
            printf("pid correct %d",$pid);
        } else {
            printf("pid incorrect");exit(2);  
        }
        $query="SELECT url FROM myurl.base WHERE id='$pid'";
        $res=mysql_query($query);
        if($res){
          $row=mysql_fetch_assoc($res);
          header('Location: '.$row['url']);
        }
    };
    
    if(isset($_GET['cat']) && isset($_GET['scat'])){
      $cat=$_GET['cat'];
      $cat=parse_secure($cat);
      if(isset($_GET['ps'])){
        $ps = $_GET['ps'];
        $ps=parse_secure($ps);
      } else {
      $ps =0;
      };
      $catl=iconv_strlen($thm);
      echo "<html><head><title>Short url generator</title></head><body>";
      echo "<h1>$cat</h1><br>";
          $qry="SELECT bs.id as pid,bs.url url,bs.subcategory scat,bs.category cat FROM base bs INNER JOIN category ct ON ct.id=bs.category WHERE bs.subcategory=\"".$_GET['scat']."\" AND bs.category=\"".parse_secure($_GET['cat'])."\"";
          $res=mysql_query($qry);
          if($res){
            while($row=mysql_fetch_assoc($res)){
              echo "<a href=\"http://".$_SERVER['SERVER_NAME'].$_SERVER['SCRIPT_NAME']."?pid=".$row['pid']."\">http://".$_SERVER['SERVER_NAME'].$_SERVER['SCRIPT_NAME']."?pid=".$row['pid']."</a> ".$row['url'];
              echo " <a href=\"http://".$_SERVER['SERVER_NAME'].$_SERVER['SCRIPT_NAME']."?cat=".$row['cat']."&scat=".$row['scat']."\">http://".$_SERVER['SERVER_NAME'].$_SERVER['SCRIPT_NAME']."?cat=".$row['cat']."&scat=".$row['scat']."</a>".$row['url'];
              echo "<br>";
            }
          }
    exit(3);
    };
    
    if(isset($_GET['cat'])){
      $cat=parse_secure($_GET['cat']);
      $scat=parse_secure($_GET['scat']);
      if(isset($_GET['ps'])){
        $ps = $_GET['ps'];
      } else {
      $ps =0;
      };
      $catl=iconv_strlen($thm);
      echo "<html><head><title>Short url generator</title></head><body>";
      echo "<h1>$cat</h1><br>";
          $qry="SELECT bs.id as pid,bs.url url,bs.subcategory scat,bs.category cat FROM base bs INNER JOIN category ct ON ct.id=bs.category WHERE bs.category=\"".$cat."\" OR ( bs.subcategory=\"".$scat."\" AND bs.category=\"".$cat."\")";
          $res=mysql_query($qry);
          if($res){
            while($row=mysql_fetch_assoc($res)){
              echo "<a href=\"http://".$_SERVER['SERVER_NAME'].$_SERVER['SCRIPT_NAME']."?pid=".$row['pid']."\">http://".$_SERVER['SERVER_NAME'].$_SERVER['SCRIPT_NAME']."?pid=".$row['pid']."</a>".$row['url'];
              echo " <a href=\"http://".$_SERVER['SERVER_NAME'].$_SERVER['SCRIPT_NAME']."?cat=".$row['cat']."&scat=".$row['scat']."\">http://".$_SERVER['SERVER_NAME'].$_SERVER['SCRIPT_NAME']."?cat=".$row['cat']."&scat=".$row['scat']."</a>".$row['url'];
              echo "<br>";
            }
          }
    };
    
    if(isset($_POST['url']) && (isset($_POST['category']) || isset($_POST['cat'])) && (isset($_POST['subcat']) || isset($_POST['scat']))){
      $url=$_POST['url'];
    $purl=substr($url,0,26);
      if($purl=="http://".$_SERVER['SERVER_NAME']."/")exit(0);
    $purl=substr($url,0,30);
      if($purl=="http://www.".$_SERVER['SERVER_NAME']."/")exit(0);
      $cat=parse_secure($_POST['category']);
      $catid=parse_secure($_POST['cat']);
      $scat=parse_secure($_POST['subcat']);
      $scatid=parse_secure($_POST['scat']);
      if($url) {
          if(!isValidURL($url))
    {
    $errMsg .= "* Please enter valid URL including http://<br>";

    AliceGoth, 21 Июня 2012

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

    +140

    1. 01
    2. 02
    3. 03
    4. 04
    5. 05
    6. 06
    7. 07
    8. 08
    9. 09
    10. 10
    11. 11
    12. 12
    foreach (glob('data/'.$year . "/unzip/*.txt") as $filename) {
    	    $name_file = explode(".",$filename);
    		
    		if (!file_exists($name_file[0].".out")){
    		// заливаем в jar
            exec('nohup java -jar "noaa.jar" ' . $filename . ' ' . $name_file[0] . '.out > /dev/null &', $log, $log1);
            echo "Insert " . $filename . " Complete!\n\r";
    		
    		usleep(10000);
    		}
    		else echo "You have uploaded this file already!\n\r";
        }

    Copy-Paste, 20 Июня 2012

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

    +140

    1. 1
    2. 2
    3. 3
    4. 4
    5. 5
    6. 6
    7. 7
    private static object Clone(object obj)
    {
    	object newObj = Activator.CreateInstance(obj.GetType());
    	foreach (PropertyInfo pi in obj.GetType().GetProperties())
    		pi.SetValue(newObj, pi.GetValue(obj, null), null);
    	return newObj;
    }

    Потребовалось клонировать объект библиотечного класса со множеством свойств.

    Steve_Brown, 20 Июня 2012

    Комментарии (10)
  11. SQL / Говнокод #11244

    −119

    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
    select a, trim(both ',' from max(SYS_CONNECT_BY_PATH(b, ',')))bb from (
      select count(1) over (partition by a order by /* Важно:*/ a,b /*!*/)rn, a, b from (
    
        select a, b from (
          select 1 a, 'a' b from dual union all
          select 1 a, 'b' b from dual union all
          select 2 a, 'c' b from dual union all
          select 2 a, 'd' b from dual union all
          select 2 a, 'e' b from dual union all
          select 3 a, 'f' b from dual
        ) order by dbms_random.value
    
      )
    )
    start with rn=1 connect by nocycle prior a=a and prior rn+1=rn
    group by a;

    Задача на агрегацию с конкатенацией строк. Можно решить правильно - через свой агрегирующий объект, а можно так, "не по правилам" ))

    RomaShka, 20 Июня 2012

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