1. Java / Говнокод #15484

    +72

    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
    public boolean fastItemEquals(ItemStack st, ItemStack nd) {
            if(st.hashCode() == nd.hashCode()) return true;
            if(st.getType() != nd.getType()) return false;
            if(!st.getItemMeta().getDisplayName().equals(nd.getItemMeta().getDisplayName())) return false;
            if(st.getEnchantments().size() != nd.getEnchantments().size()) return false;
            if(st.getItemMeta().getLore().size() != nd.getItemMeta().getLore().size()) return false;
            final List<String> 
                    lst = st.getItemMeta().getLore(),
                    lnd = nd.getItemMeta().getLore();
            for(int i = 0 ; i < st.getItemMeta().getLore().size() ; i++)
                if(!lst.get(i).equals(lnd.get(i))) return false;
            
            //return st.isSimilar(nd);
            return true;
        }
        
        /* оригинал
        @Override
        public boolean isSimilar(ItemStack stack) {
            if (stack == null) {
                return false;
            }
            if (stack == this) {
                return true;
            }
            if (!(stack instanceof CraftItemStack)) {
                return stack.getClass() == ItemStack.class && stack.isSimilar(this);
            }
    
            CraftItemStack that = (CraftItemStack) stack;
            if (handle == that.handle) {
                return true;
            }
            if (handle == null || that.handle == null) {
                return false;
            }
            if (!(that.getTypeId() == getTypeId() && getDurability() == that.getDurability())) {
                return false;
            }
            return hasItemMeta() ? that.hasItemMeta() && handle.tag.equals(that.handle.tag) : !that.hasItemMeta();
        }
        */

    DiaLight, 15 Марта 2014

    Комментарии (0)
  2. Java / Говнокод #15483

    +68

    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
    public boolean fastItemEquals(ItemStack st, ItemStack nd) {
            if(st.hashCode() == nd.hashCode()) return true;
            if(st.getType() != nd.getType()) return false;
            if(!st.getItemMeta().getDisplayName().equals(nd.getItemMeta().getDisplayName())) return false;
            if(st.getEnchantments().size() != nd.getEnchantments().size()) return false;
            if(st.getItemMeta().getLore().size() != nd.getItemMeta().getLore().size()) return false;
            List<String> 
                    lst = st.getItemMeta().getLore(),
                    lnd = nd.getItemMeta().getLore();
            for(int i = 0 ; i < st.getItemMeta().getLore().size() ; i++)
                if(!lst.get(i).equals(lst.get(i))) return false;
            
            //return st.isSimilar(nd);
            return true;
        }
        
        /* оригинал
        @Override
        public boolean isSimilar(ItemStack stack) {
            if (stack == null) {
                return false;
            }
            if (stack == this) {
                return true;
            }
            if (!(stack instanceof CraftItemStack)) {
                return stack.getClass() == ItemStack.class && stack.isSimilar(this);
            }
    
            CraftItemStack that = (CraftItemStack) stack;
            if (handle == that.handle) {
                return true;
            }
            if (handle == null || that.handle == null) {
                return false;
            }
            if (!(that.getTypeId() == getTypeId() && getDurability() == that.getDurability())) {
                return false;
            }
            return hasItemMeta() ? that.hasItemMeta() && handle.tag.equals(that.handle.tag) : !that.hasItemMeta();
        }
        */

    DiaLight, 15 Марта 2014

    Комментарии (0)
  3. Java / Говнокод #15482

    +70

    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
    public boolean fastItemEquals(ItemStack st, ItemStack nd) {
            if(st.hashCode() != nd.hashCode()) return false;
            if(st.getType() != nd.getType()) return false;
            if(!st.getItemMeta().getDisplayName().equals(nd.getItemMeta().getDisplayName())) return false;
            if(st.getEnchantments().size() != nd.getEnchantments().size()) return false;
            //return st.isSimilar(nd);
            return true;
        }
        
        /* оригинал
        @Override
        public boolean isSimilar(ItemStack stack) {
            if (stack == null) {
                return false;
            }
            if (stack == this) {
                return true;
            }
            if (!(stack instanceof CraftItemStack)) {
                return stack.getClass() == ItemStack.class && stack.isSimilar(this);
            }
    
            CraftItemStack that = (CraftItemStack) stack;
            if (handle == that.handle) {
                return true;
            }
            if (handle == null || that.handle == null) {
                return false;
            }
            if (!(that.getTypeId() == getTypeId() && getDurability() == that.getDurability())) {
                return false;
            }
            return hasItemMeta() ? that.hasItemMeta() && handle.tag.equals(that.handle.tag) : !that.hasItemMeta();
        }
        */

    DiaLight, 15 Марта 2014

    Комментарии (0)
  4. 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)
  5. 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)
  6. 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)
  7. Куча / Говнокод #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)
  8. Куча / Говнокод #15472

    +122

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

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

    LispGovno, 14 Марта 2014

    Комментарии (22)
  9. 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)
  10. 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)