1. JavaScript / Говнокод #14340

    +155

    1. 1
    2. 2
    $(element).width($(element).width());
    $(element).height($(element).height());

    Просто нет слов.

    Diwms, 10 Января 2014

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

    +156

    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
    function t($text, $parameters = null) {
            $lang = empty($_COOKIE['lang']) ? 'ru' : $_COOKIE['lang'];
            $result = !array_key_exists($text, Application_Model_Translate::$lang_package) || ($lang == 'ru') ? $text :
                    Application_Model_Translate::$lang_package[$text][(int) ($lang == 'en')];
            if (isset($parameters)) {
                    if (!is_array($parameters))
                            $parameters = array($parameters);
                    foreach ($parameters as &$param)
                            $param = addslashes($param);
                    eval('$result = sprintf($result, "'. implode('","', $parameters) . '");');
            }
            return $result;
    }

    Groovy, 10 Января 2014

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

    +137

    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
    public static string AddControlDigits(string input)
    {
          if (String.IsNullOrEmpty(input))
              return "";
          try
          {
              XDocument doc = XDocument.Parse(input.JavaSubString(input.IndexOf("<contracts>"), input.IndexOf("</contracts>") + "</contracts>".Length));
              String s = new String(doc.ToString().ToCharArray());
                    
              XElement rootElement = doc.Root.Element("list_item");
    
              string basicNumber = rootElement.Element("basicNumber").Value;
              string endNumber = rootElement.Element("endNumber").Value;
              string loanCaseNumber = rootElement.Element("loanCaseNumber").Value;
              string loanCaseComplementNumber = rootElement.Element("loanCaseComplementNumber").Value;
              string bridgeLoanComplementNumber = rootElement.Element("bridgeLoanComplementNumber").Value;
    
              int checkNumber = CalcCheckDigitCU(basicNumber + endNumber);
              int loanCaseCheckNumber = calcCheckDigitUP(loanCaseNumber);
              int bridgeLoanCheckNumber = CalcCheckDigitCU(basicNumber + bridgeLoanComplementNumber);
    
              rootElement.Add(new XElement("checkNumber", checkNumber));
              rootElement.Add(new XElement("loanCaseCheckNumber", loanCaseCheckNumber));
              rootElement.Add(new XElement("bridgeLoanCheckNumber", bridgeLoanCheckNumber));
    
              input = input.Replace(s, doc.ToString());
    
              return "";
         }
         catch (Exception ex)
         {
             throw;
          }
     }

    жопа

    taburetka, 10 Января 2014

    Комментарии (33)
  4. Java / Говнокод #14337

    +73

    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
    85. 85
    public enum Action {
    
        ADD, DELETE, UPDATE, REFRESH;
    
        public static Action getEnum(String value) {
            for (Action current : values()) {
                if (current.name().equalsIgnoreCase(value)) {
                    return current;
                }
            }
            throw new IllegalArgumentException("Unknown input value. Input value is '" + value + "'");
        }
    
        @Override
        public String toString() {
            return this.name().toLowerCase();
        }
    }
    
    public enum Manager {
    
        USER, ROLE, SERVICE;
    
        public static Manager getEnum(String value) {
            for (Manager current : values()) {
                if (current.name().equalsIgnoreCase(value)) {
                    return current;
                }
            }
            throw new IllegalArgumentException("Unknown input value. Input value is '" + value + "'");
        }
    
        @Override
        public String toString() {
            return this.name().toLowerCase();
        }
    
        public boolean isUser() {
            return this == USER;
        }
    
        public boolean isRole() {
            return this == ROLE;
        }
    
        public boolean isService() {
            return this == SERVICE ;
        }
    }
    
    public class StringToEnumConverterFactory implements ConverterFactory<String, Enum> {
        @Override
        public <T extends Enum> Converter<String, T> getConverter(Class<T> targetType) {
            return new StringToEnumConverter<T>(targetType);
        }
    
        private final class StringToEnumConverter<T extends Enum> implements Converter<String, T> {
    
            private Class<T> enumType;
    
            private StringToEnumConverter(Class<T> enumType) {
                this.enumType = enumType;
            }
    
            @Override
            public T convert(String source) {
                if (enumType.getName().equalsIgnoreCase("com.finder.enumerator.manager")) {
                    return (T) Manager.getEnum(source);
                }
                if (enumType.getName().equalsIgnoreCase("com.finder.enumerator.action")) {
                    return (T) Action.getEnum(source);
                }
                return (T) Enum.valueOf(this.enumType, source);
            }
        }
    }
    
    /* -- Mapping -- */
    @RequestMapping(value = "manage/index/{manager}/{action}", method = RequestMethod.GET)
    public String addValueToEntity(@PathVariable("manager") Manager manager, @PathVariable("action") Action action) {
    ...
    
    @RequestMapping(value = "/manage/index", method = RequestMethod.GET)
    public String indexPage(ModelMap model, @RequestParam(value = "manager", required = true) Manager manager) {
    ...

    Spring MVC. Проблема в том что строка lovercase а значения Enum-ов uppercase

    govnoacc, 10 Января 2014

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

    +16

    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
    #include <iostream>
    using namespace std;
    struct T
    {
      int a, b, &c;
      T():a(0), b(1), c(a){cout<<"dc"<<endl;}
      T(const T& a):a(a.a), b(a.b), c(&a.c == &a.a ? this->a : b){cout<<"cc"<<endl;}
      T& operator=(T a)
      {
        ::new((void*)(&b+1)) int*(&a.c == &a.a ? &this->a : &b);
        //asm volatile ("" : : : "memory");
        cout<<"co"<<endl;
        return *this;
      }
      void Switch()
      {
        ::new((void*)(&b+1)) int*(&c == &a ? &b : &a);
        //asm volatile ("" : : : "memory");
        cout<<"sw"<<endl;
      }
    } __attribute__((aligned(1))) ;
    
    int main() {
      T a;
      cout<<a.a<<endl;
      cout<<a.b<<endl;
      cout<<a.c<<endl;
      a.Switch();
      cout<<a.c<<endl;
      T b;
      cout<<b.c<<endl;
      b=a;
      cout<<b.c<<endl;
      b.b=666;
      cout<<b.c<<endl;
      return 0;
    }

    Очевидно откуда это.

    LispGovno, 10 Января 2014

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

    +18

    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
    85. 85
    86. 86
    87. 87
    88. 88
    template <typename T>
      struct canref {
        struct yes { uint8_t bytes[1]; };
        struct no  { uint8_t bytes[2]; };
        template <typename U>    static yes test(U*p);
        template <typename U>    static no  test(...);
        static const bool value = sizeof(test<T>(NULL)) == sizeof(yes);
      };
      template <typename T, int N, bool CanRef=canref<T>::value>
      class array; 
      // class for all types
      template <typename T, int N>
      class array <T,N,true>
      {
        struct Bytes
        {
          uint8_t bytes[sizeof(T)];
        };
        struct TStruct
        {
          T t;
          TStruct(T t):t(t){}
        };
    
        Bytes elements[N];
        int count;
        void copy_ctor (int index, const T& t)
        {
          new (&((*this)[index])) T(t);      
        }
        void copy (int index, const T& t)
        {
          (*this)[index] = t;
        }
    
        void dtor (int index)
        {
          (*this)[index].~T();
        }
      public:
        array () : count(0) {}
    
        ~array () 
        {
          resize(0);
        }
        T& operator [] (int index) 
        {
          assert (index>=0 && index<count);      
          return ((TStruct*)(&elements[index]))->t;
        }
        const T& operator [] (int index) const 
        {
          assert (index>=0 && index<count);      
          return ((TStruct*)(&elements[index]))->t;
        }
        template <int M>
        array (const array<T,M> &a)
        {
          assert(a.count<=N);
          count = a.count;
          for (int i=0; i<count; ++i)
            copyctor(i, a[i]);
        }
        template <int M>
        array& operator = (const array<T,M> &a)
        {
          if (this != &a)
          {
            if (count>a.count)
            {
              for (int i=0;       i<a.count; ++i) copy(i, a[i]);
              for (int i=a.count; i<count;   ++i) dtor(i);
              count = a.count;
            } else
            {
              assert(a.count<=N);
              int ocount = count;
              count = a.count;
              for (int i=0;      i<ocount; ++i) copy(i, a[i]);
              for (int i=ocount; i<count;  ++i) copy_ctor(i, a[i]);
            }
          }
        }
        int size() 
        {
          return count;
        }

    Скоро даже сратору станет очевидно откуда это.

    LispGovno, 10 Января 2014

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

    +141

    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
    using System;
    using System.Globalization;
    using System.IO;
     
    namespace CyberForumTasks
    {
        class Program
        {
            static void Main()
            {
                var text = File.ReadAllText("C:\\test.txt");
     
                for (var i = 0; i < text.Length - 1; i++)
                {
                    if (text[i].ToString(CultureInfo.InvariantCulture).Contains("1"))
                        if (text[i + 1].ToString(CultureInfo.InvariantCulture).Contains("0"))
                            if (text[i + 2].ToString(CultureInfo.InvariantCulture).Contains("1"))
                                Console.Write("101");
     
                    if (text[i].ToString(CultureInfo.InvariantCulture).Contains("1"))
                        if (text[i + 1].ToString(CultureInfo.InvariantCulture).Contains("1"))
                            if (text[i + 2].ToString(CultureInfo.InvariantCulture).Contains("0"))
                                Console.Write("110");
     
                    if (text[i].ToString(CultureInfo.InvariantCulture).Contains("1"))
                        if (text[i + 1].ToString(CultureInfo.InvariantCulture).Contains("1"))
                            if (text[i + 2].ToString(CultureInfo.InvariantCulture).Contains("1"))
                                Console.Write("111");
     
                    if (text[i].ToString(CultureInfo.InvariantCulture).Contains("1"))
                        if (text[i + 1].ToString(CultureInfo.InvariantCulture).Contains("0"))
                            if (text[i + 2].ToString(CultureInfo.InvariantCulture).Contains("0"))
                                if (text[i + 3].ToString(CultureInfo.InvariantCulture).Contains("0"))
                                    Console.Write("1000");
     
                    if (text[i].ToString(CultureInfo.InvariantCulture).Contains("1"))
                        if (text[i + 1].ToString(CultureInfo.InvariantCulture).Contains("0"))
                            if (text[i + 2].ToString(CultureInfo.InvariantCulture).Contains("0"))
                                if (text[i + 3].ToString(CultureInfo.InvariantCulture).Contains("1"))
                                    Console.Write("1001");
     
                    if (text[i].ToString(CultureInfo.InvariantCulture).Contains("1"))
                        if (text[i + 1].ToString(CultureInfo.InvariantCulture).Contains("0"))
                            if (text[i + 2].ToString(CultureInfo.InvariantCulture).Contains("1"))
                                if (text[i + 3].ToString(CultureInfo.InvariantCulture).Contains("0"))
                                    Console.Write("1010");
                }
            }
        }
    }

    Дан файл целых чисел. Продублировать в нем все числа, принадлежащие диапазону 5..10.

    Psilon, 09 Января 2014

    Комментарии (32)
  8. JavaScript / Говнокод #14333

    +158

    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
    if (xmasCard.isTablet)
            {
                if (xmasCard.orient === "portrait")
                {
                    addPositionItems = 2;
                    if (myX === 0)
                    {
                        myX = (window.innerWidth - parseInt($("#snowManNaked").css("width").split("px")[0])) / 2;
                    }
                }
                else if (xmasCard.orient === "landscape")
                {
                    addPositionItems = 1.1933174224343675417661097852029;
                    if (myX === 0)
                    {
                        myX = (window.innerWidth - parseInt($("#snowManNaked").css("width").split("px")[0])) / 2;
                    }
                }
            }

    Код от колумбийских аутсорсеров. На вопрос "а что это за волшебное число такое" был дан ответ - "more numbers you put more precise it gets on all screens".

    cahbtexhuk, 09 Января 2014

    Комментарии (3)
  9. Куча / Говнокод #14331

    +128

    1. 1
    2. 2
    3. 3
    4. 4
    Sorry! The page could not be loaded.
    
    Unable to connect to MySQL and select database.
    MySQL reported: Access denied for user 'root'@'localhost' (using password: YES)

    http://gvforum.ru/

    эх, vasiliy, кто ж на продакшене базу от рута поднимает? надо же от юзверя с правами insert, delete, update, select

    Lure Of Chaos, 08 Января 2014

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

    +15

    1. 01
    2. 02
    3. 03
    4. 04
    5. 05
    6. 06
    7. 07
    8. 08
    9. 09
    10. 10
    11. 11
    12. 12
    struct Point3D {
      float x,y,z;
    
      float& operator [] (int i) {
        switch (i) {
        case 0: return x;
        case 1: return y;
        case 2: return z;
        default: assert(false);
        }
      }
    };

    Писал Жабапоглащенный.

    LispGovno, 08 Января 2014

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