1. C# / Говнокод #16534

    +134

    1. 01
    2. 02
    3. 03
    4. 04
    5. 05
    6. 06
    7. 07
    8. 08
    9. 09
    10. 10
    for (var i = 0; i < numberPhone.Length; i++)
                    {
                        if (numberPhone[i] == ',')
                            return resultPhone;
                        if (Char.IsNumber(numberPhone[i]))
                        {
                            resultPhone += numberPhone[i];
                        }
                    }
                    return resultPhone;

    vladb9582, 14 Августа 2014

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

    +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
    private function generate_accomodations_array($adults, $children, $ages) {
        $result = array();
        foreach($adults as $adult) {
          foreach($children as $child) {
            $param = array();
            if($child > 0) {
              for($age1=0; $age1<count($ages); $age1++) {
                if($child > 1) {
                  for($age2=$age1; $age2<count($ages); $age2++) {
                    $param = array($ages[$age1], $ages[$age2]);
                    $result[] = $this->generate_accomodations_row($adult, $child, $param);
                  }
                } else {
                  $param = array($ages[$age1]);
                  $result[] = $this->generate_accomodations_row($adult, $child, $param);
                }
              }
            } else {
              $result[] = $this->generate_accomodations_row($adult, $child, $param);
            }
          }
        }
        return $result;
      }
    
      private function generate_accomodations_row($adult = null, $child = null, $ages = null) {
        $result = array();
        if(!is_null($adult)) {
          $res_adult = array('adult' => $adult);
          $result = array_merge($result, $res_adult);
        }
        if(!is_null($child)) {
          $res_child = array('child' => $child);
          $result = array_merge($result, $res_child);
        }
        if(!is_null($ages)) {
          $res_ages = array();
          $i = 1;
          foreach($ages as $age) {
            $res_ages = array_merge(array('child-age'.$i++ => $age), $res_ages);
          }
          $result = array_merge($result, $res_ages);
        }
        if(!is_null($adult)) {
          for($i=0;$i<$adult;$i++) {
            $result['pegas_ages'][] = $this->adult_age;
          }
        }
        if(!is_null($ages)) {
          $result['pegas_ages'] = array_merge($result['pegas_ages'], $ages);
        }
        return $result;
      }

    govnocodegenerator, 14 Августа 2014

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

    −88

    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
    class DataModel(dict):
        _SCHEME_VERSION = 0
        _transform = dict()
        _additional = dict()
        _migration = None
    
        def __init__(self, data=None, network=None, conf=None):
            if network and conf:
                _scheme = map(lambda x: x.strip(), conf.get(network).keys())
                _map =  map(lambda x: x.strip(), conf.get(network).values())
    
                self._scheme = int(conf._scheme)
    
                map(lambda x: setattr(self, x[0], data.get(x[1], None)),
                    [(_scheme[i], _map[i]) for i in xrange(0,len(_map))])
    
                if self._transform.get(network, False):
                    map(lambda x: setattr(self, x, getattr(self._transform[network], x)(getattr(self, x))),
                        [k for k in self._transform[network].__dict__.keys() if not k.startswith('__')])
            else:
                dict.__init__(self, data)
    
            if self.get('_scheme', 0)<self._SCHEME_VERSION and self._migration is not None:
                k = [int(k.split('_')[1]) for k in self._migration.__dict__.keys() if not k.startswith('__')]
                k.sort()
                [k.remove(x) for x in k if x<=self.get('_scheme', 0)]
                map(lambda x: getattr(self._migration, 'scheme_%s' % x)(self), k)
                self._scheme = self._SCHEME_VERSION
    
            map(lambda x: setattr(self, x, getattr(self._additional, x)(self)),
                [k for k in self._additional.__dict__.keys() if not k.startswith('__')])
    
        def __setattr__(self, name, val):
            if name in self.__dict__:
                self.__dict__[name]= val
            else:
                self[name] = val
    
        def __getattr__(self, name):
            if name in self.__dict__:
                return self.__dict__[name]
            else:
                return self[name]

    Mongo migration, written in Python, for human beings.

    vaxxxa, 14 Августа 2014

    Комментарии (1)
  4. PHP / Говнокод #16527

    +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
    19. 19
    20. 20
    21. 21
    22. 22
    23. 23
    24. 24
    25. 25
    26. 26
    27. 27
    foreach ($val as $k => $v)
    		{
    			if (!is_array($v))
    			{
    				$val[$k] = htmlspecialcharsbx($v);
    			}
    			else
    			{
    				foreach ($v as $kp => $vp)
    				{
    					foreach ($vp as $kkp => $vvp)
    					{
    						if (!is_array($vvp))
    						{
    							$val[$k][$kp][$kkp] = htmlspecialcharsbx($vvp);
    						}
    						else
    						{
    							foreach ($vvp as $kvvp => $vvvp)
    							{
    								$val[$k][$kp][$kkp][$kvvp] = htmlspecialcharsbx($vvvp);
    							}
    						}
    					}
    				}
    			}
    		}

    clauclauclau, 14 Августа 2014

    Комментарии (108)
  5. 1C / Говнокод #16526

    −163

    1. 1
    2. 2
    3. 3
    4. 4
    Если ЗначениеЗаполнено(Сделка) И ЛЕВ(Сделка.Ссылка, 10) = "Заказ пост" Тогда
             //другой говнокод
    
    КонецЕсли;

    Правильная проверка типов

    alexinzaz, 14 Августа 2014

    Комментарии (40)
  6. JavaScript / Говнокод #16524

    +149

    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
    (function(G, U) {
        "use strict";
        var $ = G.jQuery,
            string = "string",
            number = "number",
            bool   = "boolean",
            object = "object";
    
        function hasStr(obj, prop) {
            return obj.hasOwnProperty(prop) && typeof obj[prop] === string;
        }
    
        function hasNum(obj, prop) {
            return obj.hasOwnProperty(prop) && typeof obj[prop] === number;
        }
    
        function hasArr(obj, prop) {
            return obj.hasOwnProperty(prop) && $.isArray(obj[prop]);
        }
    
        function hasFn(obj, prop) {
            return obj.hasOwnProperty(prop) && $.isFunction(obj[prop]);
        }
    
        function hasBool(obj, prop) {
            return obj.hasOwnProperty(prop) && typeof obj[prop] === bool;
        }
    
        function copyProps(source, target, fields) {
            var i,
                count,
                fieldType,
                fieldTypes = {
                    str : hasStr,
                    bool: hasBool,
                    arr : hasArr,
                    fn  : hasFn,
                    num : hasNum
                };
                
            if (arguments.length < 2){
                return;
            }
            
            if (arguments.length === 2){
                target = {};
            }
    
            if ($.isPlainObject(source) && $.isPlainObject(target) && $.isPlainObject(fields)) {
                for (fieldType in fieldTypes) {
                    if (fieldTypes.hasOwnProperty(fieldType)) {
                        if (hasArr(fields, fieldType)) {
                            for (i = 0, count = fields[fieldType].length; i < count; i += 1) {
                                if (fieldTypes[fieldType](source, fields[fieldType][i])) {
                                    target[fields[fieldType][i]] = source[fields[fieldType][i]];
                                }
                            }
                        }
                    }
                }
            }
            return target;
        }
    
        G.copyProps = copyProps; //Export into global namespace
    }(this, undefined));

    Здравствуйте! Написал функцию, которая безопасно копирует свойства из одного объекта в другой, выполняя проверку типа каждого копируемого поля. Скажите, какие недостатки и насколько оправдано её применение по сравнению со стандартной функцией jQuery extend()? Работает только с простыми объектами, для вложенных объектов нужно ещё раз вызывать эту функцию.

    dunmaksim, 14 Августа 2014

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

    +133

    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
    var status = true;
                    var name = aspnet_UsersRepository.FindAll().FirstOrDefault(u => u.aspnet_Membership.Email.Equals(model.Email, StringComparison.InvariantCultureIgnoreCase));
                    if (name != null) { return View("Error_user"); }
    
                    /*13.08.2014 EmirMamashovCode{} нахождение сущ. ли такой агент*/
                    var usersBalanses = UserBalancesRepository.FindAll().ToList();
                   /* если заполнено код агента и имя агента */
                    if (model.KodAgent != null && model.NameAgent != null)
                    {
                        foreach (var usersBalanse in usersBalanses)
                        {
                            if (model.KodAgent == usersBalanse.KodforPay)
                            {
                                status = true;
                            }
                            else{status = false;}
                        }
                        if (status == false)
                        {
                            return View("Error_notFoundAgent");
                        }
                       
                    }

    нахождение сущ. ли такой агент

    Emir, 13 Августа 2014

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

    +57

    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
    bool Processor::check_holes(int x, int y){
        int scale = 1000000;
        if((x > (die_size-mem_size)/2*scale && x < (die_size-mem_size)*scale) && (y > (die_size-mem_size)/2*scale && y < (die_size-mem_size)*scale)){
            return false;
        }
        if((x > (die_size-mem_size)*scale) && (y > (die_size-mem_size)/2*scale && y < (die_size-mem_size)*scale)){
            if(((int)(x - (die_size-mem_size)*scale) % 400) > 340 && ((int)(y - (die_size-mem_size)/2*scale) % 400) > 340){
                if((x - (die_size-mem_size)*scale) < 2400){
                    return true;
                }
            }
        }
        if((x < (die_size-mem_size)/2*scale) && (y > (die_size-mem_size)/2*scale && y < (die_size-mem_size)*scale)){
            if(((int)((die_size-mem_size)/2*scale - x) % 400) > 340 && ((int)(y - (die_size-mem_size)/2*scale) % 400) > 340){
                if(((die_size-mem_size)/2*scale - x) < 2400){
                    return true;
                }
            }
        }
        if((y > (die_size-mem_size)*scale) && (x > (die_size-mem_size)/2*scale && x < (die_size-mem_size)*scale)){
            if(((int)(y - (die_size-mem_size)*scale) % 400) > 340 && ((int)(x - (die_size-mem_size)/2*scale) % 400) > 340){
                if((y - (die_size-mem_size)*scale) < 2400){
                    return true;
                }   
            }
        }
        if((y < (die_size-mem_size)/2*scale) && (x > (die_size-mem_size)/2*scale && x < (die_size-mem_size)*scale)){
            if(((int)((die_size-mem_size)/2*scale - y) % 400) > 340 && ((int)(x - (die_size-mem_size)/2*scale) % 400) > 340){
                if(((die_size-mem_size)/2*scale - y) < 2400){
                    return true;
                }
            }
        }
        return false;
    }

    Проверяем дырки

    Abbath, 13 Августа 2014

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

    +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
    if (isset($_POST['find'])) { $find = $_POST['find']; if ($find == '') { unset($find);} } 
    require 'bd.php';
    if (isset($find)){$parametr=$find;} else {$parametr='main';}
    $res = mysql_query("SHOW TABLES");
    if ($parametr != 'main'){
    while ($row = mysql_fetch_row($res)) {if($parametr==$row[0]){$check=1;} }}
    if($check != 1){$parametr='main';} 
    $sql_select = "SELECT * FROM `$parametr`; 
    $result = mysql_query($sql_select);
    $row = mysql_fetch_array($result);
    $query='SELECT MAX(id) FROM `$parametr`';
    $query=mysql_fetch_row(mysql_query($query));
    $max_id=$query[0];
    $i = 1;
    $icorrect = $max_id;
    while ($i <= 18) {
    $query='SELECT * FROM `$parametr` WHERE id='.$icorrect.'';
    $result=mysql_fetch_array(mysql_query($query));
    $i++;
    echo $result['name'],' <b>said</b>: ',$result['text'];
    echo '<br />';
    $icorrect = $icorrect - 1;

    Бухой быдлокодер пытается написать удобный чат на php с полным функционалом в одной странице

    kooomle, 13 Августа 2014

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

    +62

    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
    Grid Processor::build_grid()
    {
        Grid res;
        double top = 340+60;
        double left = 0, right = 60;
        Point a,b,c,d;
        for(int i = 0; i < 6; ++i){
            for(int j = 0; j < 13; ++j){
                a = {left*1e-6, top*1e-6, 2.1e-3};
                b = {right*1e-6, top*1e-6, 2.1e-3};
                c = {(left-3.25)*1e-6, (top+3.25)*1e-6, 2e-3};
                d = {(right+3.25)*1e-6, (top+3.25)*1e-6, 2e-3};  
                auto t = std::make_tuple(a,b,c,d);
                res.push_back(t);
                left += (340+60);
                right += (340+60);
            }
            top += (340+60);
            left = 0;
            right = 60;
        }
        
        top = (int)(-mem_size*1e6)+60;
        left = (int)(mem_size*1e6)+340;
        right = (int)(mem_size*1e6)+400;
        for(int i = 0; i < 13; ++i){
            for(int j = 0; j < 6; ++j){
                a = {left*1e-6, top*1e-6, 2.1e-3};
                b = {right*1e-6, top*1e-6, 2.1e-3};
                c = {(left-3.25)*1e-6, (top+3.25)*1e-6, 2e-3};
                d = {(right+3.25)*1e-6, (top+3.25)*1e-6, 2e-3};  
                auto t = std::make_tuple(a,b,c,d);
                res.push_back(t);
                left += (340+60);
                right += (340+60);
            }
            top += (340+60);
            left = (int)(mem_size*1e6)+340;
            right = (int)(mem_size*1e6)+(340+60);
        }
        
        top = (int)(-(mem_size+2.4e-3)*1e6)+60;
        left = 0, right = 60;
        for(int i = 0; i < 6; ++i){
            for(int j = 0; j < 13; ++j){
                a = {left*1e-6, top*1e-6, 2.1e-3};
                b = {right*1e-6, top*1e-6, 2.1e-3};
                c = {(left-3.25)*1e-6, (top+3.25)*1e-6, 2e-3};
                d = {(right+3.25)*1e-6, (top+3.25)*1e-6, 2e-3};  
                auto t = std::make_tuple(a,b,c,d);
                res.push_back(t);
                left += (340+60);
                right += (340+60);
            }
            top += (340+60);
            left = 0;
            right = 60;
        }
        
        top = (int)(-mem_size*1e6)+60;
        left = -2400;
        right = -2400+60;
        for(int i = 0; i < 13; ++i){
            for(int j = 0; j < 6; ++j){
                a = {left*1e-6, top*1e-6, 2.1e-3};
                b = {right*1e-6, top*1e-6, 2.1e-3};
                c = {(left-3.25)*1e-6, (top+3.25)*1e-6, 2e-3};
                d = {(right+3.25)*1e-6, (top+3.25)*1e-6, 2e-3};  
                auto t = std::make_tuple(a,b,c,d);
                res.push_back(t);
                left += (340+60);
                right += (340+60);
            }
            top += (340+60);
            left = -2400;
            right = -2400+60;
        }
        
        return res;
    }

    Magic numbers, Voodoo numbers!

    Abbath, 12 Августа 2014

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