1. Ruby / Говнокод #6612

    −106

    1. 01
    2. 02
    3. 03
    4. 04
    5. 05
    6. 06
    7. 07
    8. 08
    9. 09
    10. 10
    def parse_response(object)
        return Hashie::Mash.new(JSON.parse(object))
      rescue => e
        #should handle here different error types/levels or else throw the exceptions to the upper layer (client)
        if e.is_a?(JSON::ParserError) && e.message =~ /<html>/
          raise "Invalid response from Platform server - #{self.class.parse_json_error(response.body)}"
        else
          raise e
        end
      end

    sumskyi, 10 Мая 2011

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

    +149

    1. 1
    2. 2
    3. 3
    4. 4
    5. 5
    6. 6
    7. 7
    $day = "Tuesday";
                        print $day." = $ day <br>";  // Tuesday
    		$var = "day";                             // используются двойные кавычки
                        print $var." = $ var <br>";  // day 
    		$$var = "Friday";
                        print $var." = $ var <br>";  // day
    		print $day." = $ day <br>";    // Friday

    Почему $day принимает значение Friday к нему ведь никто не обращался ???
    Записки идиота.

    lan-dao, 10 Мая 2011

    Комментарии (12)
  3. Python / Говнокод #6610

    −180

    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
    #обработка формы
    if request.method == 'POST':
        form = MdatForm(request.POST)
        #проверка правильности заполнения полей формы
        if form.is_valid():
                cd = form.cleaned_data
                #переменные для проверки правильности ввода данных
                valid1 = cd['sername']+cd['name']+cd['ssername']
                valid2 = cd['get']+cd['born']+cd['adres']
                #проверка ФИО
                for i in valid1:
                    if (re.match(u"^[A-Za-z0-9]+$", i))or(i in errorfio):
                        return redirect_with_message(request, 'error', 'Корректно введите ФИО', reverse(changemet))
                #проверка адрес, дата роэждения, кем выдано
                for i in valid2:
                    if (re.match(u"^[A-Za-z]+$", i))or(i in errorvmb):
                        return redirect_with_message(request, 'error', 'Корректно введите "Место рождения", "Адрес", "Кем выдан"', reverse(changemet))
                #сохранить изменения
                changemetadd(cd, request.user)
                #запись действия в журнал
                userlogpath(request.user, 'Осуществлено редактирование метаданных')
                #вывод сообщения
                return redirect_with_message(request, 'success', 'Данные были сохранены в системе регистрации изображений', reverse('home.views.index'))
    
    
    #форма первичной регистрации
    class PhForms(forms.Form):
            email = forms.EmailField(label='Email*', error_messages={'required': 'Заполните поле'})
            sername = forms.CharField(max_length=50, label='Фамилия*', error_messages={'required': 'Заполните поле'})
            name = forms.CharField(max_length=50, label='Имя*', error_messages={'required': 'Заполните поле'})
            ssername = forms.CharField(max_length=40, label='Отчество', required=False)
            databorn = forms.DateField(label='Дата рождения:', widget=SelectDateWidget(years=range(year, year-101, -1)), required=False)#forms.DateField(label='Дата рождения:*',initial=datetime.date.today, input_formats=('%d-%m-%Y',),
    		#widget=SelectDateWidget(input_format='%d-%B-%Y', years=range(year, year-101, -1)))
            pasportserial = forms.IntegerField(max_value=9999, label='Паспорт серия', required=False)
            pasportnomer = forms.IntegerField(max_value=999999, label='Паспорт номер', required=False)
            get = forms.CharField(max_length=100, label='Кем выдан*', required=False)
            dataget = forms.DateField(label='Дата выдачи:', widget=SelectDateWidget(years=range(year, year-101, -1)), required=False)#forms.DateField(label='Дата выдачи*:', initial=datetime.date.today, input_formats=('%d-%m-%Y',),
    		#widget=SelectDateWidget(input_format='%d-%B-%Y', years=range(year, year-101, -1)))
            born = forms.CharField(max_length=200, label='Место рождения*', required=False)
            adres = forms.CharField(max_length=200, label='Адрес*', required=False)
    	#text = forms.CharField(label='Семейное положение', max_length=200)
    
    
    #изображения и мииатюры
    class Image(models.Model):
        user = models.ForeignKey('User')
        publication_date = models.DateTimeField(auto_now_add=True)
        nomersertifikata = models.IntegerField()
        imgname = models.CharField(max_length=200)
        tip_foto = models.ForeignKey('img_subj.ImageSubjects')
        public = models.BooleanField()
        img = models.ImageField(upload_to=get_upload_to)
        mini_img = models.ImageField(upload_to=mini_get_upload_to)
        #создание миниатюры
        def save(self):
            THUMBNAIL_SIZE = (100, 100)
            image = PIL.Image.open(self.img)
            if image.mode not in ('L', 'RGB'):
                image = image.convert('RGB')
            image.thumbnail(THUMBNAIL_SIZE, PIL.Image.ANTIALIAS)
    
            temp_handle = StringIO()
            image.save(temp_handle, 'png')
            temp_handle.seek(0)
    
            suf = SimpleUploadedFile(os.path.split(self.img.name)[-1],
            temp_handle.read(), content_type='image/png')
            self.mini_img.save(suf.name+'.png', suf, save=False)
    
            super(Image, self).save()

    Вот так кодят в универах.

    alex-86, 10 Мая 2011

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

    −176

    1. 1
    2. 2
    3. 3
    4. 4
    def reverse(s, rs=''):
        for i in range(1, len(s)):
            rs = rs + s[len(s)-i]
        return rs+s[0]

    Reverse String по-питоновски с говном

    Govnocoder#0xFF, 10 Мая 2011

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

    +159

    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
    class CVal
    {
    private:
        int m_val;
    public:
        __declspec(property(get=get_Val, put=put_Val)) int Val;
        int get_Val()
        {
            return m_val;
        }
        void put_Val(int val)
        {
            m_val = val;
        }
    };

    Говно в рамках стандарта C++.

    Говногость, 10 Мая 2011

    Комментарии (40)
  6. PHP / Говнокод #6607

    +159

    1. 1
    2. 2
    3. 3
    4. 4
    5. 5
    6. 6
    7. 7
    8. 8
    $value = "";
    $content = $content;
    $val = "\$content->" . $field->name;
    $fieldname = $field->name;
    
    eval("if (isset($val)) \$value = \"$val\";");
    $value = JText::_($value);
    $value = stripslashes($value);

    Joomla. Adsmanager

    Jetti, 10 Мая 2011

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

    +131

    1. 1
    2. 2
    3. 3
    4. 4
    5. 5
    6. 6
    7. 7
    8. 8
    <tr> <td width="209" valign="top"><font color="#1674b5">Русский язык</font></td> <td width="244" valign="top"><font color="#1674b5">История России</font></td> <td width="218" valign="top"><font color="#1674b5">Биология</font></td> </tr>
                 
                  <tr> <td width="209" valign="top"><font color="#1674b5">Литература</font></td> <td width="244" valign="top"><font color="#1674b5">Обществознание</font></td> <td width="218" valign="top"><font color="#1674b5">Химия</font></td> </tr>
    
                 
                  <tr> <td width="209" valign="top"><font color="#1674b5">Математика</font></td> <td width="244" valign="top"><font color="#1674b5">Физика</font></td> <td width="218" valign="top"><font color="#1674b5">География</font></td> </tr>
                 
                  <tr> <td width="209" valign="top"><font color="#1674b5">Информатика и ИКТ</font></td> <td width="244" valign="top"><font color="#1674b5">Иностранный язык</font></td> <td width="218" valign="top">

    Вёрстка сайта на Битриксе.

    RaZeR, 09 Мая 2011

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

    +147

    1. 1
    http://pastebin.com/HmLsBTsp

    manyrus, 09 Мая 2011

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

    +125

    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
    /// <summary>
            /// Return a DateTime version of the given Jabber date.  Example date: 20020504T20:39:42
            /// </summary>
            /// <param name="dt">The pseudo-ISO-8601 formatted date (no milliseconds)</param>
            /// <returns>A (usually UTC) DateTime</returns>
            public static DateTime JabberDate(string dt)
            {
                if ((dt == null) || (dt == ""))
                    return DateTime.MinValue;
                try
                {
                    return new DateTime(int.Parse(dt.Substring(0, 4)),
                                        int.Parse(dt.Substring(4, 2)),
                                        int.Parse(dt.Substring(6, 2)),
                                        int.Parse(dt.Substring(9,2)),
                                        int.Parse(dt.Substring(12,2)),
                                        int.Parse(dt.Substring(15,2)));
                }
                catch
                {
                    return DateTime.MinValue;
                }
            }
            /// <summary>
            /// Get a jabber-formated date for the DateTime.   Example date: 20020504T20:39:42
            /// </summary>
            /// <param name="dt">The (usually UTC) DateTime to format</param>
            /// <returns>The pseudo-ISO-8601 formatted date (no milliseconds)</returns>
            public static string JabberDate(DateTime dt)
            {
                return string.Format("{0:yyyy}{0:MM}{0:dd}T{0:HH}:{0:mm}:{0:ss}", dt);
            }

    Перевод DateTime в строку вида "20020504T20:39:42" и обратно. Из исходников библиотеки Jabber-net.
    TryParseExact и ToString с форматом "yyyyMMddTHH:mm:ss" - это пусть лентяи используют.

    Nagg, 09 Мая 2011

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

    +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
    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
    class CLoader
    {
    	protected static $_importPaths = array(APPLICATION_PATH);
    	
    	public static function import($path)
    	{
    		self::$_importPaths[] = APPLICATION_PATH . '/' . $path;
    	}
    	
    	public function classExist($className)
    	{
    		return class_exists($className) || interface_exists($className);
    	}
    	
    	public static function autoload($className)
    	{
    		foreach(self::$_importPaths as $path)
    		{
    			if(is_file($fileName = $path . '/' . $className . '.php'))
    			{
    				include $fileName;
    				break;
    			}
    		}
    	}
    }
    
    spl_autoload_register(array('CLoader', 'autoload'));

    Гавнокод или нет? Идея в том, чтобы нормально можно было написать if(CLoader::classExist('Router'))...

    Может я чего не дочитал, но если добавлять пути с либами в include_path, а в функции autoload просто писать include $className . '.php', то class_exists('Router') выкинет ошибку, если файл Router.php не найден.

    Jetti, 09 Мая 2011

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