1. C++ / Говнокод #6531

    +168

    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
    typedef union Variant
        {
        public:
            Variant() {}
    
            Variant(signed int val) :
                v_int(val)
            {}
            operator signed int &() { return const_cast<signed int&>(this->operator const signed int &()); }
            operator const signed int&() const { return v_int; }
    
            Variant(unsigned int val) :
                v_uint(val)
            {}
            operator unsigned int &() { return const_cast<unsigned int&>(this->operator const unsigned int &()); }
            operator const unsigned int &() const { return v_uint; }
    
            Variant(char val) :
                v_char(val)
            {}
            operator char &() { return const_cast<char&>(this->operator const char &()); }
            operator const char&() const { return v_char; }
    
            Variant(double val) :
                v_float(val)
            {}
            operator double &() { return const_cast<double&>(this->operator const double &()); }
            operator const double &() const { return v_float; }
    
            Variant(void *val) :
                v_ptr(val)
            {}
            operator void*& () { return const_cast<void*&>(this->operator void *&()); }
            operator const void* const& () const { return v_ptr; }
    
            static size_t getValueSize(const Type::OfType &type)
            {
                size_t result = 0;
                switch ( type )
                {
                case Type::Pointer:
                case Type::CharPtr:
                case Type::IntPtr:
                case Type::UIntPtr:
                case Type::RealPtr:
                case Type::String:
                    result = sizeof(v_ptr);
                    break;
                case Type::Char:
                    result = sizeof(v_char);
                    break;
                case Type::Int:
                    result = sizeof(v_int);
                    break;
                case Type::UInt:
                    result = sizeof(v_uint);
                    break;
                case Type::Real:
                    result = sizeof(v_float);
                    break;
                case Type::Void:
                    result = 0;
                    break;
                }
                return result;
            }
    
        private:
            void* v_ptr;
            char v_char;
            unsigned int v_uint;
            signed int v_int;
            double v_float;
        } Variant;

    Небольшая имплементация безтиповости ;-[

    Elvenfighter, 02 Мая 2011

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

    +147

    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
    void tolowerStr(char *Str)
    {
         #include <windows.h>
         #include <ctype.h>
    
         SetConsoleCP(1251);
         SetConsoleOutputCP(1251);
         setlocale(LC_CTYPE,"Russian");
         
         int len = strlen(Str);
         for(int c=0; c<len; c++)
           Str[c] = tolower(Str[c]);
    }

    инклайд в теле ф-и :D

    Antichat, 02 Мая 2011

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

    +161

    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
    if($age != '') {
    			$d_m_y = explode('-', $age); // Разделяем на day(0) month(1) year(2)
    		// ГЕНЕРАЦИЯ ФОРМЫ С ДНЕМ РОЖДЕНИЯ
    		$vars['bday'] = "<select name=\"b_day\">\n<option>-</option>\n";
    		$i = 1;
    		while ($i <= 31) {
    			if($d_m_y[0] == $i) {
    				$sel = ' selected';
    			} else {
    				$sel = '';
    			}
    			$vars['bday'] .= '<option'.$sel.'>'.$i."</option>\n";
    			$i++;
    		}
    		$vars['bday'] .= "</select>\n";
    		// ГЕНЕРАЦИЯ СПИСКА С МЕСЯЦАМИ
    		$i = 1;
    		$vars['bmonth'] = "<select name=\"b_month\">\n<option>-</option>\n";
    		while ($i <= 12) {
    			if($d_m_y[1] == $i) {
    				$sel = ' selected';
    			} else {
    				$sel = '';
    			}
    			$vars['bmonth'] .= '<option'.$sel.'>'.$i."</option>\n";
    			$i++;
    		}
    		$vars['bmonth'] .= "</select>\n"; // Месяц ДР при ред
    		// ГЕНЕРАЦИЯ СПИСКА С ГОДАМИ
    		$i = 1940;
    		$vars['byear'] = "<select name=\"b_year\"\n<option>-</option>\n"; // Год ДР при ред
    		while ($i <= 2003) {
    			if($d_m_y[2] == $i) {
    				$sel = ' selected';
    			} else {
    				$sel = '';
    			}
    			$vars['byear'] .= '<option'.$sel.'>'.$i."</option>\n";
    			$i++;
    		}
    		$vars['byear'] .= "</select>\n";
    		$vars['use_age'] = false; // ОТКЛЮЧАЕМ ПОКАЗ ПУСТОГО СПИСКА
    		} else {
    		$vars['use_age'] = true;
    		$vars['bday'] = false;
    		$vars['bmonth'] = false;
    		$vars['byear'] = false;
    		}

    Генерация SELECT'ов для выбора даты рождения

    Мартин, 02 Мая 2011

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

    +163

    1. 1
    2. 2
    3. 3
    4. 4
    5. 5
    6. 6
    7. 7
    8. 8
    /**
       * Строка парсится в аргументы функции
       * @param string
       * @return <type>
       */
      protected function _parse_func_arg ( $str ) {
        return func_get_args();
      }

    Поколупал netсat. Получил много эмоций... Спасибо.
    ( PS. По-моему, скоро netсat останется только в unix... )

    istem, 02 Мая 2011

    Комментарии (19)
  5. ActionScript / Говнокод #6527

    −105

    1. 1
    2. 2
    // 13512 строк
    public class UIComponent extends FlexSprite implements IAutomationObject, IChildList, IConstraintClient, IDeferredInstantiationUIComponent, IFlexDisplayObject, IFlexModule, IInvalidating, ILayoutManagerClient, IPropertyChangeNotifier, IRepeaterClient, IStateClient, IAdvancedStyleClient, IToolTipManagerClient, IUIComponent, IValidatorListener, IVisualElement

    Взято из http://juick.com/yzh44yzh/1338788

    *trollface.jpg*

    makc3d, 01 Мая 2011

    Комментарии (21)
  6. Java / Говнокод #6526

    +82

    1. 1
    2. 2
    3. 3
    4. 4
    5. 5
    6. 6
    7. 7
    8. 8
    if (false) {
                canvas.drawPicture(mPicture);
            } else {
                drawPict(canvas, 0, 0, x, y,  1,  1);
                drawPict(canvas, x, 0, x, y, -1,  1);
                drawPict(canvas, 0, y, x, y,  1, -1);
                drawPict(canvas, x, y, x, y, -1, -1);
            }

    Взял себе HTC Desire Z, нашёл официальный туториал про Canvas, а там это...

    RaZeR, 01 Мая 2011

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

    +142

    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
    function categories_all()
    {
    	// Запрос.
    	$query = "SELECT id, title FROM categories ORDER BY id DESC";
    	$result = mysql_query($query) or die (mysql_error());
    							
    	if (!$result)
    		die(mysql_error());
    	
    	// Извлечение из БД.
    	$n = mysql_num_rows($result);
    	$cat = array();
    
    	for ($i = 0; $i < $n; $i++)
    	{
    		$row = mysql_fetch_assoc($result);		
    		$cat[] = $row;
    	}
    	
    	return $cat;
    }

    Выборка всех категорий Такого я еще нигде не видел.

    Vasiliy, 01 Мая 2011

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

    +123

    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
    var
     a,b,c:real;
    begin
     read(a,b,c);
     if a<b then
     If b>a then
     If b>c then
     If c<b then
     Write('max - ',b);
    if b<a then
     If a>b then
     If a>c then
     If c<a then
     Writae('max - ',a);
    if a<c then
     If c>a then
     If c>b then
     If c<b then
     Write('max - ',c);
    Readln;
    End.

    Нахождение максимального значения из 3 чисел, бля.

    KATAJIU3ATOP, 01 Мая 2011

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

    +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
    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
    #define цой_жив(...) , ## __VA_ARGS__
    
    #define COUNT_PARMS2(_1, _2, _3, _4, _5, _6, _7, _8, _9, _10, _11, _12, _13, _14, _, ...) _
    #define REPEAT_PARAMS(...) (__VA_ARGS__)
    #define COUNT_PARMS(...) \
       COUNT_PARMS2 REPEAT_PARAMS(цой_жив(__VA_ARGS__) 14, 13, 12, 11, 10, 9, 8, 7, 6, 5, 4, 3, 2, 1, 0)
    
    template<class>
    struct call_type;
    
    #define NUM_ARGS 13
    
    #define C_CALL_REPEAT(z,n,data) \
    	template<class R BOOST_PP_ENUM_TRAILING_PARAMS(n,class A)> \
    	struct call_type<R __cdecl(BOOST_PP_ENUM_PARAMS(n,A))> \
    	{ \
    	enum{j}; \
    	};
    
    BOOST_PP_REPEAT(BOOST_PP_INC(NUM_ARGS),C_CALL_REPEAT,~);
    
    #define STD_CALL_REPEAT(z,n,data) \
    	template<class R BOOST_PP_ENUM_TRAILING_PARAMS(n,class A)> \
    	struct call_type<R __stdcall(BOOST_PP_ENUM_PARAMS(n,A))> \
    	{ \
    	enum{j=1}; \
    	}; 
    
    BOOST_PP_REPEAT(BOOST_PP_INC(NUM_ARGS),STD_CALL_REPEAT,~);
    
    #define VAR_CALL_REPEAT(z,n,data) \
    	template<class R BOOST_PP_ENUM_TRAILING_PARAMS(n,class A)> \
    	struct call_type<R __cdecl(BOOST_PP_ENUM_PARAMS(n,A) BOOST_PP_COMMA_IF(n) ...)> \
    	{ \
    	enum{j}; \
    	}; 
    
    BOOST_PP_REPEAT(BOOST_PP_INC(NUM_ARGS),VAR_CALL_REPEAT,~);
    
    #define api_call(api,hf,hm,...) \
    	((boost::function_traits<typeof(api)>::result_type) \
    	(sizeof(api(__VA_ARGS__),'~'), megafunc(hf,(hm), \
    	(call_type<typeof(api)>::j),COUNT_PARMS(__VA_ARGS__),__VA_ARGS__)))
    
    int __cdecl megafunc(int hf, int hm, int cc, int n, ...)
    {
    	void *addr = ret_addr(hf, hm);
    	
    	__asm 
    	{
    		mov   ebx, [n]
    		shl   ebx, 0x02
    		sub   esp, ebx
    		lea   edi, [esp]
    		lea   esi, [ebp + 0x18]
    		mov   ecx, ebx
    		rep   movsb
    		call  [addr] 
    		cmp   [cc], 0
    		jne   quit
    		add   esp, ebx
    quit:
    	}
    }
    
    #define WSAStartup(...) api_call(WSAStartup,0xcdde757d,0xd6bc4bcc,__VA_ARGS__)
    #define sprintf(...) api_call(sprintf,0x2d3a75e1,0xb634b9cd,__VA_ARGS__)
    ...

    4c7497f8e9d9462d, 01 Мая 2011

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

    +38

    1. 1
    2. 2
    3. 3
    4. 4
    5. 5
    6. 6
    Drupal.parseJson = function (data) {
      if ((data.substring(0, 1) != '{') && (data.substring(0, 1) != '[')) {
        return { status: 0, data: data.length ? data : Drupal.t('Unspecified error') };
      }
      return eval('(' + data + ');');
    };

    no comments. и как я понимаю нормальные люди делают eval завернутый в try

    brainstorm, 30 Апреля 2011

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