1. JavaScript / Говнокод #9232

    +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
    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
    Battle = new Class({
    	// Options
    	selected: 1,
    	onPopupClose: function() {},
    	
    	// Class initalisation
    	initialize: function(options) {
    		Object.append(this, options);
    	},
    	
    	// Open popup
    	initPopup: function(title, selection) {
    		this.selected = selection;
    		this.popup = new LightFace.Static({
    			title: title,
    			content: 'vote-options'
    		});
    	},
    	
    	// Vote
    	vote: function(social_network) {
    		var share = this.selected == 1 ? this.share1 : this.share2;
    		var pic   = this.selected == 1 ? this.pic1   : this.pic2;
    		var url   = '';
    		
    		if(social_network == 'fb') {
    			url  = 'http://www.facebook.com/sharer.php?s=100';
    			url += '&p[title]='     + encodeURIComponent(this.text);
    			url += '&p[summary]='   + encodeURIComponent(share);
    			url += '&p[url]='       + encodeURIComponent(this.url);
    			url += '&p[images][0]=' + encodeURIComponent(pic);
    		} else if(social_network == 'tw') {
    			url  = 'http://twitter.com/share?';
    			url += 'text='      + encodeURIComponent(this.text);
    			url += '&url='      + encodeURIComponent(this.url);
    			url += '&counturl=' + encodeURIComponent(this.url);
    		} else if(social_network == 'vk') {
    			url  = 'http://vkontakte.ru/share.php?';
    			url += 'url='          + encodeURIComponent(this.url);
    			url += '&title='       + encodeURIComponent(this.text);
    			url += '&description=' + encodeURIComponent(share);
    			url += '&image='       + encodeURIComponent(pic);
    			url += '&noparse=true';
    		} else if(social_network == 'ok') {
    			url  = 'http://www.odnoklassniki.ru/dk?st.cmd=addShare&st.s=1';
    			url += '&st.comments=' + encodeURIComponent(share);
    			url += '&st._surl='    + encodeURIComponent(this.url);
    		} else if(social_network == 'ml') {
    			url  = 'http://connect.mail.ru/share?';
    			url += 'url='          + encodeURIComponent(this.url);
    			url += '&title='       + encodeURIComponent(this.text);
    			url += '&description=' + encodeURIComponent(share);
    			url += '&imageurl='    + encodeURIComponent(pic);
    		}
    
    		window.open(url,'','toolbar=0,status=0,width=626,height=436');
    		
    		return this.vote_ns()
    	},
    	
    	// Vote count
    	vote_ns: function() {
    		new Request({
    			url: '/vote/' + this.id + '/' + this.selected
    		}).send();
    
    		this.popup.close();
    		this.onPopupClose.delay(400);
    
    		var vote_count = $('vote-num-'+this.selected);
    		vote_count.set('text', vote_count.get('text').toInt() + 1);
    
    		$('vote-1').destroy();
    		$('vote-2').destroy();
    		$('voted_thank_you').show();
    
    		return false
    	},
    	
    	// Askbook Promo
    	promoAskbook: function() {
    		this.promoBox = new LightFace.Static({
    			width:     500,
    			draggable: true,
    			title:     'AskBook.me',
    			content:   'askbook_promo'
    		});
    	}
    
    });

    Класс битв на 1001golos.ru

    eriko, 26 Января 2012

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

    +135

    1. 01
    2. 02
    3. 03
    4. 04
    5. 05
    6. 06
    7. 07
    8. 08
    9. 09
    10. 10
    class Program
    {
        static void Main(String[] args)
        {
            for (int i = 0; i < 10; i++)
            {
                Main();
            }
        }
    }

    Студент выдал такое в ответ на задание написать код, вызывающий функцию 10 раз. Пол часа бедняга втыкал откуда стэк оверфлоу...

    vistefan, 26 Января 2012

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

    +158

    1. 1
    2. 2
    3. 3
    4. 4
    if(strlen(trim($row['article']))!=0)
    {
     // Some action
    }

    empty? не, это из будущего.
    Суки! Сколько можно это писать!

    Zerstoren, 26 Января 2012

    Комментарии (16)
  4. Pascal / Говнокод #9229

    +95

    1. 1
    2. 2
    3. 3
    4. 4
    5. 5
    procedure TEditor.cbReverseClick(Sender: TObject);
    begin
      T.Reversed := not T.Reversed;
      Show;
    end;

    Вместо
    T.Reversed := cbReverse.Checked;
    Интересно, может ли это создать баг?

    TarasB, 26 Января 2012

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

    +175

    1. 1
    2. 2
    while ($new_width>$maxwidth) { $new_width *= 0.99; $new_height *= 0.99; }	
    	  while ($new_height>$maxheight) { $new_width *= 0.99; $new_height *= 0.99; }

    Мега код из сайта написанного на InstantCMS
    Вот так там уменьшаются картинки под максимальный размер...

    3xdimon, 26 Января 2012

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

    +156

    1. 1
    2. 2
    3. 3
    4. 4
    5. 5
    6. 6
    7. 7
    function makeFriendlyURL($pre, $suff, $alias) {
            $Alias = explode('/',$alias);
            $alias = array_pop($Alias);
            $dir = implode('/', $Alias);
            unset($Alias);
            return ($dir != '' ? "$dir/" : '') . $pre . $alias . $suff;
    }

    Член класса DocumentParser в CMF MODX.

    MaXL, 26 Января 2012

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

    +151

    1. 1
    2. 2
    3. 3
    4. 4
    $username1=$_COOKIE['username'];
    $password1=$_COOKIE['password'];
    $username1 = mysql_real_escape_string(stripslashes($_COOKIE['username']));
    $password1 = mysql_real_escape_string(stripslashes($_COOKIE['password']));

    cthulhu25, 25 Января 2012

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

    +169

    1. 1
    2. 2
    3. 3
    4. 4
    final static public function route($home)
    	{
    		require_once "$home/pages/" . $_GET['q'] . ".php";
    	}

    Роутер и неепет.

    Razban_Guestov, 25 Января 2012

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

    −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
    NetworkStatus netStatus = [curReach currentReachabilityStatus];
    switch (netStatus)
    	{
    		case NotReachable:
    		{
    			lastNetworkStatus = @"NotReachable";
    			
    		}
    	}
    		
    	if ([lastNetworkStatus isEqualToString:@"NotReachable"]) {
                                    .  .  . 
            }

    Переменная lastNetworkStatus больше нигде не используется и объявлена глобальной. Приложение есть на сторе http://itunes.apple.com/us/app/25-things-to-do-in-amsterdam/id452987778?mt=8
    Дали на доработку =)

    Lumyk, 25 Января 2012

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

    +148

    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
    #include <iostream.h>
    
    typedef short *(*bar2)(double);
    
    typedef char *(*bar3)();
    
    typedef long long int **(* bar5)();
    
    typedef bar5 (** bar4)(bar3);
    typedef bar4 (** bar1)(bar2);
    
    
    typedef long long int *(*(*(*(*(**bar0)(short *(*)(double ))))(char *(*)()))());
    
    
    long long int ** func5()
    {
    	static long long int  A = 42;
    	static long long int* B = &A;
    	return &B;
    }
    
    char* func3()
    {
    	return new char;
    }
    
    bar5 func4(bar3 A)
    {
    	return &func5;
    }
    
    short* fun2(double A)
    {
    	return new short;
    };
    
    bar4 fun1(bar2 A){
    	static void* p = &func4;
    	return (bar4)&p;
    }
    
    #pragma argsused
    int main(int argc, char* argv[])
    {
    	void* p = &fun1;
    
    	bar0 foo0 = (bar1)&p;
    	bar1 foo1 = (bar1)&p;
    
    	long long int ** pr1 = (*(*(*foo1)(&fun2))(&func3))();
    	long long int ** pr0 = (*(*(*foo0)(&fun2))(&func3))();
    
    	std::cout<<**pr1<<std::endl;
    	std::cout<<**pr0<<std::endl;
    	std::cin.get();
    
    	return 0;
    }

    разбирался с указателями на функции

    sanchousf, 25 Января 2012

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