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

    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
    public function callCost($fromCity, $fromStreet, $fromHouse, $fromHousing, $fromBuilding, $fromPorch, $fromLat, $fromLon, $toCity, $toStreet, $toHouse, $toHousing, $toBuilding, $toPorch, $toLat, $toLon, $clientName, $phone, $priorTime, $customCarId, $customCar, $carType, $carGroupId, $tariffGroupId, $comment, $additional = '')
        {
            if ($json = $this->reqCache->getValue($fromLat . $fromLon . $toLat . $toLon . $phone . $priorTime . $tariffGroupId . $comment . $additional)) {
                $data = json_decode($json);
                return $data;
            } else {
    			$tariffGroupId = $this->findTariffOnCarType($carType);
    			$additional = explode(';', $additional);
    			$route = new TaxiRouteAnalyzer($this->dbHost, $this->database, $this->dbLogin, $this->dbPass);
    			$this->writeLog($tariffGroupId);
    			$data = $route->analyzeRoute(1, $fromCity, $fromStreet, $fromHouse, $fromHousing, $fromLat, $fromLon, $toCity, $toStreet, $toHouse, $toHousing, $toLat, $toLon, $additional, $tariffGroupId, $this->isDay(), 1);
                $res = json_encode($data);
                $this->reqCache->setValue($fromLat . $fromLon . $toLat . $toLon . $phone . $priorTime . $tariffGroupId . $comment . $additional, $res, $this->cacheTime);
    			return $data; 
            }
        }

    человеку доверили сделать кэширование данных...

    akanit, 14 Декабря 2015

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

    +1

    1. 01
    2. 02
    3. 03
    4. 04
    5. 05
    6. 06
    7. 07
    8. 08
    9. 09
    10. 10
    var cloths = {
      <?php foreach ($clothList as $cloth): ?>
        "<?=$cloth->id()?>": {
          "id": <?=$cloth->id()?>,
          "name": "<?=$cloth->name()?>",
          "public_name": "<?=str_replace('"', '\"', $cloth->public_name())?>"
        },
      <?php endforeach; ?>
      "dummy": {}
    };

    kgm-rj, 14 Декабря 2015

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

    +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
    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
    if (dlgOpen.ShowDialog() != DialogResult.OK) return;
    
                txtLog.Clear();
                string customXMLFileName = dlgOpen.FileName;
                XmlDocument xmlDoc = new XmlDocument();
                xmlDoc.Load(customXMLFileName);
               
                foreach (XmlNode node in xmlDoc.DocumentElement.ChildNodes)
                {
                   
                    if (node.Name == "Surfaces")
                       {
    
                        foreach (XmlNode childNode in node.ChildNodes)
                        {
                            txtLog.AppendText(childNode.Name.ToString() + Environment.NewLine);
    
                            foreach (XmlNode _childNode in childNode.ChildNodes)
                            {
                                if (_childNode.Name == "SourceData")
                                {
                                    foreach (XmlNode __childNode in _childNode.ChildNodes)
                                    {
                                        txtLog.AppendText(__childNode.Name.ToString() + Environment.NewLine);
                                        if (__childNode.Name == "Breaklines")
                                        {
                                            foreach (XmlNode ___childNode in __childNode.ChildNodes)
                                            {
                                                txtLog.AppendText(___childNode.Name.ToString() + Environment.NewLine);
                                                XmlNode dataNode = ___childNode.LastChild;
                                                string txtData = dataNode.InnerText;
                                                txtLog.AppendText(txtData + Environment.NewLine);
                                            }
                                        }
                                    }
                                }
                            }
                        }
                   }
                }

    Невнимательное чтение MSDN привело к такому плачевному результату. А всего лишь хотелось прочитать значение дочерних нод Breaklines....
    GetElementsByTagName в помощь....

    Thrasher1980, 12 Декабря 2015

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

    +8

    1. 1
    2. 2
    3. 3
    4. 4
    5. 5
    6. 6
    7. 7
    public static class StringExtensions
        {
            public static bool IsNulldOrEmpty(this string str)
            {
                return string.IsNullOrEmpty(str);
            }
        }

    why

    antoanelenkov, 12 Декабря 2015

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

    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
    #include <iostream>
    #include <vector>
    #include <cmath>
    #include <algorithm>
    #include <stdio.h>
     
    std::vector<int> A, B, C;
     
    void build(const std::vector<int> A, int k, int razmer){
            int n = razmer;
            B.resize(n);
            C.resize(n);
            B.front() = A.front();
            C.back() = A.back();
     
            k--;
     
            for(int i1(1), i2(n - 2); i1 < n; i1++, i2--){
                    B[i1] = (i1 % k) ? std::max(A[i1], B[i1 - 1]) : A[i1];
                    C[i2] = ((i2 + 1) % k) ? std::max(A[i2], C[i2 + 1]) : A[i2];
            }
    }
     
    int main(){
            int m, count;
            A.resize(100001);
            scanf("%d", &m);
            count = 0;
     
            while(true){
                    scanf("%d", &A[count]);
                    if(A[count] == -1) break;
                    count++;
            }
     
            build(A, m, count);
            int l = 0;
            while(count - 1 >= m){
                    printf("%d\n", std::max(C[l], B[l + m - 1]));
                    l++;
            }
            return 0;
    }

    Код, реализующий поиск максимума по подотрезках последовательности чисел. Если непонятно, то тут строится дерево отрезков, и потом с ним происходит какая-то ебола. Красивое решение получается при использовании стандартного алгоритма поиска максимума в очереди за O(1) при помощи двух стеков.

    HiewMorjowie, 12 Декабря 2015

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

    +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
    14. 14
    15. 15
    16. 16
    17. 17
    18. 18
    19. 19
    <script>
    var link=window.location.href;
    var arr = link.split("#");
    document.write("<script> function fuk_flash(){");
    if (arr[1] != "d4"){
    document.write("appD4.setAttribute(\"style\", \"display:none\");");
    }
    if (arr[1] != "d5"){
    document.write("appD5.setAttribute(\"style\", \"display:none\");");
    }
    if (arr[1] != "f"){
    document.write("appF.setAttribute(\"style\", \"display:none\");");
    }
    document.write("}<\/script>");
    </script>
    
    <script>
    window.onload=fuk_flash;
    </script>

    Когда на странице 3 флэшки, необходимо показывать только одну, исходя из атрибутов ссылки, и когда ни одна из них не показывает полосу загрузки (при своем немалом весе) после обращения к себе, и когда все более-менее адекватные решения провалились.



    (Но проблема оказалась в том, что флэш находил в адресе страницы # и переставал грузиться)

    stasyan1902, 12 Декабря 2015

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

    +2

    1. 1
    2. 2
    3. 3
    4. 4
    if (!$subscription) {
        return $this->redirect(['action' => 'cancel_success']);
        throw new BadRequestException();
    }

    epadqwbd, 11 Декабря 2015

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

    −4

    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
    try {
        f();
    }
    catch(...) {
        std::cout << "f() throw\n";
    }
    try {
        g();
    }
    catch(...) {
        std::cout << "g() throw\n";
    }
    try {
        k();
    }
    catch(...) {
        std::cout << "k() throw\n";
    }
    // etc ...

    absolut, 11 Декабря 2015

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

    +2

    1. 1
    https://toster.ru/q/274179

    Ученики Mr.Shit (беднягу зачмырили и он сменил домен на php. webtm.ru) продолжают радовать

    loki90, 11 Декабря 2015

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

    +11

    1. 1
    2. 2
    3. 3
    4. 4
    5. 5
    6. 6
    7. 7
    8. 8
    void Aligner::set_genomic_sequences(vector< pair <string,string> > nt_genomic_seq){
    	this->nt_genomic_sequences = *(new forward_list<pair<string,string>>);
    	this->int_genomic_sequences = *(new forward_list<pair<string,string>>);
    	for(vector<pair<string,string>>::const_iterator iter = nt_genomic_seq.begin() ; iter != nt_genomic_seq.end() ; iter++){
    		nt_genomic_sequences.emplace_front((*iter).first,(*iter).second);
    		int_genomic_sequences.emplace_front((*iter).first , nt2int((*iter).second));
    	}
    }

    Типичный академический код из https://bitbucket.org/yuvalel/repgenhmm. Могу только предположить, что авторы скопипастили код из Java, а потом разыменовывали указатели, пока не скомпилировалось.

    Yuuri, 11 Декабря 2015

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