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

    +154

    1. 1
    2. 2
    3. 3
    4. 4
    $background_nid = _get_last_section_background($node);
    $new_background_nid = ($background_nid == 47)?48:47;
    $background_color = db_query("SELECT field_background_color_value FROM {field_revision_field_background_color} WHERE entity_id=:nid AND entity_type='node'", array(":nid" => $new_background_nid))->fetchField();
    $style_background = "background-color: #".$background_color."; ";

    Изысканное получение node id в Drupal

    valllllera, 18 Февраля 2014

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

    +150

    1. 1
    2. 2
    3. 3
    4. 4
    jQuery(document).ready(function() {
      var this = jQuery(this);
      this.someMethod();
    });

    "Почему-то не работает..."

    i--, 18 Февраля 2014

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

    +51

    1. 001
    2. 002
    3. 003
    4. 004
    5. 005
    6. 006
    7. 007
    8. 008
    9. 009
    10. 010
    11. 011
    12. 012
    13. 013
    14. 014
    15. 015
    16. 016
    17. 017
    18. 018
    19. 019
    20. 020
    21. 021
    22. 022
    23. 023
    24. 024
    25. 025
    26. 026
    27. 027
    28. 028
    29. 029
    30. 030
    31. 031
    32. 032
    33. 033
    34. 034
    35. 035
    36. 036
    37. 037
    38. 038
    39. 039
    40. 040
    41. 041
    42. 042
    43. 043
    44. 044
    45. 045
    46. 046
    47. 047
    48. 048
    49. 049
    50. 050
    51. 051
    52. 052
    53. 053
    54. 054
    55. 055
    56. 056
    57. 057
    58. 058
    59. 059
    60. 060
    61. 061
    62. 062
    63. 063
    64. 064
    65. 065
    66. 066
    67. 067
    68. 068
    69. 069
    70. 070
    71. 071
    72. 072
    73. 073
    74. 074
    75. 075
    76. 076
    77. 077
    78. 078
    79. 079
    80. 080
    81. 081
    82. 082
    83. 083
    84. 084
    85. 085
    86. 086
    87. 087
    88. 088
    89. 089
    90. 090
    91. 091
    92. 092
    93. 093
    94. 094
    95. 095
    96. 096
    97. 097
    98. 098
    99. 099
    100. 100
    #include<iostream>
    #include<istream>
    #include<fstream>
    #include<string>
    using namespace std;
    const int con=100;
    const int MAX=3;
    class movie
    {
    public:
    string title;
    string genre;
    string country;
    int year;
    double gainings;
    };
    int main(); {
    {
    string* argv = new string[10]={ "Star wars", "Harry Potter" , "Lion king", "Lord of the rings" , "Evgozavur", "Cow's house" , "Snow dogs", "Ice age" , "Shrek", "Dino"};
    int n=1,gainigs=10;
    int a,b,c;
    movie film1;
    movie film2;
    movie film3;
    cout << " Enter the title:"<<endl;
    cin>>film1.title;
    cout << " Enter the genre:"<<endl;
    cin>>film1.genre;
    cout << " Enter the country:"<<endl;
    cin>>film1.dev;
    cout << " Enter the year:"<<endl;
    cin>>film1.year;
    cout << " Enter the gainings:"<<endl;
    cin>>a;
    while (a>10){
    cout << " Enter the gainings:"<<endl;
    cin>>a;
    }film1.gainings=a;
    cout<<endl<<endl<<endl;
    cout<<" Enter the title:"<<endl;
    cin>>film2.title;
    cout<<" Enter the genre:"<<endl;
    cin>>film2.genre;
    cout<<" Enter the dev:"<<endl;
    cin>>film2.dev;
    cout<< " Enter the year:"<<endl;
    cin >> film2.year;
    cout<<" Enter the gainings:"<<endl;
    cin>>b;
    while (b>10){
    cout<<" Enter the gainings:"<<endl;
    cin>>b;
    }game2.gainings=b;
    cout<<endl<<endl<<endl;
    cout<<" Enter the title:"<<endl;
    cin>>film3.title;
    cout<<" Enter the genre:"<<endl;
    cin>>film3.genre;
    cout<<" Enter the dev:"<<endl;
    cin>>film3.dev;
    cout<<" Enter the year:"<<endl;
    cin>>film3.year;
    cout<<" Enter the gainings:"<<endl;
    cin>>c;
    while (c>10){
    cout<<" Enter the gainings:"<<endl;
    cin>>c;
    }film3.gainings=c;
    for (int j=0; j<n; j++)
    {
    cout<<""<<endl;
    cout<<"Title: " <<film1.title<<endl;
    cout<<"Genre: " <<film1.genre<<endl;
    cout<<"Year: " <<film1.year<<endl;
    cout<<"Gainings: "<<film1.gainings<<endl;
    cout<<""<<endl;
    cout<< "Title: "<<film2.title<<endl;
    cout<< "Genre: "<<film2.genre<<endl;
    cout<< "Year: "<<film2.year<<endl;
    cout<< "Gainings: " << film2.gainings<<endl;
    cout<<""<<endl;
    cout<<"Title: " <<film3.title <<endl;
    cout<<"Genre: " <<film3.genre <<endl;
    cout<<"Year: " <<film3.year <<endl;
    cout<<"Gainings: "<<film3.Gainings<<endl;
    cout<<"works"<<endl;
    }
    cout<<"printing works"<<endl;
    argv[0]=film1.title;
    argv[1]=film1.genre;
    argv[2]=film1.year;
    argv[3]=film1.gainings;
    cout<<"adding works"<<endl;
    cout<<endl<<endl<<endl;
    cout<<argv[0]<<endl;
    cout<<argv[1]<<endl;cout<<argv[2]<<endl;cout<<argv[3]<<endl;
    cout<<"print after add works"<<endl;
    system("pause");
    return 0;
    }

    Из http://forums.bgdev.org/index.php?showtopic=43872

    wasde, 18 Февраля 2014

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

    +136

    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
    private AseConnection con;
    
    public void CloseConnection()
    {
        if (this.con != null && this.con.State == ConnectionState.Open)
        {
            CloseConnection(this.con);
        }
    }
    
    public void CloseConnection(AseConnection con)
    {
        if (con == null)
            return;
    
        if (con.State == ConnectionState.Closed)
            return;
    
        con.Close();
    }

    А кому ещё враппэровъ? У меня много ихъ!

    wissenstein, 18 Февраля 2014

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

    +150

    1. 1
    var valid = !!files.length;

    Fileupload (c)

    begmst, 18 Февраля 2014

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

    −122

    1. 1
    ObjectUtils.deleteFromDictionary(showTweens,  slideView);

    Для тех, кто не в курсе:

    delete dictionary[key];

    wvxvw, 18 Февраля 2014

    Комментарии (1)
  7. Си / Говнокод #14630

    +127

    1. 1
    #define SOME_MACRO_NAME 	4 /* 1 */

    sermp, 18 Февраля 2014

    Комментарии (20)
  8. SQL / Говнокод #14629

    −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
    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
    89. 89
    90. 90
    91. 91
    92. 92
    93. 93
    94. 94
    95. 95
    96. 96
    97. 97
    -- Процедура формирования таблицы анализа по FIR
    CREATE PROCEDURE KojevnikovFir
                       @DateFo varchar(10),
                       @DateTo varchar(10)
    AS DECLARE @Polet int, @ProcPolet numeric(4,2)
    -- определяю кол-во выполненных рейсов в диапазоне дат----
    SET @Polet =  (SELECT DISTINCT Count(ID)  FROM PPLS WHERE                      
      ( ( FLI_ENTRY=1 or FLI_EXIT=1 )  or   (DEP=1 and DEP_AERODROME like'UK%' )  or
      (ARR=1 and DEST_AERODROME Like'UK%')  ) and (ENTRY_TIME >=@DateFo and ENTRY_TIME <=@DateTo))
    ----------- Начало формирования таблицы FIR-------------------
    -- Создаем  SCROLL курсор 1 для чтения
    DECLARE Cursor_All_Pol CURSOR SCROLL KEYSET TYPE_WARNING FOR SELECT  Marsrut,All_Polet
    FROM Marsr_All_Pol FOR READ ONLY 
    -- Открытие курсора 1 и наполнение его данными  
    OPEN Cursor_All_Pol DECLARE @Marsrut char(11), @All_Polet int,@Count1 int,@Count1_end int
    SET @Count1=1 SET @Count1_end = @@CURSOR_ROWS 
                            -- ===========обьявляю и заполняю курсор по 2 таблице==============
                            DECLARE Cursor_Air CURSOR SCROLL KEYSET TYPE_WARNING
                            FOR SELECT  Marsrut,TYPE_AIRCRAFT,kol_TypeAir FROM Marsr_kol_Air FOR READ ONLY 
                            -- Открытие курсора 2 и наполнение его данными  
                            OPEN Cursor_Air   
                            DECLARE @MarsrutAir char(11),@Type nvarchar(4), @Air_Polet int,@Count2 int,@Count2_end int
                            SET @Count2 = 0 SET @Count2_end = @@CURSOR_ROWS 
                            -- ===========обьявляю и заполняю курсор по 3 таблице==============
                            DECLARE Cursor_AK CURSOR SCROLL KEYSET TYPE_WARNING
                            FOR SELECT  Marsrut,ICAO,AK,kol_AK FROM dbo.Marsr_kol_AK FOR READ ONLY 
                            -- Открытие курсора 2 и наполнение его данными  
                            OPEN Cursor_AK   
                            DECLARE @MarsrutAK char(11),@ICAO char(3),@AK varchar(60),@kol_AK int,@Count3 int,@Count3_end int
                            SET @Count3 = 0 SET @Count3_end = @@CURSOR_ROWS 
    -- цикл по первому курсору
    WHILE @Count1 < @Count1_end BEGIN 
    -- на 1 запись курсора 1
    FETCH NEXT FROM Cursor_All_Pol INTO @Marsrut, @All_Polet
    -- вставляю строку маршрута и кол-ва полетов в таблицу
    SET @ProcPolet = ((@All_Polet * 100)/@Polet)
    INSERT KojevnikovAnalizFIR (Marsrut,All_Polet,PrcAll,TYPE_AIRCRAFT,kol_TypeAir,ICAO,AK,kol_AK)
    VALUES (@Marsrut,@All_Polet,@ProcPolet,null,null,null,null,null)  
    SET @Count1 = @Count1 + 1 
                            -- цикл по второму курсору
                            FETCH FIRST FROM Cursor_Air INTO @MarsrutAir,@Type,@Air_Polet
                            SET @Count2 = 1
                            -- Формирую 1 строку маршрут + ВС
                            IF @Marsrut = @MarsrutAir BEGIN
                                  INSERT KojevnikovAnalizFIR (Marsrut,All_Polet,PrcAll,TYPE_AIRCRAFT,kol_TypeAir,ICAO,AK,kol_AK)
                                   VALUES (null,null,null,@Type,@Air_Polet,null,null,null)
                               END --IF  
                            WHILE @Count2 < @Count2_end BEGIN 
                            -- увеличиваю счетчик  курсора 2
                            FETCH NEXT FROM Cursor_Air INTO @MarsrutAir,@Type,@Air_Polet
                            -- Формирую строку маршрут + ВС
                            IF @Marsrut = @MarsrutAir BEGIN
                           INSERT KojevnikovAnalizFIR (Marsrut,All_Polet,PrcAll,TYPE_AIRCRAFT,kol_TypeAir,ICAO,AK,kol_AK)
                           VALUES (null,null,null,@Type,@Air_Polet,null,null,null)
                               END --IF       
                             -- закрываю цикл WHILE 2 (второй курсор)
                           SET @Count2 = @Count2 + 1
                            END   
                            -- цикл по третьему курсору
                            FETCH FIRST FROM Cursor_AK INTO @MarsrutAK,@ICAO,@AK,@kol_AK
                            SET @Count3 = 1
                            -- Формирую 1 строку маршрут + АК
                            IF @Marsrut = @MarsrutAK BEGIN
                           INSERT KojevnikovAnalizFIR (Marsrut,All_Polet,PrcAll,TYPE_AIRCRAFT,kol_TypeAir,ICAO,AK,kol_AK)
                           VALUES (null,null,null,null,null,@ICAO,@AK,@kol_AK)
                           END --IF  
                            WHILE @Count3 < @Count3_end BEGIN 
                            -- увеличиваю счетчик  курсора 3
                            FETCH NEXT FROM Cursor_AK INTO @MarsrutAK,@ICAO,@AK,@kol_AK
                            -- Формирую строку маршрут + ВС
                            IF @Marsrut = @MarsrutAK BEGIN
                           INSERT KojevnikovAnalizFIR (Marsrut,All_Polet,PrcAll,TYPE_AIRCRAFT,kol_TypeAir,ICAO,AK,kol_AK)
                           VALUES (null,null,null,null,null,@ICAO,@AK,@kol_AK)
                           END --IF       
                             -- закрываю цикл WHILE 2 (второй курсор)
                           SET @Count3 = @Count3 + 1
                            END   
    -- закрываю цикл WHILE 1 (первый курсор)
    END
                            -- Закрываю курсор 2
                            CLOSE Cursor_Air 
                            -- Удаляю курсор 1 как обьект
                            DEALLOCATE Cursor_Air
                            -- Закрываю курсор 3
                            CLOSE Cursor_AK 
                            -- Удаляю курсор 1 как обьект
                            DEALLOCATE Cursor_AK
    -- Закрываю курсор
    CLOSE Cursor_All_Pol 
    -- Удаляю курсор 1 как обьект
    DEALLOCATE Cursor_All_Pol
    ------------Конец--------------------
    GO
    select * from KojevnikovAnalizFIR 
    truncate table dbo.KojevnikovAnalizFIR
    DELETE from KojevnikovAnalizFIR
    exec dbo.KojevnikovFir '2004-01-01','2004-01-05'

    курсор головного мозга 2.1

    bahamot, 18 Февраля 2014

    Комментарии (2)
  9. Си / Говнокод #14627

    +136

    1. 1
    2. 2
    3. 3
    4. 4
    5. 5
    //...
    float a = 7;
    printf("%d", *(unsigned int *)(&a) >> 23);
    // Что напечатает?
    //...

    На экзамене как-то задали такой вопрос. А ну-ка, кто без компилятора ответит?

    GonZaleZ, 18 Февраля 2014

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

    +59

    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
    89. 89
    90. 90
    91. 91
    92. 92
    93. 93
    #ifndef PORT_H_
    #define PORT_H_
    
    #define MAKE_PORT(portName, ddrName, pinName, className, ID) \
    		class className{\
    		public:\
    			typedef uint8_t DataT; /* Alias for the type of data port*/\
    		private:\
    			static volatile DataT &data()\
    			{\
    				return portName;\
    			}\
    			static volatile DataT &dir()\
    			{\
    				return ddrName;\
    			}\
    			static volatile DataT &pin()\
    			{\
    				return pinName;\
    			}\
    		public:\
    			static void Write(DataT value) /*Write value to port PORT = value*/\
    			{\
    				data() = value;\
    			}\
    			static void ClearAndSet(DataT clearMask, DataT value) /*Clear by mask and set PORT = (PORT & ~clearMask) | value */\
    			{\
    				data() = (data() & ~clearMask) | value;\
    			}\
    			static DataT Read() /*Read the value written to the port*/\
    			{\
    				return data();\
    			}\
    			static void DirWrite(DataT value)/*Record the value of the direction of the lines I/O */\
    			{\
    				dir() = value;\
    			}\
    			static DataT DirRead() /*Read the value of the direction of the lines I/O */\
    			{\
    				return dir();\
    			}\
    			static void Set(DataT value) /*Set bits in the port PORT |= value;*/\
    			{\
    				data() |= value;\
    			}\
    			static void Clear(DataT value) /*Clear bits in the port PORT &= ~value;*/\
    			{\
    				data() &= ~value;\
    			}\
    			static void Togle(DataT value) /*Switch bits PORT ^= value;*/\
    			{\
    				data() ^= value;\
    			}\
    			static void DirSet(DataT value) /*Set direction bits*/\
    			{\
    				dir() |= value;\
    			}\
    			static void DirClear(DataT value) /*Clear direction bits*/\
    			{\
    				dir() &= ~value;\
    			}\
    			static void DirTogle(DataT value)\
    			{\
    				dir() ^= value;\
    			}\
    			static DataT PinRead()\
    			{\
    				return pin();\
    			}\
    			enum{Id = ID};\
    			enum{Width=sizeof(DataT)*8};/*Bit depth*/\
    		};
    
    #ifdef PORTA
    	MAKE_PORT(PORTA, DDRA, PINA, Porta, 'A');
    #endif
    
    #ifdef PORTB
    	MAKE_PORT(PORTB, DDRB, PINB, Portb, 'B');
    #endif
    
    #ifdef PORTC
    	MAKE_PORT(PORTC, DDRC, PINC, Portc, 'C');
    #endif
    
    #ifdef PORTD
    	MAKE_PORT(PORTD, DDRD, PIND, Portd, 'D');
    #endif
    
    
    
    
    #endif /* PORT_H_ */

    Использование СИ++ в микроконтроллерах доставляет....

    nsa_a1, 18 Февраля 2014

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