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

    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
    // table for cart must have unique index for both columns for correct effect of this function
        function save() {
            if ($this->errno_ || !$this->db_link_)
                return;
                
            // optimized loop
            $n = count($this->products_) - 1;
            $s_query = "REPLACE INTO `". Config::DB_CART_TABLE_NAME ."` VALUES ";
            for($i = 0; $i < $n; ++$i) {
                $s_query .= "('". $this->phpsessid_ ."',". $this->products_[$i]->getId() .",". $this->counts_[$i] .",'". $this->sizes_[$i] ."')"; 
            }
            if ($n + 1) 
                $s_query .= "('". $this->phpsessid_ ."',". $this->products_[$n]->getId() .",". $this->counts_[$n] .",'". $this->sizes_[$n] ."')";
            
            print($s_query);
            $res = mysqli_query($this->db_link_, $s_query);
            if (!$res)
                $this->errno_ = IModel::E_DB_QUERY;
        }
    
    // Запрос сформирован некорректно, нету запятых между кортежами значений:/
    // REPLACE INTO `cart` VALUES ('cbn1c7ljjd3gglb2lmpa96grnq3prq2iefb2elvcb4fhr9r0qls1',700,4,'')('cbn1c7ljjd3gglb2lmpa96grnq3prq2iefb2elvcb4fhr9r0qls1',701,2,'')

    Опять мой говнокод.
    И это как-то србатывало О_о

    OlegUP, 10 Апреля 2019

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

    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
    static class MathParser
    {
        static double getFunc(char op, double a, double b)
        {
            switch (op)
            {
                case '+': return a + b;   case '-': return a - b;
                case '*': return a * b;   case '/': return a / b;   case '%': return a % b;
                case '^': return Pow(a, b);   default: return double.NaN;
            }       
        }
        static char[][] ops = { new char[] { '+', '-' }, new char[] { '*', '/', '%' }, new char[] { '^' } };
        public static double Eval(string str) => Eval(ref str, 0, str.Length);
        private static double Eval(ref string str, int z, int l, int i = 0)
        {
            for (; i < 3; i++)
                for (int v = l - 1; v >= z; v--)
                    for (int j = ops[i].Length - 1; j >= 0; j--)
                        if (str[v] == ops[i][j])
                            return getFunc(str[v], 
                                Eval(ref str, z, v, i),
                                Eval(ref str, v + 1, l, i + 1));
            return double.Parse(str.Substring(z, l - z));
        }
    }

    Какой-то укуренный калькулятор получился...
    MathParser.Eval("3,1346") => 3.1346
    MathParser.Eval("3+2*5") => 13
    MathParser.Eval("2^5-1") => 31
    MathParser.Eval("1/2^3") => 0.125
    MathParser.Eval("2^2^2^2") => 256
    MathParser.Eval("7,2%3") => 1.2

    groser, 09 Апреля 2019

    Комментарии (182)
  3. Си / Говнокод #25526

    +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
    #include <stdio.h>
    #include <stdlib.h>
    
    void myfree(void *ptr)
    {
      printf("%p\n", *(void **)ptr);
      free(*(void **)ptr);
      printf("freed!\n");
    }
    
    int main(void) {
      char *x __attribute__ (( cleanup (myfree)  )) = malloc(1);
      printf("%p\n", x);
      return 0;
    }

    https://gcc.gnu.org/onlinedocs/gcc/Common-Variable-Attributes.html

    cleanup (cleanup_function)

    The cleanup attribute runs a function when the variable goes out of scope. This attribute can only be applied to auto function scope variables; it may not be applied to parameters or variables with static storage duration. The function must take one parameter, a pointer to a type compatible with the variable. The return value of the function (if any) is ignored.

    If -fexceptions is enabled, then cleanup_function is run during the stack unwinding that happens during the processing of the exception. Note that the cleanup attribute does not allow the exception to be caught, only to perform an action. It is undefined what happens if cleanup_function does not return normally.

    j123123, 09 Апреля 2019

    Комментарии (28)
  4. Куча / Говнокод #25525

    −106

    1. 1
    Вы все дураки и не лечитесь

    HEPEALHO_KPYT, 09 Апреля 2019

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

    +1

    1. 1
    2. 2
    3. 3
    4. 4
    for i in for i in itertools.count():
        # ...
        if i >= x:
            break

    syoma, 08 Апреля 2019

    Комментарии (7)
  6. Куча / Говнокод #25523

    −101

    1. 1
    Забаньте гостинхо.

    Гуестинхо

    fuckyou, 08 Апреля 2019

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

    0

    1. 1
    if (true === false)

    не ну шоб наверняка

    quentiam, 08 Апреля 2019

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

    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
    using System;
    using System.Linq;
    using s = System.String;
    using i = System.Int32;
    class Player
    {
        static i sgn(i x) => x < 0 ? -1 : x > 0 ? 1 : 0;
        static s g(ref i z, i Z, s S)
        {
            i t = sgn(z - Z);
            if (t < 0) z++;
            else if (t > 0) z--;
            return S[t + 1] + "";
        }
        static void Main()
        {
            var a = Console.ReadLine().Split().Select(i.Parse).ToArray();
            i X = a[0], Y = a[1], x = a[2], y = a[3];
            while (true)
            {
                Console.ReadLine();
                Console.WriteLine(g(ref y, Y, "S N") + g(ref x, X, "E W"));
            }
        }
    }

    Поиск пути на плоскости от первой точки координат до второй. Выводит направление следующего передвижения.

    groser, 08 Апреля 2019

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

    +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
    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
    #include <iostream>
    #include <functional>
    #include <array>
    #include <iterator>
    
    template <class T>
    class Filter : public std::iterator<
                     std::input_iterator_tag,
                     typename std::iterator_traits<T>::value_type,
                     typename std::iterator_traits<T>::difference_type,
                     typename std::iterator_traits<T>::pointer,
                     typename std::iterator_traits<T>::reference
                   >
    {
    private:
      typedef typename std::iterator_traits<T>::value_type value_type;
      std::function<bool(value_type)> m_predicate;
      T m_begin, m_end;
      value_type m_current;
    
    public:
      Filter(T t_begin, T t_end, std::function<bool(value_type)> t_predicate)
        : m_begin(t_begin), m_end(t_end), m_predicate(t_predicate)
      {
      }
      
      Filter<T>& begin()
      {
        return ++*this;
      }
      
      Filter<T>& end()
      {
        return *this;
      }
      
      value_type operator* ()
      {
        return m_current;
      }
      
      Filter<T>& operator++ ()
      {
        do {
          m_current = *m_begin;
          ++m_begin;
        } while (m_begin != m_end && !m_predicate(m_current));
        return *this;
      }
      
      
      bool operator!= (Filter<T>& t_right)
      {
        return m_begin != t_right.m_end;
      }
    };
    
    
    int main()
    {
      std::array<int, 10> arr{ {4, 35, 0, 23, 0, 0, 5} };
      for (auto i : Filter<typename std::array<int,10>::iterator>(arr.begin(), arr.end(), [](int x){return x != 0;})) {
        std::cout << i << " ";
      }
    }

    Lemming, 07 Апреля 2019

    Комментарии (63)
  10. Куча / Говнокод #25519

    −99

    1. 1
    Прошу забанить всех на один год.

    админа - бессрочно.

    AHCKujlbHblu_netyx, 06 Апреля 2019

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