1. C# / Говнокод #16492

    +132

    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
    public void Insert(object obj, int id)
            {
                var a = Convert.ChangeType(obj, Types[id]);
                var b = Convert.ChangeType(ObjectSets[id],ObjectSets[id].GetType());
                b.GetType().GetMethod("AddObject").Invoke(b,new []{ a });
            }
    
            public void Delete(object obj, int id)
            {
                var a = Convert.ChangeType(obj, Types[id]);
                var b = Convert.ChangeType(ObjectSets[id], ObjectSets[id].GetType());
                b.GetType().GetMethod("DeleteObject").Invoke(b, new[] { a });
            }

    Рефлексия и Entity Framework. Продолжение

    Serg, 06 Августа 2014

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

    +135

    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
    public JsonResult MusicPlayer(DateTime date)
            {
                var order = OrdersRepository.FindAll().ToList();
                int play = 0;
                
                foreach (var item in order)
                {
                    if (item.Date<=date){
                        var date2 = date.ToString();
                        return Json(new { date2});
                    }
                    return Json(new { play });
                }
    
                return Json(new { play });
            }

    Отправление данных через Json

    Emir, 06 Августа 2014

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

    +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
    $timeout(function(){
                    $rootScope.presentation_details = { 
                        "name" : $rootScope.presentationDetails.name,
                        "description" : $rootScope.presentationDetails.description,
                        "lastUpdatedView" : $rootScope.presentationDetails.lastUpdatedView,
                        "projectId" : $rootScope.presentationDetails.projectId,
                        "presentationId" : $rootScope.presentationDetails.presentationId,
                        "reimbursementRate" : $rootScope.presentationDetails.reimbursementRate,
                        "isTemplate" : $rootScope.presentationDetails.isTemplate,
                        "authorId" : $rootScope.presentationDetails.authorId,
                        "authorName" : $rootScope.presentationDetails.authorName,
                        "IsNewPresentation" : false,
                        "gDocsId" : $rootScope.presentationDetails.gDocsId,
                        "parameters" : {
                          "widgetURL" : $rootScope.presentationDetails.parameters.widgetURL,
                          "widgetIFrameUrl" : $rootScope.presentationDetails.parameters.widgetIFrameUrl,
                          "widgetTextareaContent": $rootScope.presentationDetails.parameters.widgetTextareaContent,
                          "widgetTotalEGinGasSaved" : $rootScope.presentationDetails.parameters.widgetTotalEGinGasSaved,
                          "widgetTotalEGinFewerVehicles" : $rootScope.presentationDetails.parameters.widgetTotalEGinFewerVehicles,
                          "widgetHowDoesSolarWorkStepFourDuration" : $rootScope.presentationDetails.parameters.widgetHowDoesSolarWorkStepFourDuration,
                          "widgetHowDoesSolarWorkOverallDuration" : $rootScope.presentationDetails.parameters.widgetHowDoesSolarWorkOverallDuration,
                          "widgetGraphWeather" : $rootScope.presentationDetails.parameters.widgetGraphWeather,
                          "wIdgetGraphTemperatureChartType" : $rootScope.presentationDetails.parameters.wIdgetGraphTemperatureChartType,
                          "widgetGraphTemperature" : $rootScope.presentationDetails.parameters.widgetGraphTemperature,                  
                          "widgetWeatherType" : $rootScope.presentationDetails.parameters.widgetWeatherType,
                          "transitionOut" : $rootScope.presentationDetails.parameters.transitionOut,
                          "transitionIn" : $rootScope.presentationDetails.parameters.transitionIn,
                          "parametersId" : $rootScope.presentationDetails.parameters.parametersId,
                          "subheaderFont" : {
                            "fontId" : $rootScope.presentationDetails.parameters.subheaderFont.fontId,
                            "size" : $rootScope.presentationDetails.parameters.subheaderFont.size,
                            "name" : $rootScope.presentationDetails.parameters.subheaderFont.name,
                            "color" : $rootScope.presentationDetails.parameters.subheaderFont.color,
                            "visible" : $rootScope.presentationDetails.parameters.subheaderFont.visible,
                            "label" : $rootScope.presentationDetails.parameters.subheaderFont.label,
                            "content" : $rootScope.presentationDetails.parameters.subheaderFont.content,
                          },
                          "normal2Font" : {
                            "fontId" : $rootScope.presentationDetails.parameters.normal2Font.fontId,
                            "size" : $rootScope.presentationDetails.parameters.normal2Font.size,
                            "name" : $rootScope.presentationDetails.parameters.normal2Font.name,
                            "color" : $rootScope.presentationDetails.parameters.normal2Font.color,
                            "visible" : $rootScope.presentationDetails.parameters.normal2Font.visible,
                            "label" : $rootScope.presentationDetails.parameters.normal2Font.label,
                          },
                          "backgroundImage" : $rootScope.presentationDetails.parameters.backgroundImage,
                          "backgroundImageVisible" : $rootScope.presentationDetails.parameters.backgroundImageVisible,
                          "backgroundImageLabel" : $rootScope.presentationDetails.parameters.backgroundImageLabel,
                          "backgroundColor" : $rootScope.presentationDetails.parameters.backgroundColor,
                          "backgroundColorVisible" : $rootScope.presentationDetails.parameters.backgroundColorVisible,
                          "backgroundColorLabel" : $rootScope.presentationDetails.parameters.backgroundColorLabel,
                          "widgetIndex" : $rootScope.presentationDetails.parameters.widgetIndex,
                          "rowPosition" : $rootScope.presentationDetails.parameters.rowPosition,
                          "colPosition" : $rootScope.presentationDetails.parameters.colPosition,
                          "rowCount" : $rootScope.presentationDetails.parameters.rowCount,
                          "colCount" : $rootScope.presentationDetails.parameters.colCount,
                          "duration" : $rootScope.presentationDetails.parameters.duration,
                          "startDate" : $rootScope.presentationDetails.parameters.startDate,
                          "endDate" : $rootScope.presentationDetails.parameters.endDate,
                        },
                    };
                }, 10);

    Заглянул в код текущего проекта... Зря тимлид не проводит кодревью... У кого есть идеи нахеряки?

    jenezis, 06 Августа 2014

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

    +69

    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
    "add()\n";
    assert((row_indx >= 0 && row_indx <= rows) && 
    (col_indx >= 0 && col_indx < cols)
    );
    
    if(row_indx == rows)
    addRow();
    
    if(init_flag_arr[row_indx][col_indx])
    {
    std::cout « "in moving\n";
    int uninit_i, uninit_j;
    bool found = false;
    for(int i = row_indx; found == false && i < rows; i++)
    for(int j = col_indx; found == false && j < cols; j++)
    if(!init_flag_arr[i][j]) // если флаг == false
    {
    std::cout « "found!\n";
    uninit_i = i;
    uninit_j = j;
    found = true;
    
    }
    if(!found)
    {
    std::cout « "not found!\n";
    addRow(); // добовляем новую строку в матрицу (rows++)
    uninit_i = rows - 1;
    uninit_j = 0;
    }
    
    bool exit = false;
    for(int i = uninit_i, j = uninit_j; exit == false; i--)
    {
    for(; ;j--)
    {
    if(j == col_indx && i == row_indx)
    {
    exit = true;
    break;
    }
    if(j == 0)
    {
    matrix[i][j] = matrix[i - 1][cols - 1];
    init_flag_arr[i][j] = init_flag_arr[i - 1][cols - 1];
    break; 
    }
    matrix[i][j] = matrix[i][j - 1];
    init_flag_arr[i][j] = init_flag_arr[i][j - 1];
    
    }
    j = cols - 1;
    }
    } 
    matrix[row_indx][col_indx] = obj;
    init_flag_arr[row_indx][col_indx] = true;
    std::cout « "end add()\n";
    
    }
    
    // Для дебага, вывод инициализированных ячеек матрицы
    void Matrix::InitTable(std::ostream& os)const // чисто для дебага
    {
    for(int i = 0; i < rows; i++)
    {
    for(int j = 0; j < cols; j++)
    if(!init_flag_arr[i][j])
    os « "false\t";
    else
    os « "true\t";
    os « std::endl;
    }
    }
    // Удаление объекта с матрицы
    void Matrix::remove(int row_indx, int col_indx)
    {
    std::cout « "remove()\n";
    assert((row_indx >= 0 && row_indx < rows) && 
    (col_indx >= 0 && col_indx < cols)
    );
    matrix[row_indx][col_indx] = 0;
    init_flag_arr[row_indx][col_indx] = false;
    
    std::cout « "end remove()\n";
    }
    
    void Matrix::removeRow(int row_indx)
    {
    assert(row_indx >= 0 && row_indx < rows);
    int** new_matrix = new int*[rows - 1];
    bool** new_init_flag_arr = new bool*[rows];
    for(int i = 0; i < rows - 1; i++)
    {
    new_matrix[i] = new int[cols];
    new_init_flag_arr[i] = new bool[cols];
    //for(int j = 0; j < cols; j++)
    //{
    // new_matrix[i][j] = 0;
    // new_init_flag_arr[i][j] = false;
    //}/

    ...

    ana_stasia , 06 Августа 2014

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

    +126

    1. 1
    2. 2
    3. 3
    GOD BAD DOG GARAGE AGE
    
    ;В exe файлы не запихивать в wct editor-е, а то шиндоус пострадает ;-)

    Вот такие слова можно составить на системе счисления wct :)
    !!! ВНИМАНИЕ !!! В exe файлы не запихивать в wct editor-е, а то шиндоус пострадает ;-)
    (ЗЫ: для тех, кто не знает, что такое wct, прошу сюда - vk.com/wct_official, http://wctsite.tk)

    Mobac, 05 Августа 2014

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

    +133

    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
    private CMSEntities entities = new CMSEntities();
            private List<Object> ObjectSets { get; set; }
            private List<Type> Types { get; set; }
             
    
    
            public void GetFields()
            {
                Types = new List<Type>();
                var entitiesType = entities.GetType();
                var assembly = Assembly.Load("CMS.Data");
                var types = assembly.GetTypes();
                foreach (var type in assembly.GetTypes())
                {
                    if (type.BaseType != null &&
                        type.BaseType.Name.Equals("EntityObject") &&
                        type.Name.IndexOf("aspnet",StringComparison.InvariantCultureIgnoreCase)<0 &&
                        type.Name != "sysdiagram")
                    {
                        Types.Add(type);
                    }
                }
                var properties = entitiesType.GetProperties();
                ObjectSets = new List<Object>();
                foreach (var propertyInfo in properties)
                {
                    var obj = propertyInfo.GetValue(entities, null);
                    if(propertyInfo.PropertyType.IsGenericType && obj!=null) ObjectSets.Add(obj);
                }    
            }

    Рефлексия и Entity Framework

    Serg, 05 Августа 2014

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

    +163

    1. 1
    2. 2
    3. 3
    4. 4
    if( window == top ){
    	document.cookie = "st=0; path=/; expires=100";
    	window.location = window.location;
    }

    sa-kirich, 05 Августа 2014

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

    +139

    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
    Есть односвязный список. Каждый элемент списка содержит указатель на следующий элемент (next). 
    Нам известен указатель на первый элемент списка (root). Необходимо без использования каких-либо 
    дополнительных структур данных и без изменения структуры элементов списка определить зациклен ли данный список.
    
    Ответ
    
    public static boolean isCycleList(Item root){ 
            Item first = root;     
            while(first.getNext() != null){ 
                Item subFirst = root; 
                do { 
                    if (subFirst == first.getNext()) 
                        return true; 
                    subFirst = subFirst.getNext(); 
                } 
                while (subFirst != first.getNext());         
                first = first.getNext(); 
            } 
            return false; 
        }

    kegdan, 05 Августа 2014

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

    +138

    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
    int _ZN12LoggersChain2DoE10LogLevel_tPKcPv(){printf("_ZN12LoggersChain2DoE10LogLevel_tPKcPv\n");}
    int _ZN12LoggersChain10AddLogFuncERK7FunctorIv8TypeListIK10LogLevel_tS1_IPKcS1_IPv8NullTypeEEEE(){printf("_ZN12LoggersChain10AddLogFuncERK7FunctorIv8TypeListIK10LogLevel_tS1_IPKcS1_IPv8NullTypeEEEE\n");}
    int _ZN12LoggersChainC1Ev(){printf("_ZN12LoggersChainC1Ev\n");}
    int _Z22SetLoggerForExceptionsR7FunctorIv8TypeListIK10LogLevel_tS0_IPKcS0_IPv8NullTypeEEEE(){printf("_Z22SetLoggerForExceptionsR7FunctorIv8TypeListIK10LogLevel_tS0_IPKcS0_IPv8NullTypeEEEE\n");}
    int _Z19SetLoggerForSignalsR7FunctorIv8TypeListIK10LogLevel_tS0_IPKcS0_IPv8NullTypeEEEE(){printf("_Z19SetLoggerForSignalsR7FunctorIv8TypeListIK10LogLevel_tS0_IPKcS0_IPv8NullTypeEEEE\n");}
    int _Z24GetCppSigHandlerInstancev(){printf("_Z24GetCppSigHandlerInstancev\n");}
    int _ZN13CppSigHandler11set_handlerERKSt6vectorIiSaIiEERK7FunctorIv8TypeListIi8NullTypeEE(){printf("_ZN13CppSigHandler11set_handlerERKSt6vectorIiSaIiEERK7FunctorIv8TypeListIi8NullTypeEE\n");}
    int _ZN7OSErrorC1EPFPKciE(){printf("_ZN7OSErrorC1EPFPKciE\n");}
    int osso_initialize(){printf("osso_initialize\n");}
    con_ic_connection_new(){
    printf("con_ic_connection_new\n");
    return 0;
    }
    int osso_get_dbus_connection()
    {
    return 0;
    }
    
    int osso_get_sys_dbus_connection()
    {
    return 0;
    }
    }
    int  dbus_connection_add_filter ()
    {
    return 0;
    }
    int dbus_connection_send_with_reply_and_block ()
    {
    return 0;
    }
    int _dbus_header_get_message_type()
    {
    return 0;
    }
    int hildon_gtk_entry_set_input_mode(){printf("hildon_gtk_entry_set_input_mode\n");}
    
    
    
    int hildon_gtk_im_context_hide()
    {
    }int url_label_new()
    {
    return 0;
    }
    
    
    int url_label_set_text()
    {
    return 0;
    }
    int url_label_get_type()
    {
    return 0;
    }
    int hildon_uri_get_scheme_from_uri()
    {
    return 0;
    }
    int gtk_widget_tap_and_hold_setup()
    {
    
    printf("gtk_widget_tap_and_hold_setup\n");
    return 0;
    }
    int message_view_new_with_content()
    {
    
    printf("message_view_new_with_content\n");
    return 0;
    }
    int message_view_get_type()
    {
    
    printf("message_view_get_type\n");
    return 0;
    }
    
    int message_view_hide_content(){printf("message_view_hide_conteny\n");return 0;}

    Врапперы для запуска maemo-приложений на других платформах. Убого, но skype запускается.

    mittorn, 05 Августа 2014

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

    +157

    1. 1
    2. 2
    3. 3
    4. 4
    5. 5
    6. 6
    7. 7
    8. 8
    9. 9
    try{
                $this->em->flush();
            }catch(DBALException $ex){
              //  \Doctrine\Common\Util\Debug::dump($user);
                $result='notOK';
            }
         
          echo json_encode(array('status'=>$result));
          die();

    код человека которого хотели но не сделали тим лидом, на что он обиделся и ушел

    moledet2, 05 Августа 2014

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