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

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

    +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
    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
    <?php
    //дата и время.
    $date1 = date('d.m.Y');
    $date2 = date('H:i:s');
    //$i - счётчик пользователей, $cnt - то, что будем выводить (в завершении)
    //$uall - Ссылки на пользователей онлайн
    $i = 0;
    $cnt = NULL;
    $uall = NULL;
    $db->query = "SELECT id, nick, timeof, online FROM ".$GLOBALS['pref']."users";
    $qonl = $db->query();
    $cnt .= "Всего участников ";
    
    while ($usronl = $db->farray($qonl)) {
    if ($usronl['online'] == TRUE) {
    $ar = explode("|:|", $usronl['timeof']);
    
    //Если сегодняшняя дата
    if ($ar[0] === $date1) {
    
    $est = explode(":", $ar[1]);
    $tm = explode(":", $date2);
    $m4 = $est[0] - $tm[0];
    $m5 = $tm[1] - $est[1];
    $m6 = "$m5";
    if (($est[0] === $tm[0]) && (($m5 <= 15))) {
    if ($i > 0) { $p = ","; } else { $p = NULL; }
    if ($i == 1) { $s = ","; } else { $s = NULL; }
    $i++;
    $uall .= $s."<a href=\"http://".$GLOBALS['url']."/users/
    profile/".$usronl['id']."/\" title=\"Посмотреть профиль\">".$usronl['nick']."<
    /a>".$p." ";
    
     } elseif (($m4 == -1) && ($m6{0} === "-" && $m5 <= -45)) {
    if ($i > 0) { $p = ","; } else { $p = NULL; }
    if ($i == 1) { $s = ","; } else { $s = NULL; }
    $i++;
    $uall .= $s."<a href=\"http://".$GLOBALS['url']."/users/
    profile/".$usronl['id']."/\" title=\"Посмотреть профиль\">".$usronl['nick']."<
    /a>".$p." ";
     }
      }
       } 
    	} //end while
    if ($i == 0) {
    $uall .= "никого";
    } else {
    
    $co = strlen($uall);
    $uall = substr($uall, 0, $co - 7);
    $uall .= ".";
    }
    $cnt .= "(".$i."):<BR>".$uall;
    
    ?>

    Писал вывод онлайн посетителей на сайте в 2009 году.

    Furry, 21 Февраля 2011

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

    +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
    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
    struct Event
    {
       int priority;
       bool operator<(Event e) const
       {
          return e.priority>priority;
       }
       
       virtual void operator() () = 0;
    };
    
    priority_queue<Event*, deque<Event*> > eventQueue;
    
    template <typename T, void (T::*g)()>
    struct  TEvent : Event
    { 
       T* parent;
       virtual void operator() () 
       {
          (parent->*g)();
       }
       TEvent (T* _parent) : parent(_parent){}
    };
    
    struct Entity
    {
       int foo;
       void AFunc() 
       {
          cout<<foo;
       }
    
       void BFunc() 
       {
          cout<<"Ololo";
       }
               
       typedef TEvent<Entity,&Entity::AFunc> someEvent;
       Entity(int _foo): foo(_foo){}
             
       void addEvent()
       {
          eventQueue.push(new someEvent(this));
       }
    };
    
    int main()
    {
       Entity foo(10);
       foo.addEvent();
       (*eventQueue.top())();
       return 0;
    }

    Один из самых сложных и неочевидных способов вывести в консоль число 10.
    (Этот код - проверка, будет ли работать прототип велосипедного делегата)

    CHayT, 15 Февраля 2011

    Комментарии (20)
  4. JavaScript / Говнокод #5680

    +172

    1. 1
    var rus_rl = ('А-Б-В-Г-Д-Е-Ё-Ж-З-И-Й-К-Л-М-Н-О-П-Р-С-Т-У-Ф-Х-Ц-Ч-Ш-Щ-Ъ-Ы-Ь-Э-Ю-Я-а-б-в-г-д-е-ё-ж-з-и-й-к-л-м-н-о-п-р-с-т-у-ф-х-ц-ч-ш-щ-ъ-ы-ь-э-ю-я').split('-');

    vugluskr, 15 Февраля 2011

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

    +166

    1. 1
    2. 2
    3. 3
    4. 4
    5. 5
    6. 6
    7. 7
    if(VisabilityOnOff==true){
    	   document.SearchForm.searchoption[0].disabled=true;
    	   document.SearchForm.searchoption[1].disabled=true;
    }else if(VisabilityOnOff==false){
    	   document.SearchForm.searchoption[0].disabled=false;
    	   document.SearchForm.searchoption[1].disabled=false;
    }

    kuku, 09 Февраля 2011

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

    +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
    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
    //построение суффиксного массива
    vector <int> getarr(string s) 
    {
      //s - исходная строка
      //суффиксный массив
      vector <int> arr;
      arr.resize(s.size());
      //массив цветов
      vector <int> col;
      col.resize(s.size());
      //массив для временных данных
      vector <int> buf;
      buf.resize(s.size());
      //массив для карманов сортировки
      vector <int> buck;
      buck.resize(max(L, (int) s.size()));
      //Шаг первый - начальная сортировка
      //мы хотим отсортировать буквы строки
      //посчитаем количество всех букв
      for (int i = 0; i < (int) s.size(); i++) 
        buck[s[i]]++;
      //преобразуем массив так, чтобы каждый элемент указывал на положение в массиве первой данной буквы
      int sum = 0; 
      for (int i = 0; i < L; i++) 
      {
        sum += buck[i];
    	buck[i] = sum - buck[i];
      }
      //теперь заполним массив arr: Теперь в нем суффиксы отсортированы по первой букве
      for (int i = 0; i < (int) s.size(); i++) 
        arr[buck[s[i]]++] = i;
      //теперь проставляем цвета: цвет увеличивается на 1 если следующая буква - другая
      col[arr[0]] = 0; 
      for (int i = 1; i < (int) s.size(); i++) 
        col[arr[i]] = col[arr[i-1]] + (s[arr[i]] != s[arr[i-1]]); 
      int cn = col[arr[s.size() - 1]] + 1;
      //Шаг второй - постепенное расширение подстрок
      //в начале цикла отсортированы подстроки длины l, а в конце - длины 2l
      for (int l = 1; l < (int) s.size(); l *= 2) 
      {
        //обнуляем массив buck  и заполняем для сортировки по col
        for (int i = 0; i < (int) s.size(); i++) 
          buck[i] = 0; 
        for (int i = 0; i < (int) s.size(); i++) 
          buck[col[i]]++; sum = 0; 
        for (int i = 0; i < cn; i++) 
          sum += buck[i], buck[i] = sum - buck[i];
        //строим новый массив в buf (не забываем сдвинуть указатель по модулю на l влево), затем копируем его в arr
        for (int i = 0; i < (int) s.size(); i++) 
          buf[buck[col[(arr[i] - l + s.size()) % s.size()]]++]=(arr[i] - l + s.size()) % s.size(); 
        arr = buf;
        //теперь перекрашиваем массив col: заполняем массив buf, увеличиваем цвет на единицу если один из цветов отличается, затем копируем
        buf[arr[0]] = 0; 
        for (int i = 1; i < (int) s.size(); i++) 
          buf[arr[i]] = buf[arr[i - 1]] + (col[arr[i]] != col[arr[i - 1]] || col[(arr[i] + l) % s.size()] != col[(arr[i - 1] + l) % s.size()]); 
        cn = buf[arr[s.size() - 1]] + 1; 
        col = buf;
      }
      //возвращаем результат
      return arr;
    }

    Это просто жуть

    chexov, 09 Февраля 2011

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

    +133

    1. 1
    2. 2
    3. 3
    4. 4
    5. 5
    6. 6
    7. 7
    8. 8
    /* тыц */
    /*wbr:after { content: '\00200B'; }*/
    /* they say it's better */
    wbr {
      width: 0px;
      display: inline-block;
      overflow: hidden;
    }

    Вконтакте.
    http://vkontakte.ru/css/rustyle.css?104
    Привет тем, кто сказал Пашке Дурову, что костыль - это не очень хорошо.

    7ion, 21 Января 2011

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

    +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
    $mazovia[18];
    	$iso[18];
    
    	$mazovia[0]  = chr(134);$iso[0]=chr(177);		//a~
    	$mazovia[1]  = chr(143);$iso[1]=chr(161);		//A~
    	$mazovia[2]  = chr(141);$iso[2]=chr(230);		//c~
    	$mazovia[3]  = chr(149);$iso[3]=chr(198);		//C~
    	$mazovia[4]  = chr(145);$iso[4]=chr(234);		//e~
    	$mazovia[5]  = chr(144);$iso[5]=chr(202);		//E~
    	$mazovia[6]  = chr(146);$iso[6]=chr(179);		//l~
    	$mazovia[7]  = chr(156);$iso[7]=chr(163);		//L~
    	$mazovia[8]  = chr(164);$iso[8]=chr(241);		//n~
    	$mazovia[9]  = chr(165);$iso[9]=chr(209);		//N~
    	$mazovia[10] = chr(162);$iso[10]=chr(243);		//o~
    	$mazovia[11] = chr(163);$iso[11]=chr(211);		//O~
    	$mazovia[12] = chr(158);$iso[12]=chr(182);		//s~
    	$mazovia[13] = chr(152);$iso[13]=chr(166);		//S~
    	$mazovia[14] = chr(166);$iso[14]=chr(188);		//z~
    	$mazovia[15] = chr(160);$iso[15]=chr(172);		//Z~
    	$mazovia[16] = chr(167);$iso[16]=chr(191);		//z|
    	$mazovia[17] = chr(161);$iso[17]=chr(175);		//Z|
           
            $strmazovia="";
    	$strIso="";
    	for ($i=0;$i<=17;$i++){
    		$strmazovia=$strmazovia."\\".$mazovia[$i];
    		$strIso= $strIso."\\".$iso[$i];
    	}
    
    
    	function convert($str){
    		global $strmazovia;
    		global $strIso;
    	        return StrTr($str,$strmazovia,$strIso);
    	}

    xaoc, 28 Декабря 2010

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

    +128

    1. 1
    if ((((((X >= -7) && (X<= -6) & (Y!=2)) || (X<= -2) && (X>= -6) && (Y<=0) && (Y>= -1) && (Y== 0.25*X + 0.5) || (X+ -2)*(X+ -2) + (Y+2)*(Y+2)==4) && (X >= -2) && (X<=0) && (Y>=0) && (Y<=2)|| (((X*X)+(Y*Y)==4)) && ((X>=0) && (X<=2) && (Y>=0) && (Y<=2))) || ((Y==0.5*X-1) && (X>=2) && (Y<=3) & (Y!=0)))) Console.WriteLine("Принадлежит");

    HIMen, 23 Декабря 2010

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

    +153

    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
    template <class TList, template <class> class Unit>
        class GenScatterHierarchy;
     template <class T1, class T2, template <class> class Unit>
        class GenScatterHierarchy<Typelist<T1, T2>, Unit>
            : public GenScatterHierarchy<Private::ScatterHierarchyTag<T1, T2>, Unit>
            , public GenScatterHierarchy<T2, Unit>
        {
        public:
            typedef Typelist<T1, T2> TList;
            typedef GenScatterHierarchy<Private::ScatterHierarchyTag<T1, T2>, Unit> LeftBase;
            typedef GenScatterHierarchy<T2, Unit> RightBase;
            template <typename T> struct Rebind
            {
                typedef Unit<T> Result;
            };
        };

    Говногость, 21 Декабря 2010

    Комментарии (20)
  11. Ruby / Говнокод #4974

    −115

    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
    #!/usr/bin/ruby1.8
    
    require 'mysql'
    $KCODE = 'UTF8'
    
    class Country
      @@country = Array.new
      @@insert_query = String.new
      @@db = Mysql
    
      def initialize(filename)
        file = File.open(filename)
        while !file.eof?
          value, index = file.readline.split(/\s+/u)
          @@country[index.to_i] = value.to_s
        end
        file.close
      end
    
      def database_connect
        @@db = Mysql.new('localhost','username','userpass','userdatabase')
        begin
          @@db.query("SET NAMES utf8")
        rescue
          puts @@db.error
        end
      end
    
      def create_query
        begin
          result = @@db.query("SELECT * FROM table")
        rescue
          puts @@db.error
        end
        result.each_hash do |field|
          @@country.each_index do |index|
          @@insert_query += "UPDATE table SET position = #{index} WHERE caption = '#{field['caption']}';" if @@country[index] == field['caption']
          end
        end
      end
    
      def execute_query
        begin
          @@insert_query.split(/;/u).each { |query| @@db.query(query) }
          puts "result: #{@@db.errno}" if @@db.errno
        rescue
          puts @@db.error
        end
      end
    
      def database_disconnect
        @@db.close
      end
    end
    
    cnt = Country.new('country.txt')
    # connect to DB
    cnt.database_connect
    # construct query
    cnt.create_query
    # execute constructed query
    cnt.execute_query
    # close connect
    cnt.database_disconnect

    Ну можно же как-то сделать лучше?

    avastor, 19 Декабря 2010

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