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

    +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
    class Claims
    {
        ...
        function ReadClaim(...)
        {
            ...
            
            if ($this) $this->claim = $claim;
            $instance = $this ? $this : Claims::getInstance($claim);
    
            ...
        }
        ...
    }

    3371, 03 Апреля 2015

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

    +157

    1. 01
    2. 02
    3. 03
    4. 04
    5. 05
    6. 06
    7. 07
    8. 08
    9. 09
    10. 10
    function __autoload($class)
    {
    	global $CONFIG;
    	
    	if (in_array($class,array('CorpNews','User','Passengers'))) include $CONFIG[site_dir].'common/scripts/classes/common/'.$class.'.php';
    	elseif (in_array($class,array('Claims','ClaimsAviaUser','ClaimsUser'))) include $CONFIG[site_dir].'common/scripts/classes/claims/'.$class.'.php';
    	elseif (in_array($class,array('OperatorClaim','UsersCommon'))) include $CONFIG[site_dir].'common/scripts/classes/users/'.$class.'.php';
    	elseif (strpos($class, 'Avia') === 0) include $CONFIG[site_dir].'common/scripts/classes/avia/'.$class.'.php';
    	elseif (strpos($class, 'Railway') === 0) include $CONFIG[site_dir].'common/scripts/classes/railway/'.$class.'.php';
    }

    3371, 03 Апреля 2015

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

    +56

    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
    std::map<int, int> aSummator; //Массив частичных сумм
    std::vector<int> v; //Исходный массив
    
    void InitSummator()
    {
        aSummator[0] = v[0];
        aSummator[-1] = 0;
    
        for(int i = 1; i < int(v.size()); i++)
        {
            aSummator[i] = aSummator[i - 1] + v[i];
        }
    }
    
    int GetSum(int l, int r)
    {
        return aSummator[r] - aSummator[l - 1]; 
    }

    Как я писал сумматор 0.1 года назад. Вместо того, чтобы написать один if, я использовал std::map, что увеличило ассимптотику алгоритма на запрос с O(1) до O(log(n)). Но задачу при тех ограничениях (в массиве до 100000 элементов, запросов не более 100000) алгоритм решил. Преподу, естественно, показывать забоялся.

    Janycz, 03 Апреля 2015

    Комментарии (18)
  4. Python / Говнокод #17927

    −118

    1. 1
    name = name.replace(u'c', u'с') # this is magia

    kyzi007, 03 Апреля 2015

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

    +839

    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
    protected virtual string GetParentTableControlID()
            {
                try
                {
                    if (this.Parent is BaseApplicationTableControl) return this.Parent.ID;
                    if (this.Parent.Parent is BaseApplicationTableControl) return this.Parent.Parent.ID;
                    if (this.Parent.Parent.Parent is BaseApplicationTableControl) return this.Parent.Parent.Parent.ID;
                    if (this.Parent.Parent.Parent.Parent is BaseApplicationTableControl) return this.Parent.Parent.Parent.Parent.ID;
                }
                catch (Exception)
                {
                }
                return "";
            }

    greyb, 03 Апреля 2015

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

    +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
    #include <iostream>
    #include <stdexcept>
    
    template<std::size_t N>
    static int constexpr date_component(const char (&s)[N], int i, bool last, int max) {
      return 
        (i + 2 + (last ? 0 : 1) >= N) 
            ? throw std::logic_error("Too short date string") :
        (!last && s[i + 2] != ':') 
            ? throw std::logic_error("Cannot find delimiter") :
        (s[i] < '0' || s[i] > '9' ||  s[i + 1] < '0' || s[i + 1] > '9') 
            ? throw std::logic_error("Not a number") :
        ((s[i] - '0') * 10 + (s[i + 1] - '0') > max) 
            ? throw std::logic_error("Too large number") :
                (s[i] - '0') * 10 + (s[i + 1] - '0');
    }
    
    struct time { 
        int hour; int minute; int second; 
        
        template<std::size_t N>
        constexpr time(const char (&datestr)[N]) :
            hour(date_component(datestr, 0, false, 24)), 
            minute(date_component(datestr, 3, false, 60)),
            second(date_component(datestr, 6, true, 60)) 
        {}
    };
    
    struct time constexpr midnight("00:00:00");
    struct time constexpr afternoon("12:00:00");
    
    int main(int argc, char* argv[]) {
        std::cout << "Midnight hour is " << midnight.hour << std::endl;
        std::cout << "Afternoon hour is " << afternoon.hour << std::endl;
    }

    C++ и даты времени компиляции

    myaut, 03 Апреля 2015

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

    +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
    // Наткнулся в коде на
    try
    {
         throw new Provider_Exception($curl_error);
    }
    catch (Exception $e)
    {
          throw new Provider_Exception('No connection');
    }
    
    // и отрефакторил
    try
    {
         throw new Provider_Exception($curl_error);
    }
    catch (Exception $e)
    {
          throw new Provider_Exception($e->getMessage());
    }

    PROFIT!

    invision70, 03 Апреля 2015

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

    +157

    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
    <select multiple  name="fields[]">
    <option value="idblank" <?php echo in_array("idblank", $book_fields)?"selected":""; ?> >idblank</option>
    <option value="n_dog" <?php echo in_array("n_dog", $book_fields)?"selected":""; ?> >n_dog</option>
    <option value="n_failpay" <?php echo in_array("n_failpay", $book_fields)?"selected":""; ?> >n_failpay</option>
    <option value="senior" <?php echo in_array("senior", $book_fields)?"selected":""; ?> >senior</option>
    <option value="fio" <?php echo in_array("fio", $book_fields)?"selected":""; ?> >fio</option>
    <option value="date_init" <?php echo in_array("date_init", $book_fields)?"selected":""; ?> >date_init</option>
    <option value="fio_client" <?php echo in_array("fio_client", $book_fields)?"selected":""; ?>>fio_client</option>
    <option value="date_plat" <?php echo in_array("date_plat", $book_fields)?"selected":""; ?>>date_plat</option>
    <option value="pros_total" <?php echo in_array("pros_total", $book_fields)?"selected":""; ?>>pros_total</option>
    <option value="summa_post" <?php echo in_array("summa_post", $book_fields)?"selected":""; ?>>summa_post</option>
    <option value="ostatok" <?php echo in_array("ostatok", $book_fields)?"selected":""; ?>>ostatok</option>
    <option value="effect" <?php echo in_array("effect", $book_fields)?"selected":""; ?>>effect</option>
    <option value="ef" <?php echo in_array("ef", $book_fields)?"selected":""; ?>>ef</option>
    <option value="idcolor" <?php echo in_array("idcolor", $book_fields)?"selected":""; ?>>idcolor</option>
    <option value="inn" <?php echo in_array("inn", $book_fields)?"selected":""; ?>>inn</option>
    <option value="n_schet" <?php echo in_array("n_schet", $book_fields)?"selected":""; ?>>n_schet</option>
    <option value="dom_tel" <?php echo in_array("dom_tel", $book_fields)?"selected":""; ?>>dom_tel</option>
    <option value="mob_tel" <?php echo in_array("mob_tel", $book_fields)?"selected":""; ?>>mob_tel</option>
    <option value="work_tel" <?php echo in_array("work_tel", $book_fields)?"selected":""; ?>>work_tel</option>
    <option value="reg_city" <?php echo in_array("reg_city", $book_fields)?"selected":""; ?>>reg_city</option>
    <option value="reg_region" <?php echo in_array("reg_region", $book_fields)?"selected":""; ?>>reg_region</option>
    <option value="reg_district" <?php echo in_array("reg_district", $book_fields)?"selected":""; ?>>reg_district</option>
    <option value="reg_settlement" <?php echo in_array("reg_settlement", $book_fields)?"selected":""; ?>>reg_settlement</option>
    <option value="reg_adress" <?php echo in_array("reg_adress", $book_fields)?"selected":""; ?>>reg_adress</option>
    <option value="live_city" <?php echo in_array("live_city", $book_fields)?"selected":""; ?>>live_city</option>
    <option value="live_region" <?php echo in_array("live_region", $book_fields)?"selected":""; ?>>live_region</option>
    <option value="live_district" <?php echo in_array("live_district", $book_fields)?"selected":""; ?>>live_district</option>
    <option value="live_settlement" <?php echo in_array("live_settlement", $book_fields)?"selected":""; ?>>live_settlement</option>
    <option value="live_adress" <?php echo in_array("live_adress", $book_fields)?"selected":""; ?>>live_adress</option>
     </select>

    Проверка на выделенный пункт списка

    noffily, 03 Апреля 2015

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

    +53

    1. 1
    for ( ; currnet->prev != NULL; (*this)-- );

    медод везвращения итератора к началу

    artembegood, 03 Апреля 2015

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

    +149

    1. 1
    -

    onnanon, 02 Апреля 2015

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