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

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

    0

    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
    class Cell:
        def __init__(self, row_id, column_id):
            """Описание ячейки в матрице"""
            """Определение первой буквы в ячейке"""
            if row_id == 0:
                self.cell_letter_1 = 'A'
            elif row_id == 1:
                self.cell_letter_1 = 'K'
            elif row_id == 2:
                self.cell_letter_1 = 'Q'
            elif row_id == 3:
                self.cell_letter_1 = 'J'
            elif row_id == 4:
                self.cell_letter_1 = 'T'
            elif row_id == 5:
                self.cell_letter_1 = '9'
            elif row_id == 6:
                self.cell_letter_1 = '8'
            elif row_id == 7:
                self.cell_letter_1 = '7'
            elif row_id == 8:
                self.cell_letter_1 = '6'
            elif row_id == 9:
                self.cell_letter_1 = '5'
            elif row_id == 10:
                self.cell_letter_1 = '4'
            elif row_id == 11:
                self.cell_letter_1 = '3'
            elif row_id == 12:
                self.cell_letter_1 = '2'
            """Определение второй буквы в ячейке"""
            if column_id == 0:
                self.cell_letter_2 = 'A'
            elif column_id == 1:
                self.cell_letter_2 = 'K'
            elif column_id == 2:
                self.cell_letter_2 = 'Q'
            elif column_id == 3:
                self.cell_letter_2 = 'J'
            elif column_id == 4:
                self.cell_letter_2 = 'T'
            elif column_id == 5:
                self.cell_letter_2 = '9'
            elif column_id == 6:
                self.cell_letter_2 = '8'
            elif column_id == 7:
                self.cell_letter_2 = '7'
            elif column_id == 8:
                self.cell_letter_2 = '6'
            elif column_id == 9:
                self.cell_letter_2 = '5'
            elif column_id == 10:
                self.cell_letter_2 = '4'
            elif column_id == 11:
                self.cell_letter_2 = '3'
            elif column_id == 12:
                self.cell_letter_2 = '2'
            """Установка порядка отойбражения 1-й и 2-й буквы в ячейке"""
            if row_id == 0:
                self.cell_text = self.cell_letter_1 + self.cell_letter_2
            elif row_id == 1 and column_id >= 2:
                self.cell_text = self.cell_letter_1 + self.cell_letter_2
            elif row_id == 2 and column_id >= 3:
                self.cell_text = self.cell_letter_1 + self.cell_letter_2
            elif row_id == 3 and column_id >= 4:
                self.cell_text = self.cell_letter_1 + self.cell_letter_2
            elif row_id == 4 and column_id >= 5:
                self.cell_text = self.cell_letter_1 + self.cell_letter_2
            elif row_id == 5 and column_id >= 6:
                self.cell_text = self.cell_letter_1 + self.cell_letter_2
            elif row_id == 6 and column_id >= 7:
                self.cell_text = self.cell_letter_1 + self.cell_letter_2
            elif row_id == 7 and column_id >= 8:
                self.cell_text = self.cell_letter_1 + self.cell_letter_2
            elif row_id == 8 and column_id >= 9:
                self.cell_text = self.cell_letter_1 + self.cell_letter_2
            elif row_id == 9 and column_id >= 10:
                self.cell_text = self.cell_letter_1 + self.cell_letter_2
            elif row_id == 10 and column_id >= 11:
                self.cell_text = self.cell_letter_1 + self.cell_letter_2
            elif row_id == 11 and column_id == 12:
                self.cell_text = self.cell_letter_1 + self.cell_letter_2
            else:
                self.cell_text = self.cell_letter_2 + self.cell_letter_1

    http://python.su/forum/topic/33195/?page=1#post-181430

    FishHook, 17 Июля 2017

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

    0

    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
    public static int[] GetRandomComStats(int level)
        {
            int[] stats = new int[3] { -1, -1, -1 };
            int summ = (int)(1.2f * level);
            int minStat = level / 3f - (level+ 1) / 10 < 0 ? 0 : (int)(level / 3f - (level + 1) / 10);
            int maxStat = (int)(level / 3f + (level + 1) / 10);
            Debug.Log("level: " + level + " min stat: " + minStat + " max stat: " + maxStat + " summ: " + summ);
            int fr = Random.Range(0, 2);
            int f2 = Random.Range(0, 3);
            int f1 = 0;
            stats[f2] = Random.Range(minStat, maxStat + 1);
            for (int i = 0; i < 3; i++)
            {
                if (fr == 1 && stats[i] == -1)
                {
                    if (summ - stats[f2] > maxStat) stats[i] = Random.Range(minStat,  maxStat + 1);
                    else if (summ - stats[f2] < 0) stats[i] = 0;
                    else stats[i] = Random.Range(minStat, summ - stats[f2] + 1);
                    f1 = i;
                    goto label;
                }
                fr = 1;
    
            }
            label: 
            for (int i = 0; i < 3; i++)
            {
                if (stats[i] == -1)
                {
                    if (summ < stats[f1] + stats[f2]) stats[i] = 0;
                    else if (summ - stats[f1] - stats[f2] > maxStat) stats[i] = maxStat;
                    else stats[i] = summ - stats[f1] - stats[f2];
                    Debug.Log(f1 + ": " + stats[f1]+ " " + f2 + ": " + stats[f2] + " " + i + ": " + stats[i]);
                }
            }
            return stats;
        }

    Генерация рандомных стат персонажей в зависимости от уровня.

    Super_Indus_coding, 07 Июля 2017

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

    +2

    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
    $value = $grandTotal  - $tax;
            $total_name = $this->__('Grandtotal_excl_tax')." (".$this->__('excl. tax').")";
            $row = '<div class="columns xsmall-6 small-6">';
            $row .= $total_name;
            $row .= '</div><div class="columns xsmall-6 small-6 align-right">'.$this->helper('checkout')->formatPrice($value).'</div>';
    
            $totals["grand_total_excl_tax"] = $row;
    
    
            //$orderedTotals = Mage::getStoreConfig('onestepcheckout/general/summary_totals');
            $orderedTotals =  "subtotal,aw_giftcard_duty,aw_giftcard_duty_discount,shipping,cashondelivery,shipping_discount,discount,aw_giftcard,grand_total_excl_tax,tax,grand_total";
            $orderedTotals = explode(',', $orderedTotals);
            foreach($orderedTotals as $total) {
                $total = trim($total);
                if (isset($totals[$total])) {
                    echo $totals[$total];
                }
            }
            ?>
        </div>

    Разгребаем проект на Magento доставшийся в наследство. Умеете ли вы готовить Array() так как готовят его в строках 11-12 ?

    #littleitaly

    mrdink, 06 Июля 2017

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

    0

    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
    # returns yesterday reports
        def get_yesterday_reports(self):
            pass
    
        def get_waterfall_sources(self, wf_id, active_only=False):
            # TODO: check if meta property is equal to the number of items in the array
            # return test.mock_waterfall_sources.get_sources()
            status = '1' if active_only else urllib.quote('0,1')  # '0%2C1&'
            self.get_auth_token()
            encoded = urllib.urlencode({'authorization': self.token})
            url = BASE_URL + "/waterfall-ad-sources?advertiser=&itemsPerPage=9999&name=&page=1&sortAsc=true&sortBy=tier&status={}&tier=&waterfall={}&{}" \
                .format(status, wf_id, encoded)
    
            retries = 1
            while retries <= 3:
                response = requests.get(url)
                if response.status_code == 200:
                    break
                else:
                    logging.error('Failed GET request to StreamRail, status code {}, {} retries'
                                  .format(response.status_code, retries))
                retries += 1
    
            assert response.status_code == 200
            try:
                data = simplejson.loads(response.content)
                waterfall_sources = data['waterfallAdSources']
                assert int(data['meta']['total']) == len(waterfall_sources)
                return waterfall_sources
            except:
                logging.exception("Could not load ad sources for waterfall {} from StreamRail:\n"
                                  "{}".format(wf_id, response.headers))
                raise

    Хотя, с другой стороны, все эти рекламораспространители так выглядят. Но тут просто кучно так получилось.

    wvxvw, 06 Июля 2017

    Комментарии (1)
  6. Python / Говнокод #23145

    +2

    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
    if hasattr(query, "items"):
            query = query.items()
        else:
            # It's a bother at times that strings and string-like objects are
            # sequences.
            try:
                # non-sequence items should not work with len()
                # non-empty strings will fail this
                if len(query) and not isinstance(query[0], tuple):
                    raise TypeError
                # Zero-length sequences of all types will get here and succeed,
                # but that's a minor nit.  Since the original implementation
                # allowed empty dicts that type of behavior probably should be
                # preserved for consistency
            except TypeError:
                ty, va, tb = sys.exc_info()
                raise TypeError("not a valid non-string sequence "
                                "or mapping object").with_traceback(tb)

    https://github.com/python/cpython/blob/master/Lib/urllib/parse.py#L848

    Зачем генерировать TypeError, а потом ее ловить и снова кидать?

    Admina_mamu_ebal, 23 Июня 2017

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

    0

    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
    /* Регистрация */
    	public function register ($log, $pass, $pass2, $email) {
    		/* Стандартная проверка */
    			if(isset($_SESSION['userid'])) return "already_auth";
    			if(!preg_match("/^[a-zA-Z0-9]+$/", $log)) return "rus_or_eng";
    			if(strlen($log) < 5 or strlen($log) > 31) return "log_min_5";
    			if($pass != $pass2) return "pass1_not_equal_pass2";
    			if(strlen($pass) < 8 or strlen($pass) > 31) return "pass_min_8";
    		/* Генерация хэша */
    			$hash = md5('davay'.rand().'ebatsa');
    		/* Проверка на существование ника */
    			$q = $this->db->row("SELECT * FROM `users` WHERE `user` = '".$this->sql($log)."'");
    			if($q != null) return "change_nick";
    		/* Занос в базу данных нового пользователя */
    			$q = $this->db->query("INSERT INTO `users` (`user`, `password`, `hash`) VALUES (:login, :password, :hash)",
    				array("login" => $log, "password" => $pass, "hash" => $hash));
    		/* Возвращаем положительный ответ */
    			return true;
    	}

    Хэш не трогал)

    enly1, 14 Июня 2017

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

    0

    1. 1
    2. 2
    3. 3
    4. 4
    5. 5
    6. 6
    7. 7
    8. 8
    9. 9
    /* Функция загрузки модулей */
    	function load ($name, $path, $cfg = array()) {
    		require($path.'/'.$name.'.php');
    		if($cfg !== null) {
    			return new $name($cfg);
    		} else {
    			return new $name;
    		}
    	}

    Хмм, что-то тут не так.

    enly1, 14 Июня 2017

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

    −1

    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
    protected void ASPxUploadControl1_FilesUploadComplete(object sender, DevExpress.Web.ASPxUploadControl.FilesUploadCompleteEventArgs e)
            {
                if (Request.Cookies["LID"] != null)
                {
                    int ListId = Convert.ToInt32(Request.Cookies["LID"].Value);
                    Response.Cookies["LID"].Expires = DateTime.Now.AddDays(-1);
                    foreach (DevExpress.Web.ASPxUploadControl.UploadedFile uf in ASPxUploadControl1.UploadedFiles)
                    {
                        uf.SaveAs(@"C:\TEMP\ListUploads\" + uf.FileName, true);
                        ListInfo.ImportList(Convert.ToInt16(ListId), @"C:\TEMP\ListUploads\" + uf.FileName);
                    }
                }
            }

    блять, это же каким инвалидом надо быть, чтобы так сделать загрузку файла в базу?

    Lokich, 06 Июня 2017

    Комментарии (1)
  10. SQL / Говнокод #23088

    0

    1. 1
    2. 2
    3. 3
    4. 4
    5. 5
    if @SubDepartmentID = 0 set @SubDepartmentID = null
    if @QuoteID = 0 set @QuoteID = null
    if @PartnerID = 0 set @PartnerID = null
    if @QuoteID = 0 set @QuoteID = null
    if @SubDepartmentID = 0 set @SubDepartmentID = null

    это кусок хранимой процедуры

    mrvlmor, 31 Мая 2017

    Комментарии (1)
  11. JavaScript / Говнокод #23087

    +3

    1. 1
    2. 2
    3. 3
    4. 4
    // eval both the numbers to remove quotes
        // otherwise 4 + 5 will be "4" + "5" which in JS will equal 45
                evalDisplay = eval(displayNum),
                evalStored = eval(storedNum);

    Гениальный способ получить число из строки (вместо evalDisplay = +evalDisplay)

    DiphenylOxalate, 30 Мая 2017

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