1. PHP / Говнокод #15479

    +152

    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
    // Калькулятор умеющий умножать, делить, складывать и вычитать.
    
    
    <?php
    
    if ($_SERVER['REQUEST_METHOD'] == 'POST') {
    	if (isset($_POST['num1'])) { 
    		if(is_numeric($_POST['num1'])) {
    			$num1 = strip_tags($_POST['num1']*1); 
    			}
    		} 
    		elseif (isset($_POST['num1'])) {
    			echo "Неверное значение Число 1";
    		}
    	if (isset($_POST['num2'])) { 
    		if(is_numeric($_POST['num2'])) {
    			$num2 = strip_tags($_POST['num2']*1); 
    			}
    		} 
    		elseif (isset($_POST['num2'])) {
    			echo "Неверное значение Число 2";
    		}
    	if (isset($_POST['operator'])) { 
    			$operator = $_POST['operator']; 
    		} 
    		elseif (isset($_POST['operator'])) {
    			echo "Неверное значение Оператор";
    		}
    		
    
    		switch ($operator) {
    		case '-':
    		$output .= $num1-$num2;break;
    		case '+':
    		$output .= $num1+$num2;break;
    		case '*':
    		$output .= $num1*$num2;break;
    		case '/':
    			if ($num2 == 0) {echo "На 0 делить нельзя";}else{$output .= $num1/$num2;break;}
    			default:
    				$output = "Неизвестный оператор ".$operator;
    	}
    }
    	
    ?>
    <h1>Калькулятор</h1>
    
    <?php
    
    if (isset($output)){
    	echo "Результат $output";
    }
    	
    ?>
    
    <form action="<?php echo $_SERVER['REQUEST_URI']; ?>" method="post">
    
    Число 1:<br />
    <input type="text" name="num1" /><br /><br />
    
    Оператор:<br />
    <input type="text" name="operator" /><br /><br />
    
    Число 2:<br />
    <input type="text" name="num2" /><br /><br />
    
    <input type="submit" value="Считать!" />
    
    </form>

    // Калькулятор умеющий умножать, делить, складывать и вычитать.

    Arthur, 14 Марта 2014

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

    +15

    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
    #include <iostream>
    #include <string>
    #include <vector>
    #include <list>
    #include <algorithm>
    #include <iterator>
    #include <sstream>
    #include <assert.h>
    using namespace std;
    template<class Container, class Iterator> 
    size_t position(Container&& c, Iterator pos){
        return size_t(distance(begin(c), pos));
    }
    template<class Container, class Iterator, class Iterator2> 
    string sposition(Container&& c, const pair<Iterator, Iterator2>& pos){
        ostringstream r;
        r << "(" << position(c, pos.first) << ", " << position(c, pos.second) << ")";
        return r.str();
    }
    template<class Container, class Value> 
    pair<typename remove_reference<Container>::type::iterator, typename remove_reference<Container>::type::iterator>
     binary_search(Container&& source, const Value& item){
        assert(is_sorted(begin(source), end(source)));
        const auto empty = make_pair(source.end(), source.end());
        auto l = begin(source), r=end(source), m=l;
        while(true){
            if(l==r)
                return empty;
            const auto lr = distance(l,r);
            m = next(l, lr/2);
            if(*m<item)
                l = m;
            if(*m>item)
                r = m;
            if(*m==item)
                break;
            if(l!=r && next(l)==r)
                return empty;
        }
        cout<<"part1"<<endl;
        auto l1=l, r1=m, l2=m, r2=r;
        while(true){
            const auto lr1 = distance(l1, r1);
            m = next(l1, lr1/2);
            if(*m<item)
                l1 = m;
            if(*m>=item)
                r1 = m;
            if(l1==r1 || (*l1<item && *r1>=item))
                break;
        }
        cout<<"part2"<<endl;
        while(true){
            const auto lr2 = distance(l2, r2);
            m = next(l2, lr2/2);
            if(*m<=item)
                l2 = m;
            if(*m>item)
                r2 = m;
            if(l2==r2 || (*l2>=item && (r==r2 || *r2>item)))
                break;
        }
        cout<<"part3"<<endl;
        return {r1, next(l2)};
    }
    int main(){
        vector<int> s{5,7,7,7,9,19,23};
        list<int> s2(s.begin()+1, s.end());
        cout<<sposition(s, binary_search(s, 7))<<endl;
        cout<<sposition(s2, binary_search(s2, 7))<<endl;
        cout<<sposition(s, binary_search(s, 9))<<endl;
        cout<<sposition(s, binary_search(s, 5))<<endl;
        cout<<sposition(s, binary_search(s, 23))<<endl;
        cout<<sposition(s, binary_search(s, 0))<<endl;
        vector<int> e;
        cout<<sposition(e, binary_search(e, 0))<<endl;
        cout<<sposition(s, binary_search(s, 25))<<endl;
        cout<<sposition(s, binary_search(s, 10))<<endl;
        return 0;
    }

    http://coliru.stacked-crooked.com/a/0f74a4661c06cd68
    Специально для @Пи, раз ему хачкель не нравится.

    LispGovno, 14 Марта 2014

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

    +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
    class Key{
    	private $chars = array('1'=>'a','2'=>'b','3'=>'c','4'=>'d','5'=>'e','6'=>'f','7'=>'g','8'=>'h','9'=>'i');
    	private $invChars = array('9'=>'a','8'=>'b','7'=>'c','6'=>'d','5'=>'e','4'=>'f','3'=>'g','2'=>'h','1'=>'i');
    	private $key = "";
    	private $numbers = array();
    
    	public function createKey(){
    		for($a=0;$a<4;$a++){
    			$this->numbers[0] = rand(1, 9);
    			$this->numbers[1] = rand(1, 9);
    			$this->key .= $this->numbers[0].$this->invChars[$this->numbers[1]].$this->numbers[1].$this->chars[$this->numbers[0]]."-";
    		}
    		return substr_replace($this->key, '', 19, 1);
    	}
    
    	public function checkKey($key){
    		if(preg_match("/^([1-9][a-iA-I][1-9][a-iA-I][\-][1-9][a-iA-I][1-9][a-iA-I][\-][1-9][a-iA-I][1-9][a-iA-I][\-][1-9][a-iA-I][1-9][a-iA-I])$/", $key)){
    			$key = str_replace('-', '', $key);
    			if($this->chars[$key[0]] == $key[3] && $this->invChars[$key[2]] == $key[1]){
    				if($this->chars[$key[4]] == $key[7] && $this->invChars[$key[6]] == $key[5]){
    					if($this->chars[$key[8]] == $key[11] && $this->invChars[$key[10]] == $key[9]){
    						if($this->chars[$key[12]] == $key[15] && $this->invChars[$key[14]] == $key[13]){
    							return true;
    						}
    						else{
    							return false;
    						}
    					}
    					else{
    						return false;
    					}
    				}
    				else{
    					return false;
    				}
    			}
    			else{
    				return false;
    			}
    		}
    		else{
    			return false;
    		}
    	}
    }

    Особенно регулярка...

    makssof, 14 Марта 2014

    Комментарии (2)
  4. Куча / Говнокод #15474

    +126

    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
    import Data.Array
    import Control.Arrow
    l = [1,5,5,5,8,10,17]
    make_array [] = undefined
    make_array l = listArray (0, (length l)-1) l
    -- binary_search:: (Integral i, Num i, Ord e, Ix i) => e -> Array i e -> i
    binary_search item arr = bs la ra where
    	(la, ra) = bounds arr
    	nextWhileEqualItem = uncurry iterate >>> takeWhile (\i -> la<=i && i<=ra && arr!i==item) >>> last
    	bs l r
    		| (m == l || m == r) && item/=av = Nothing
    		| item<av = bs l m
    		| item>av = bs m r
    		| item==av = Just (nextWhileEqualItem ((+) (-1), m), nextWhileEqualItem ((+)1, m))
    		| otherwise = Nothing
    		where
    			m = (l+r) `div` 2
    			av = arr!m
    main = do
    	print $ binary_search 8 $ make_array l
    	print $ binary_search 5 $ make_array l
    	print $ binary_search 5 $ make_array $ tail l
    	print $ binary_search 0 $ make_array l
    	print $ binary_search 100 $ make_array l
    	print $ binary_search 9 $ make_array l

    Решил я значит поучаствовать в специальной олимпиаде Романа с двача.
    http://ideone.com/K5Jj59

    LispGovno, 14 Марта 2014

    Комментарии (21)
  5. Куча / Говнокод #15472

    +122

    1. 1
    2. 2
    substractOneFromArgument = (-)1
    main = print $ substractOneFromArgument 4

    ПИШУ ФУНКЦИЮ ВЫЧИТАЮЩУЮ ЕДИНИЦУ ИЗ СВОЕГО АРГУМЕНТА
    @
    ПОЛУЧАЮ УПОРОТЫЙ РЕЗУЛЬТАТ
    http://ideone.com/I34iLA

    LispGovno, 14 Марта 2014

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

    +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
    try {
        if ($model->save(true, null, true)) {
            if ($model->bonusActive) {
                self::assignBonus($model->customerID, $bonus['bonusID']);
            }
            if ($noAuth)
                return $model->customerID;
    
            Yii::app()->params['id'] = $model->customerID;
            return true;
        }
        else
            return false;
    } catch (CDbException $e) {
        throw $e;
    }

    Я даже не знаю, что сказать.

    wsh, 14 Марта 2014

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

    +157

    1. 1
    2. 2
    3. 3
    4. 4
    5. 5
    6. 6
    7. 7
    if ($_GET['cred_sum']!=""){
      $_GET['cred_sum']=$_GET['cred_sum']-$_GET['cred_sum']-$_GET['cred_sum'];
    }
    // simple hack
    else {
    	$_GET['cred_sum'] = -1;
    }

    Делаем cred_sum отрицательным

    painter, 13 Марта 2014

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

    +156

    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
    // MiniNews
       if($(".news_sl-column.gallery").size()) {
            $(".minigal-nav .counter").text("1 из " + $(".news_sl-column.gallery").find("li").size());
    
            $(".minigal-nav li.next").on("click", function() {
                var index = $(".news_sl-column.gallery li.current").index();
                index++;
    
                if(index > $(".news_sl-column.gallery").find("li").size() - 1) {
                    index = 0;
                }
    
                switchImage(index);
            });
            if (window.isWindowsPhone){
            	$(".news_sl-column.gallery img").attr("onclick", '$(".minigal-nav li.next").trigger("click");');
            } else {
            	$(".news_sl-column.gallery img").on("click", function() {
            	    $(".minigal-nav li.next").trigger("click");
            	});
            }
    
            if (window.isWindowsPhone){
            	$(".minigal-nav li.prev").attr("onclick", 'var index = $(".news_sl-column.gallery li.current").index(); index--; if(index < 0) { index = $(".news_sl-column.gallery").find("li").size() - 1;} switchImage(index);');
            } else {
            	$(".minigal-nav li.prev").on("click", function() {
            	    var index = $(".news_sl-column.gallery li.current").index();
            	    index--;
            	    if(index < 0) {
            	        index = $(".news_sl-column.gallery").find("li").size() - 1;
            	    }
            	    switchImage(index);
            	});
            }
    
            var switchImage = function(index) {
                $(".news_sl-column.gallery li.current").fadeOut(function() {
                    $(this).removeClass("current");
                    $(".news_sl-column.gallery").find("li").eq(index).fadeIn().addClass("current");
                });
    
                $(".minigal-texts li.current").fadeOut(function() {
                    $(this).removeClass("current");
                    $(".minigal-texts").find("li").eq(index).fadeIn().addClass("current");
                });
    
                $(".minigal-nav .counter").text(index + 1 + " из " + $(".news_sl-column.gallery").find("li").size());
            }
        }
        // endof MiniNews

    Это проект меня убивает....

    farit_slv, 13 Марта 2014

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

    +159

    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
    window.checkPluginVersion = function(id, version) {
        if (!(plugin(id) && plugin(id).valid)) return false;
        var plugin_version = plugin(id).version.split('.');
        var portal_version = version.split('.');
        if (isNaN(parseInt(plugin_version[0]))) return false;
        if (isNaN(parseInt(plugin_version[1]))) return false;
        if (isNaN(parseInt(plugin_version[2]))) return false;
        if (isNaN(parseInt(portal_version[0]))) return false;
        if (isNaN(parseInt(portal_version[1]))) return false;
        if (isNaN(parseInt(portal_version[2]))) return false;
        if (parseInt(plugin_version[0]) > parseInt(portal_version[0])) return true;
        if (parseInt(plugin_version[0]) < parseInt(portal_version[0])) return false;
        if (parseInt(plugin_version[1]) > parseInt(portal_version[1])) return true;
        if (parseInt(plugin_version[1]) < parseInt(portal_version[1])) return false;
        if (parseInt(plugin_version[2]) > parseInt(portal_version[2])) return true;
        if (parseInt(plugin_version[2]) < parseInt(portal_version[2])) return false;
        return true;
    }

    Код с Госуслуг. Nuff said

    dmgl, 13 Марта 2014

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

    +133

    1. 1
    access denied for the user "King1986" with password "weakCocc".

    Часть строки из лога. Логи пока общедоступны.

    laMer007, 13 Марта 2014

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